Skip to content

Commit 5422815

Browse files
authored
Include max cases in ExUnit reports (#13521)
Some CI environments may report the wrong number of cores to the Erlang VM. So we choose to print the number of max cases along side the seed (both which affect randomness of tests) at the top of each suite.
1 parent 80a20d2 commit 5422815

File tree

5 files changed

+27
-40
lines changed

5 files changed

+27
-40
lines changed

lib/elixir/pages/mix-and-otp/introduction-to-mix.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,11 @@ This file will be required by Mix every time before we run our tests. We can run
213213
$ mix test
214214
Compiled lib/kv.ex
215215
Generated kv app
216+
Running ExUnit with seed: 540224, max_cases: 16
216217
..
217218

218219
Finished in 0.04 seconds
219220
1 doctest, 1 test, 0 failures
220-
221-
Randomized with seed 540224
222221
```
223222

224223
Notice that by running `mix test`, Mix has compiled the source files and generated the application manifest once again. This happens because Mix supports multiple environments, which we will discuss later in this chapter.

lib/ex_unit/lib/ex_unit/cli_formatter.ex

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ defmodule ExUnit.CLIFormatter do
88
## Callbacks
99

1010
def init(opts) do
11-
print_filters(Keyword.take(opts, [:include, :exclude]))
11+
IO.puts("Running ExUnit with seed: #{opts[:seed]}, max_cases: #{opts[:max_cases]}")
12+
print_filters(opts, :exclude)
13+
print_filters(opts, :include)
14+
IO.puts("")
1215

1316
config = %{
14-
seed: opts[:seed],
1517
trace: opts[:trace],
1618
colors: colors(opts),
1719
width: get_terminal_width(),
@@ -356,22 +358,16 @@ defmodule ExUnit.CLIFormatter do
356358
true ->
357359
IO.puts(success(message, config))
358360
end
359-
360-
IO.puts("\nRandomized with seed #{config.seed}")
361361
end
362362

363363
defp if_true(value, false, _fun), do: value
364364
defp if_true(value, true, fun), do: fun.(value)
365365

366-
defp print_filters(include: [], exclude: []) do
367-
:ok
368-
end
369-
370-
defp print_filters(include: include, exclude: exclude) do
371-
if exclude != [], do: IO.puts(format_filters(exclude, :exclude))
372-
if include != [], do: IO.puts(format_filters(include, :include))
373-
IO.puts("")
374-
:ok
366+
defp print_filters(opts, key) do
367+
case opts[key] do
368+
[] -> :ok
369+
filters -> IO.puts(format_filters(filters, key))
370+
end
375371
end
376372

377373
defp print_failure(formatted, config) do

lib/ex_unit/test/ex_unit_test.exs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,6 @@ defmodule ExUnitTest do
138138
Showing results so far...
139139
140140
0 failures
141-
142-
Randomized with seed 0
143141
"""
144142
end
145143

@@ -926,7 +924,7 @@ defmodule ExUnitTest do
926924
end
927925

928926
describe ":repeat_until_failure" do
929-
test "default value 0" do
927+
test "defaults to 0" do
930928
configure_and_reload_on_exit([])
931929
ExUnit.start(autorun: false)
932930
config = ExUnit.configuration()
@@ -940,7 +938,7 @@ defmodule ExUnitTest do
940938
assert config[:repeat_until_failure] == 5
941939
end
942940

943-
test ":repeat_until_failure repeats tests up to the configured number of times" do
941+
test "repeats tests up to the configured number of times" do
944942
defmodule TestRepeatUntilFailureReached do
945943
use ExUnit.Case
946944

@@ -962,12 +960,12 @@ defmodule ExUnitTest do
962960
assert ExUnit.run() == %{total: 5, failures: 0, skipped: 1, excluded: 1}
963961
end)
964962

965-
runs = String.split(output, "Excluding", trim: true)
963+
runs = String.split(output, "Running ExUnit", trim: true)
966964
# 6 runs in total, 5 repeats
967965
assert length(runs) == 6
968966
end
969967

970-
test ":repeat_until_failure stops on failure" do
968+
test "stops on failure" do
971969
{:ok, pid} = Agent.start_link(fn -> 0 end)
972970
Process.register(pid, :ex_unit_repeat_until_failure_count)
973971

@@ -1002,7 +1000,7 @@ defmodule ExUnitTest do
10021000
assert ExUnit.run() == %{total: 4, excluded: 2, failures: 1, skipped: 1}
10031001
end)
10041002

1005-
runs = String.split(output, "Excluding", trim: true)
1003+
runs = String.split(output, "Running ExUnit", trim: true)
10061004
# four runs in total, the first two repeats work fine, the third repeat (4th run)
10071005
# fails, therefore we stop
10081006
assert length(runs) == 4

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ defmodule Mix.Tasks.Test do
3636
a summary at the end, as seen below:
3737
3838
$ mix test
39+
Running ExUnit with seed: 646219, max_cases: 16
3940
...
4041
4142
1) test greets the world (FooTest)
@@ -52,8 +53,6 @@ defmodule Mix.Tasks.Test do
5253
Finished in 0.05 seconds (0.00s async, 0.05s sync)
5354
1 doctest, 11 tests, 1 failure
5455
55-
Randomized with seed 646219
56-
5756
For each test, the test suite will print a dot. Failed tests
5857
are printed immediately in the format described in the next
5958
section.

lib/mix/test/mix/tasks/test_test.exs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ defmodule Mix.Tasks.TestTest do
265265
in_fixture("test_stale", fn ->
266266
port = mix_port(~w[test --stale --listen-on-stdin])
267267

268-
assert receive_until_match(port, "seed", "") =~ "2 tests"
268+
assert receive_until_match(port, "0 failures", "") =~ "2 tests"
269269

270270
Port.command(port, "\n")
271271

@@ -294,7 +294,7 @@ defmodule Mix.Tasks.TestTest do
294294

295295
Port.command(port, "\n")
296296

297-
assert receive_until_match(port, "seed", "") =~ "2 tests"
297+
assert receive_until_match(port, "0 failures", "") =~ "2 tests"
298298

299299
File.write!("test/b_test_stale.exs", """
300300
defmodule BTest do
@@ -323,7 +323,7 @@ defmodule Mix.Tasks.TestTest do
323323

324324
Port.command(port, "\n")
325325

326-
assert receive_until_match(port, "seed", "") =~ "2 tests"
326+
assert receive_until_match(port, "0 failures", "") =~ "2 tests"
327327
end)
328328
end
329329
end
@@ -477,38 +477,33 @@ defmodule Mix.Tasks.TestTest do
477477

478478
output = mix(["test", "apps/bar/test/bar_tests.exs"])
479479

480-
assert output =~ """
481-
==> bar
482-
....
483-
"""
480+
assert output =~ "==> bar"
481+
assert output =~ "...."
484482

485483
refute output =~ "==> foo"
486484
refute output =~ "Paths given to \"mix test\" did not match any directory/file"
487485

488486
output = mix(["test", "./apps/bar/test/bar_tests.exs"])
489487

490-
assert output =~ """
491-
==> bar
492-
....
493-
"""
488+
assert output =~ "==> bar"
489+
assert output =~ "...."
494490

495491
refute output =~ "==> foo"
496492
refute output =~ "Paths given to \"mix test\" did not match any directory/file"
497493

498494
output = mix(["test", Path.expand("apps/bar/test/bar_tests.exs")])
499495

500-
assert output =~ """
501-
==> bar
502-
....
503-
"""
496+
assert output =~ "==> bar"
497+
assert output =~ "...."
504498

505499
refute output =~ "==> foo"
506500
refute output =~ "Paths given to \"mix test\" did not match any directory/file"
507501

508502
output = mix(["test", "apps/bar/test/bar_tests.exs:10"])
509503

504+
assert output =~ "==> bar"
505+
510506
assert output =~ """
511-
==> bar
512507
Excluding tags: [:test]
513508
Including tags: [location: {"test/bar_tests.exs", 10}]
514509

0 commit comments

Comments
 (0)