Skip to content

Commit 2771845

Browse files
committed
Support :test_elixirc_options in mix test
And skip debug and docs chunks by default. Closes elixir-lang#11755.
1 parent fd51354 commit 2771845

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

lib/mix/lib/mix/compilers/test.ex

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ defmodule Mix.Compilers.Test do
2222
It expects all of the test patterns, the test files that were matched for the
2323
test patterns, the test paths, and the opts from the test task.
2424
"""
25-
def require_and_run(matched_test_files, test_paths, opts) do
25+
def require_and_run(matched_test_files, test_paths, elixirc_opts, opts) do
2626
stale = opts[:stale]
2727

2828
{test_files, stale_manifest_pid, parallel_require_callbacks} =
@@ -39,7 +39,7 @@ defmodule Mix.Compilers.Test do
3939
:noop
4040

4141
Keyword.get(opts, :profile_require) == "time" ->
42-
Kernel.ParallelCompiler.require(test_files, profile: :time)
42+
require(test_files, [profile: :time], elixirc_opts)
4343
:noop
4444

4545
true ->
@@ -48,7 +48,7 @@ defmodule Mix.Compilers.Test do
4848

4949
try do
5050
failed? =
51-
case Kernel.ParallelCompiler.require(test_files, parallel_require_callbacks) do
51+
case require(test_files, parallel_require_callbacks, elixirc_opts) do
5252
{:ok, _, [_ | _]} when warnings_as_errors? -> true
5353
{:ok, _, _} -> false
5454
{:error, _, _} -> exit({:shutdown, 1})
@@ -81,6 +81,17 @@ defmodule Mix.Compilers.Test do
8181
end
8282
end
8383

84+
defp require(files, require_opts, elixirc_opts) do
85+
elixirc_opts = Keyword.merge([docs: false, debug_info: false], elixirc_opts)
86+
previous_opts = Code.compiler_options(elixirc_opts)
87+
88+
try do
89+
Kernel.ParallelCompiler.require(files, require_opts)
90+
after
91+
Code.compiler_options(previous_opts)
92+
end
93+
end
94+
8495
defp set_up_stale(matched_test_files, test_paths, opts) do
8596
manifest = manifest()
8697
modified = Mix.Utils.last_modified(manifest)

lib/mix/lib/mix/tasks/test.ex

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,13 @@ defmodule Mix.Tasks.Test do
190190
191191
These configurations can be set in the `def project` section of your `mix.exs`:
192192
193+
* `:test_coverage` - a set of options to be passed down to the coverage
194+
mechanism. See the "Coverage" section for more information
195+
196+
* `:test_elixirc_options` - the compiler options to used when
197+
loading/compiling test files. By default it disables the debug chunk
198+
and docs chunk
199+
193200
* `:test_paths` - list of paths containing test files. Defaults to
194201
`["test"]` if the `test` directory exists; otherwise, it defaults to `[]`.
195202
It is expected that all test paths contain a `test_helper.exs` file
@@ -199,9 +206,6 @@ defmodule Mix.Tasks.Test do
199206
* `:warn_test_pattern` - a pattern to match potentially misnamed test files
200207
and display a warning. Defaults to `*_test.ex`
201208
202-
* `:test_coverage` - a set of options to be passed down to the coverage
203-
mechanism. See the "Coverage" section for more information
204-
205209
## Coloring
206210
207211
Coloring is enabled by default on most Unix terminals. They are also
@@ -523,6 +527,7 @@ defmodule Mix.Tasks.Test do
523527
ExUnit.configure(merge_helper_opts(ex_unit_opts))
524528

525529
# Finally parse, require and load the files
530+
test_elixirc_options = project[:test_elixirc_options] || []
526531
test_files = parse_files(files, shell, test_paths)
527532
test_pattern = project[:test_pattern] || "*_test.exs"
528533
warn_test_pattern = project[:warn_test_pattern] || "*_test.ex"
@@ -535,7 +540,7 @@ defmodule Mix.Tasks.Test do
535540

536541
display_warn_test_pattern(test_files, test_pattern, matched_test_files, warn_test_pattern)
537542

538-
case CT.require_and_run(matched_test_files, test_paths, opts) do
543+
case CT.require_and_run(matched_test_files, test_paths, test_elixirc_options, opts) do
539544
{:ok, %{excluded: excluded, failures: failures, total: total}} ->
540545
Mix.shell(shell)
541546
cover && cover.()

0 commit comments

Comments
 (0)