Skip to content

Commit e65dae9

Browse files
committed
Improvements to ExUnit
* Do not run duplicate cases on ExUnit.run/1 * Allow test cases to not be registered on use * Expose ExUnit.Formatter.format_assertion_diff/4
1 parent 6c5d7bf commit e65dae9

File tree

7 files changed

+255
-188
lines changed

7 files changed

+255
-188
lines changed

lib/ex_unit/lib/ex_unit.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ defmodule ExUnit do
201201

202202
System.at_exit(fn
203203
0 ->
204-
time = ExUnit.Server.modules_loaded()
204+
time = ExUnit.Server.modules_loaded(false)
205205
options = persist_defaults(configuration())
206206
%{failures: failures} = ExUnit.Runner.run(options, time)
207207

@@ -373,7 +373,7 @@ defmodule ExUnit do
373373
end
374374
end
375375

376-
_ = ExUnit.Server.modules_loaded()
376+
_ = ExUnit.Server.modules_loaded(additional_modules != [])
377377
options = persist_defaults(configuration())
378378
ExUnit.Runner.run(options, nil)
379379
end
@@ -399,7 +399,7 @@ defmodule ExUnit do
399399
@doc since: "1.12.0"
400400
@spec await_run(Task.t()) :: suite_result()
401401
def await_run(task) do
402-
ExUnit.Server.modules_loaded()
402+
ExUnit.Server.modules_loaded(false)
403403
Task.await(task, :infinity)
404404
end
405405

lib/ex_unit/lib/ex_unit/assertions.ex

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,19 +260,21 @@ defmodule ExUnit.Assertions do
260260
quote do
261261
left = unquote(left)
262262
right = unquote(right)
263+
expr = unquote(expr)
264+
message = unquote(message)
263265

264266
if ExUnit.Assertions.__equal__?(left, right) do
265267
ExUnit.Assertions.assert(false,
266268
left: left,
267-
expr: unquote(expr),
268-
message: unquote(message <> ", both sides are exactly equal")
269+
expr: expr,
270+
message: message <> ", both sides are exactly equal"
269271
)
270272
else
271273
ExUnit.Assertions.assert(unquote(call),
272274
left: left,
273275
right: right,
274-
expr: unquote(expr),
275-
message: unquote(message),
276+
expr: expr,
277+
message: message,
276278
context: unquote(context)
277279
)
278280
end

lib/ex_unit/lib/ex_unit/case.ex

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ defmodule ExUnit.Case do
284284
raise "you must set @tag, @describetag, and @moduletag after the call to \"use ExUnit.Case\""
285285
end
286286

287-
attributes = [
287+
accumulate_attributes = [
288288
:ex_unit_tests,
289289
:tag,
290290
:describetag,
@@ -294,24 +294,23 @@ defmodule ExUnit.Case do
294294
:ex_unit_registered_module_attributes
295295
]
296296

297-
Enum.each(attributes, &Module.register_attribute(module, &1, accumulate: true))
297+
Enum.each(accumulate_attributes, &Module.register_attribute(module, &1, accumulate: true))
298298

299299
persisted_attributes = [:ex_unit_async]
300+
300301
Enum.each(persisted_attributes, &Module.register_attribute(module, &1, persist: true))
301302

302-
attributes = [
303-
before_compile: ExUnit.Case,
304-
after_compile: ExUnit.Case,
305-
ex_unit_async: false
306-
]
303+
if Keyword.get(opts, :register, true) do
304+
Module.put_attribute(module, :after_compile, ExUnit.Case)
305+
end
307306

308-
Enum.each(attributes, fn {k, v} -> Module.put_attribute(module, k, v) end)
307+
Module.put_attribute(module, :before_compile, ExUnit.Case)
309308
end
310309

311310
async? = opts[:async]
312311

313-
if is_boolean(async?) do
314-
Module.put_attribute(module, :ex_unit_async, async?)
312+
if is_boolean(async?) or not registered? do
313+
Module.put_attribute(module, :ex_unit_async, async? || false)
315314
end
316315

317316
registered?

0 commit comments

Comments
 (0)