Skip to content

Commit 519eff5

Browse files
committed
Do not crash on empty test unit groups, closes #14754
1 parent e29c40a commit 519eff5

File tree

2 files changed

+39
-10
lines changed

2 files changed

+39
-10
lines changed

lib/ex_unit/lib/ex_unit/runner.ex

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -165,18 +165,23 @@ defmodule ExUnit.Runner do
165165
running
166166
end
167167

168-
defp spawn_modules(config, [{group, [_ | _] = modules} | groups], async?, running) do
169-
if max_failures_reached?(config) do
170-
running
171-
else
172-
{pid, ref} =
173-
spawn_monitor(fn ->
174-
Enum.each(modules, fn {module, params} ->
175-
run_module(config, module, async?, group, params)
168+
defp spawn_modules(config, [{group, modules} | groups], async?, running) do
169+
cond do
170+
max_failures_reached?(config) ->
171+
running
172+
173+
modules == [] ->
174+
spawn_modules(config, groups, async?, running)
175+
176+
true ->
177+
{pid, ref} =
178+
spawn_monitor(fn ->
179+
Enum.each(modules, fn {module, params} ->
180+
run_module(config, module, async?, group, params)
181+
end)
176182
end)
177-
end)
178183

179-
spawn_modules(config, groups, async?, Map.put(running, ref, pid))
184+
spawn_modules(config, groups, async?, Map.put(running, ref, pid))
180185
end
181186
end
182187

lib/ex_unit/test/ex_unit_test.exs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,30 @@ defmodule ExUnitTest do
720720
assert_receive {:tmp_dir, tmp_dir2} when tmp_dir1 != tmp_dir2
721721
end
722722

723+
test "empty parameterized tests" do
724+
defmodule EmptyParameterizedTests do
725+
use ExUnit.Case, async: true, parameterize: []
726+
727+
test "hello world" do
728+
assert false
729+
end
730+
end
731+
732+
configure_and_reload_on_exit(trace: true)
733+
assert capture_io(fn -> ExUnit.run() end) =~ "0 tests"
734+
735+
defmodule EmptyGroupedParameterizedTests do
736+
use ExUnit.Case, async: true, parameterize: [], group: :example
737+
738+
test "hello world" do
739+
assert false
740+
end
741+
end
742+
743+
configure_and_reload_on_exit(trace: true)
744+
assert capture_io(fn -> ExUnit.run() end) =~ "0 tests"
745+
end
746+
723747
describe "after_suite/1" do
724748
test "executes all callbacks set in reverse order" do
725749
Process.register(self(), :after_suite_test_process)

0 commit comments

Comments
 (0)