Skip to content
Closed
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
34 changes: 20 additions & 14 deletions lib/ex_unit/lib/ex_unit/assertions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,16 @@ defmodule ExUnit.Assertions do
{args, value} = extract_args(assertion, __CALLER__)

quote generated: true do
if value = unquote(value) do
value
else
raise ExUnit.AssertionError,
args: unquote(args),
expr: unquote(escape_quoted(:assert, [], assertion)),
message: "Expected truthy, got #{inspect(value)}"
# not using `if` here because we don't want :generated to be propagated and suppress warnings
case unquote(value) do
falsy when falsy in [false, nil] ->
raise ExUnit.AssertionError,
args: unquote(args),
expr: unquote(escape_quoted(:assert, [], assertion)),
message: "Expected truthy, got #{inspect(falsy)}"

truthy ->
truthy
end
end
end
Expand Down Expand Up @@ -238,13 +241,16 @@ defmodule ExUnit.Assertions do
{args, value} = extract_args(assertion, __CALLER__)

quote generated: true do
if value = unquote(value) do
raise ExUnit.AssertionError,
args: unquote(args),
expr: unquote(escape_quoted(:refute, [], assertion)),
message: "Expected false or nil, got #{inspect(value)}"
else
value
# not using `if` here because we don't want :generated to be propagated and suppress warnings
case unquote(value) do
falsy when falsy in [false, nil] ->
falsy

truthy ->
raise ExUnit.AssertionError,
args: unquote(args),
expr: unquote(escape_quoted(:refute, [], assertion)),
message: "Expected false or nil, got #{inspect(truthy)}"
end
end
end
Expand Down