Skip to content

Add mix test --dry-run flag #14499

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Nezteb
Copy link
Contributor

@Nezteb Nezteb commented May 15, 2025

Aims to address #14393

@Nezteb Nezteb force-pushed the mix-test-dry-run-flag branch from 0eadca6 to 64bb5e1 Compare May 15, 2025 16:34
@Nezteb
Copy link
Contributor Author

Nezteb commented May 15, 2025

I'm not quite sure why one of the builds is failing:

...
==> ex_doc (elixir)
CANONICAL=main/ bin/elixir ../ex_doc/bin/ex_doc "Elixir" "1.19.0-dev" "lib/elixir/ebin" --main "Kernel" --source-url "https://github.com/elixir-lang/elixir" --source-ref "0eadca63de6d5171d5331af013866d1d7e637c95" --logo lib/elixir/pages/images/logo.png --output doc/elixir --canonical "https://hexdocs.pm/elixir/main/" --homepage-url "https://elixir-lang.org/docs.html" --warnings-as-errors --config "lib/elixir/scripts/elixir_docs.exs"
View "html" docs at "doc/elixir/index.html"
View "epub" docs at "doc/elixir/Elixir.epub"
bin/elixir lib/elixir/scripts/docs_config.exs "elixir"
** (Enum.OutOfBoundsError) out of bounds error at position 0 when traversing enumerable #Stream<[enum: [], funs: [#Function<39.94662069/1 in Stream.filter/2>]]>
    (elixir 1.19.0-dev) lib/enum.ex:1058: Enum.fetch!/2
    lib/elixir/scripts/docs_config.exs:23: (file)
make: *** [Makefile:199: docs_elixir] Error 1

@@ -770,6 +770,40 @@ defmodule Mix.Tasks.TestTest do
end
end

describe "--dry-run" do
Copy link
Contributor Author

@Nezteb Nezteb May 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More test cases to add:

  • --dry-run + --only
  • --dry-run + --exclude
  • ...?

Copy link
Member

@whatyouhide whatyouhide left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, implementation-wise I think we might need to take a different approach. Right now, I see two main issues:

  1. We're not running ExUnit.Formatters on dry runs—I think we might want to. Basically, the only thing we want --dry-run to do is to literally skip executing the body of tests (+ setup/setup_all calls and whatnot), but everything else would be the same.
  2. We are printing test files, but this doesn't give us information about what tests (or test cases even, if there are >1 test cases in a file) would run. I think this is important. Think of using --dry-run to answer the question "if I pass this --exclude option, how many tests will be skipped"?.

Do these points make sense? I am not even sure this is very feasible, so we'd need to sort of proof-of-concept this.

@Nezteb Nezteb requested a review from whatyouhide May 16, 2025 16:59
Comment on lines +50 to +61
modules_to_restore =
if not opts[:dry_run] do
do_run(config, modules_to_restore, opts, load_us)
else
nil
end

stats = ExUnit.RunnerStats.stats(stats_pid)
EM.stop(config.manager)
after_suite_callbacks = Application.fetch_env!(:ex_unit, :after_suite)
Enum.each(after_suite_callbacks, fn callback -> callback.(stats) end)
{stats, modules_to_restore}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@whatyouhide So, I tried to move the flag down the stack as far as possible. I still need to write tests, but does this look more in the right direction? 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants