@@ -259,48 +259,60 @@ defmodule ExUnit.Case do
259
259
end
260
260
261
261
quote do
262
- unless Module . has_attribute? ( __MODULE__ , :ex_unit_tests ) do
263
- tag_check =
264
- [ :moduletag , :describetag , :tag ]
265
- |> Enum . any? ( & Module . has_attribute? ( __MODULE__ , & 1 ) )
266
-
267
- if tag_check do
268
- raise "you must set @tag, @describetag, and @moduletag after the call to \" use ExUnit.Case\" "
269
- end
270
-
271
- attributes = [
272
- :ex_unit_tests ,
273
- :tag ,
274
- :describetag ,
275
- :moduletag ,
276
- :ex_unit_registered_test_attributes ,
277
- :ex_unit_registered_describe_attributes ,
278
- :ex_unit_registered_module_attributes ,
279
- :ex_unit_used_describes
280
- ]
281
-
282
- Enum . each ( attributes , & Module . register_attribute ( __MODULE__ , & 1 , accumulate: true ) )
283
-
284
- @ before_compile ExUnit.Case
285
- @ after_compile ExUnit.Case
286
- @ ex_unit_async false
287
- @ ex_unit_describe nil
262
+ unless ExUnit.Case . __register__ ( __MODULE__ , unquote ( opts ) ) do
288
263
use ExUnit.Callbacks
289
264
end
290
265
291
- async = unquote ( opts ) [ :async ]
292
-
293
- if is_boolean ( async ) do
294
- @ ex_unit_async async
295
- end
296
-
297
266
import ExUnit.Callbacks
298
267
import ExUnit.Assertions
299
268
import ExUnit.Case , only: [ describe: 2 , test: 1 , test: 2 , test: 3 ]
300
269
import ExUnit.DocTest
301
270
end
302
271
end
303
272
273
+ @ doc false
274
+ def __register__ ( module , opts ) do
275
+ registered? = Module . has_attribute? ( module , :ex_unit_tests )
276
+
277
+ unless registered? do
278
+ tag_check = Enum . any? ( [ :moduletag , :describetag , :tag ] , & Module . has_attribute? ( module , & 1 ) )
279
+
280
+ if tag_check do
281
+ raise "you must set @tag, @describetag, and @moduletag after the call to \" use ExUnit.Case\" "
282
+ end
283
+
284
+ attributes = [
285
+ :ex_unit_tests ,
286
+ :tag ,
287
+ :describetag ,
288
+ :moduletag ,
289
+ :ex_unit_registered_test_attributes ,
290
+ :ex_unit_registered_describe_attributes ,
291
+ :ex_unit_registered_module_attributes ,
292
+ :ex_unit_used_describes
293
+ ]
294
+
295
+ Enum . each ( attributes , & Module . register_attribute ( module , & 1 , accumulate: true ) )
296
+
297
+ attributes = [
298
+ before_compile: ExUnit.Case ,
299
+ after_compile: ExUnit.Case ,
300
+ ex_unit_async: false ,
301
+ ex_unit_describe: nil
302
+ ]
303
+
304
+ Enum . each ( attributes , fn { k , v } -> Module . put_attribute ( module , k , v ) end )
305
+ end
306
+
307
+ async? = opts [ :async ]
308
+
309
+ if is_boolean ( async? ) do
310
+ Module . put_attribute ( module , :ex_unit_async , async? )
311
+ end
312
+
313
+ registered?
314
+ end
315
+
304
316
@ doc """
305
317
Defines a test with `message`.
306
318
0 commit comments