Skip to content

Commit

Permalink
Do not run test suite on mix test --profile-require
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Dec 3, 2021
1 parent ed91b33 commit dfd12b9
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 43 deletions.
81 changes: 39 additions & 42 deletions lib/mix/lib/mix/compilers/test.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,52 +25,57 @@ defmodule Mix.Compilers.Test do
def require_and_run(matched_test_files, test_paths, opts) do
stale = opts[:stale]

{test_files, stale_manifest_pid, parallel_require_opts} =
{test_files, stale_manifest_pid, parallel_require_callbacks} =
if stale do
set_up_stale(matched_test_files, test_paths, opts)
else
{matched_test_files, nil, []}
end

if test_files == [] do
:noop
else
task = ExUnit.async_run()
parallel_require_opts = profile_opts(parallel_require_opts, opts)
warnings_as_errors? = Keyword.get(opts, :warnings_as_errors, false)

try do
failed? =
case Kernel.ParallelCompiler.require(test_files, parallel_require_opts) do
{:ok, _, [_ | _]} when warnings_as_errors? -> true
{:ok, _, _} -> false
{:error, _, _} -> exit({:shutdown, 1})
end
cond do
test_files == [] ->
:noop

Keyword.get(opts, :profile_require) == "time" ->
Kernel.ParallelCompiler.require(test_files, profile: :time)
:noop

true ->
task = ExUnit.async_run()
warnings_as_errors? = Keyword.get(opts, :warnings_as_errors, false)

try do
failed? =
case Kernel.ParallelCompiler.require(test_files, parallel_require_callbacks) do
{:ok, _, [_ | _]} when warnings_as_errors? -> true
{:ok, _, _} -> false
{:error, _, _} -> exit({:shutdown, 1})
end

%{failures: failures} = results = ExUnit.await_run(task)

%{failures: failures} = results = ExUnit.await_run(task)
if failures == 0 do
if failed? do
message =
"\nERROR! Test suite aborted after successful execution due to warnings while using the --warnings-as-errors option"

if failures == 0 do
if failed? do
message =
"\nERROR! Test suite aborted after successful execution due to warnings while using the --warnings-as-errors option"
IO.puts(:stderr, IO.ANSI.format([:red, message]))
exit({:shutdown, 1})
end

IO.puts(:stderr, IO.ANSI.format([:red, message]))
exit({:shutdown, 1})
agent_write_manifest(stale_manifest_pid)
end

agent_write_manifest(stale_manifest_pid)
{:ok, results}
catch
kind, reason ->
# In case there is an error, shut down the runner task
# before the error propagates up and trigger links.
Task.shutdown(task)
:erlang.raise(kind, reason, __STACKTRACE__)
after
agent_stop(stale_manifest_pid)
end

{:ok, results}
catch
kind, reason ->
# In case there is an error, shut down the runner task
# before the error propagates up and trigger links.
Task.shutdown(task)
:erlang.raise(kind, reason, __STACKTRACE__)
after
agent_stop(stale_manifest_pid)
end
end
end

Expand Down Expand Up @@ -167,14 +172,6 @@ defmodule Mix.Compilers.Test do
sources
end

defp profile_opts(target, opts) do
if Keyword.get(opts, :profile_require) == "time" do
Keyword.put(target, :profile, :time)
else
target
end
end

## Manifest

defp manifest, do: Path.join(Mix.Project.manifest_path(), @stale_manifest)
Expand Down
3 changes: 2 additions & 1 deletion lib/mix/lib/mix/tasks/test.ex
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ defmodule Mix.Tasks.Test do
* `--preload-modules` - preloads all modules defined in applications
* `--profile-require` - profiles the time spent to require test files
* `--profile-require` - profiles the time spent to require test files.
Used only for debugging. The test suite does not run.
* `--raise` - raises if the test suite failed
Expand Down

0 comments on commit dfd12b9

Please sign in to comment.