Skip to content

add test for mix test --only async/sync filter #13651

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

Merged
merged 2 commits into from
Jun 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion lib/ex_unit/test/ex_unit_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1101,10 +1101,50 @@ defmodule ExUnitTest do
assert third =~ "ThirdTestFIFO"
end

test "can filter async tests" do
defmodule FirstTestAsyncTrue do
use ExUnit.Case, async: true

test "first test" do
assert true
end
end

defmodule SecondTestAsyncTrue do
use ExUnit.Case, async: true

test "second test" do
assert true
end
end

defmodule FirstTestAsyncFalse do
use ExUnit.Case, async: false

test "first test" do
assert true
end
end

assert {%{failures: 0, skipped: 0, total: 3, excluded: 1}, _} =
run_with_filter([include: [async: true], exclude: [:test]], [])

assert {%{failures: 0, skipped: 0, total: 3, excluded: 2}, _} =
run_with_filter([include: [async: false], exclude: [:test]], [
FirstTestAsyncTrue,
SecondTestAsyncTrue,
FirstTestAsyncFalse
])
end

## Helpers

defp run_with_filter(filters, cases) do
Enum.each(cases, &ExUnit.Server.add_module(&1, {false, nil}))
Enum.each(cases, fn mod ->
[config] = mod.__info__(:attributes) |> Keyword.fetch!(:ex_unit_module)
ExUnit.Server.add_module(mod, config)
end)

ExUnit.Server.modules_loaded(false)

opts =
Expand Down