Skip to content

Commit

Permalink
Allow to reset async for ExUnit.Case by using it again (#9360)
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvinst authored and whatyouhide committed Sep 22, 2019
1 parent 36a1a98 commit 96c187e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/ex_unit/lib/ex_unit/case.ex
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,6 @@ defmodule ExUnit.Case do
end

quote do
async = !!unquote(opts)[:async]

unless Module.has_attribute?(__MODULE__, :ex_unit_tests) do
tag_check =
[:moduletag, :describetag, :tag]
Expand All @@ -249,11 +247,17 @@ defmodule ExUnit.Case do

@before_compile ExUnit.Case
@after_compile ExUnit.Case
@ex_unit_async async
@ex_unit_async false
@ex_unit_describe nil
use ExUnit.Callbacks
end

async = unquote(opts)[:async]

if is_boolean(async) do
@ex_unit_async async
end

import ExUnit.Callbacks
import ExUnit.Assertions
import ExUnit.Case, only: [describe: 2, test: 1, test: 2, test: 3]
Expand Down
36 changes: 36 additions & 0 deletions lib/ex_unit/test/ex_unit/case_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,39 @@ defmodule ExUnit.CaseTest do
end
end
end

defmodule ExUnit.DoubleCaseTest1 do
use ExUnit.Case, async: true
use ExUnit.Case

test "async must be true", context do
assert context.async
end
end

defmodule ExUnit.DoubleCaseTest2 do
use ExUnit.Case, async: false
use ExUnit.Case

test "async must be false", context do
refute context.async
end
end

defmodule ExUnit.DoubleCaseTest3 do
use ExUnit.Case, async: true
use ExUnit.Case, async: false

test "async must be false", context do
refute context.async
end
end

defmodule ExUnit.DoubleCaseTest4 do
use ExUnit.Case
use ExUnit.Case, async: true

test "async must be true", context do
assert context.async
end
end

0 comments on commit 96c187e

Please sign in to comment.