diff --git a/lib/ex_unit/lib/ex_unit/case.ex b/lib/ex_unit/lib/ex_unit/case.ex index 3295ebaf32b..01488a6a8a7 100644 --- a/lib/ex_unit/lib/ex_unit/case.ex +++ b/lib/ex_unit/lib/ex_unit/case.ex @@ -624,6 +624,7 @@ defmodule ExUnit.Case do moduletag = Module.get_attribute(mod, :moduletag) tag = Module.delete_attribute(mod, :tag) + {async, _parameterize} = Module.get_attribute(mod, :ex_unit_module) {name, describe, describe_line, describetag} = case Module.get_attribute(mod, :ex_unit_describe) do @@ -648,6 +649,7 @@ defmodule ExUnit.Case do line: line, file: file, registered: registered, + async: async, describe: describe, describe_line: describe_line, test_type: test_type diff --git a/lib/mix/test/fixtures/test_async/lib/a.ex b/lib/mix/test/fixtures/test_async/lib/a.ex new file mode 100644 index 00000000000..d534bf917f1 --- /dev/null +++ b/lib/mix/test/fixtures/test_async/lib/a.ex @@ -0,0 +1,3 @@ +defmodule A do + def f, do: :ok +end diff --git a/lib/mix/test/fixtures/test_async/lib/b.ex b/lib/mix/test/fixtures/test_async/lib/b.ex new file mode 100644 index 00000000000..2cd8410c8fc --- /dev/null +++ b/lib/mix/test/fixtures/test_async/lib/b.ex @@ -0,0 +1,3 @@ +defmodule B do + def f, do: A.f() +end diff --git a/lib/mix/test/fixtures/test_async/mix.exs b/lib/mix/test/fixtures/test_async/mix.exs new file mode 100644 index 00000000000..90619669059 --- /dev/null +++ b/lib/mix/test/fixtures/test_async/mix.exs @@ -0,0 +1,11 @@ +defmodule TestAsync.MixProject do + use Mix.Project + + def project do + [ + app: :test_async, + version: "0.0.1", + test_pattern: "*_test_async.exs" + ] + end +end diff --git a/lib/mix/test/fixtures/test_async/test/a_test_async.exs b/lib/mix/test/fixtures/test_async/test/a_test_async.exs new file mode 100644 index 00000000000..c6b9ef857ef --- /dev/null +++ b/lib/mix/test/fixtures/test_async/test/a_test_async.exs @@ -0,0 +1,7 @@ +defmodule ATest do + use ExUnit.Case, async: true + + test "f async" do + assert A.f() == :ok + end +end diff --git a/lib/mix/test/fixtures/test_async/test/b_test_async.exs b/lib/mix/test/fixtures/test_async/test/b_test_async.exs new file mode 100644 index 00000000000..7b9b5f19a53 --- /dev/null +++ b/lib/mix/test/fixtures/test_async/test/b_test_async.exs @@ -0,0 +1,7 @@ +defmodule BTest do + use ExUnit.Case, async: false + + test "f sync" do + assert B.f() == :ok + end +end diff --git a/lib/mix/test/fixtures/test_async/test/test_helper.exs b/lib/mix/test/fixtures/test_async/test/test_helper.exs new file mode 100644 index 00000000000..869559e709e --- /dev/null +++ b/lib/mix/test/fixtures/test_async/test/test_helper.exs @@ -0,0 +1 @@ +ExUnit.start() diff --git a/lib/mix/test/mix/tasks/test_test.exs b/lib/mix/test/mix/tasks/test_test.exs index 81d34889776..0ef3b1af2ae 100644 --- a/lib/mix/test/mix/tasks/test_test.exs +++ b/lib/mix/test/mix/tasks/test_test.exs @@ -620,6 +620,26 @@ defmodule Mix.Tasks.TestTest do end end + describe "--only" do + test "runs only async tests with --only async:true" do + in_fixture("test_async", fn -> + output = mix(["test", "--only", "async:true", "--trace"]) + assert output =~ "2 tests, 0 failures, 1 excluded" + assert output =~ ~r/test f async \(.*ms\)/ + assert output =~ "test f sync (excluded)" + end) + end + + test "runs only sync tests with --only async:false" do + in_fixture("test_async", fn -> + output = mix(["test", "--only", "async:false", "--trace"]) + assert output =~ "2 tests, 0 failures, 1 excluded" + assert output =~ ~r/test f sync \(.*ms\)/ + assert output =~ "test f async (excluded)" + end) + end + end + defp receive_until_match(port, expected, acc) do receive do {^port, {:data, output}} ->