From 96c187ebbd9844834af6a5c2f77ddaea50b9c1c3 Mon Sep 17 00:00:00 2001 From: Kelvin Stinghen Date: Sun, 22 Sep 2019 13:50:27 -0300 Subject: [PATCH] Allow to reset async for ExUnit.Case by using it again (#9360) --- lib/ex_unit/lib/ex_unit/case.ex | 10 ++++--- lib/ex_unit/test/ex_unit/case_test.exs | 36 ++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/lib/ex_unit/lib/ex_unit/case.ex b/lib/ex_unit/lib/ex_unit/case.ex index 934f638f291..097ef89ea63 100644 --- a/lib/ex_unit/lib/ex_unit/case.ex +++ b/lib/ex_unit/lib/ex_unit/case.ex @@ -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] @@ -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] diff --git a/lib/ex_unit/test/ex_unit/case_test.exs b/lib/ex_unit/test/ex_unit/case_test.exs index c1950deba21..6e8b0e5f7d3 100644 --- a/lib/ex_unit/test/ex_unit/case_test.exs +++ b/lib/ex_unit/test/ex_unit/case_test.exs @@ -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