-
-
Save kw7oe/78c37db22c89d7eabb7f80c91b94dfba to your computer and use it in GitHub Desktop.
Minimal changes to implement ExUnit.rerun(list_of_modules)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/ex_unit/lib/ex_unit.ex b/lib/ex_unit/lib/ex_unit.ex | |
index f5b4417df..24115d05f 100644 | |
--- a/lib/ex_unit/lib/ex_unit.ex | |
+++ b/lib/ex_unit/lib/ex_unit.ex | |
@@ -360,6 +360,17 @@ def run do | |
ExUnit.Runner.run(options, nil) | |
end | |
+ @spec rerun(list()) :: suite_result() | |
+ def rerun(modules) do | |
+ for module <- modules do | |
+ ExUnit.Server.add_sync_module(module) | |
+ end | |
+ | |
+ _ = ExUnit.Server.modules_loaded() | |
+ options = persist_defaults(configuration()) | |
+ ExUnit.Runner.run(options, nil) | |
+ end | |
+ | |
@doc """ | |
Starts tests asynchronously while test cases are still loading. | |
diff --git a/lib/ex_unit/test/ex_unit_test.exs b/lib/ex_unit/test/ex_unit_test.exs | |
index 24015fbbf..087365f9d 100644 | |
--- a/lib/ex_unit/test/ex_unit_test.exs | |
+++ b/lib/ex_unit/test/ex_unit_test.exs | |
@@ -32,6 +32,35 @@ test "false" do | |
end) =~ "\n0 failures\n" | |
end | |
+ test "supports many reruns" do | |
+ defmodule SampleTest do | |
+ use ExUnit.Case | |
+ | |
+ test "true" do | |
+ assert false | |
+ end | |
+ | |
+ test "false" do | |
+ assert false | |
+ end | |
+ end | |
+ | |
+ configure_and_reload_on_exit([]) | |
+ | |
+ assert capture_io(fn -> | |
+ assert ExUnit.run() == %{failures: 2, skipped: 0, total: 2, excluded: 0} | |
+ end) =~ "\n2 tests, 2 failures\n" | |
+ | |
+ assert capture_io(fn -> | |
+ assert ExUnit.rerun([SampleTest]) == %{ | |
+ failures: 2, | |
+ skipped: 0, | |
+ total: 2, | |
+ excluded: 0 | |
+ } | |
+ end) =~ "\n2 tests, 2 failures\n" | |
+ end | |
+ | |
test "prints aborted runs on sigquit", config do | |
Process.register(self(), :aborted_on_sigquit) | |
line = __ENV__.line + 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment