Skip to content
Closed
Show file tree
Hide file tree
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
18 changes: 11 additions & 7 deletions stdlib/Test/src/Test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,10 @@ struct Threw <: ExecutionResult
source::LineNumberNode
end

_quote_evaluated_arg(x::Union{Symbol, Expr, QuoteNode}) = Expr(:quote, x)
_quote_evaluated_arg(x) = x
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like Meta.quot should maybe behave like this, but that's outside the scope of this PR.



function eval_test_comparison(comparison::Expr, quoted::Expr, source::LineNumberNode, negate::Bool=false)
comparison.head === :comparison || throw(ArgumentError("$comparison is not a comparison expression"))
comparison_args = comparison.args
Expand All @@ -382,8 +386,8 @@ function eval_test_comparison(comparison::Expr, quoted::Expr, source::LineNumber
if res
res = op(a, b)
end
quoted_args[i] = a
quoted_args[i+2] = b
quoted_args[i] = _quote_evaluated_arg(a)
quoted_args[i+2] = _quote_evaluated_arg(b)
i += 2
end

Expand All @@ -405,13 +409,13 @@ function eval_test_function(func, args, kwargs, quoted_func::Union{Expr,Symbol},
# the arguments evaluated
kw_suffix = ""
if quoted_func === :≈ && !res
kw_suffix = " ($(join(["$k=$v" for (k, v) in kwargs], ", ")))"
quoted_args = args
kw_suffix = " ($(join(["$k=$(repr(v))" for (k, v) in kwargs], ", ")))"
quoted_args = map(_quote_evaluated_arg, args)
elseif isempty(kwargs)
quoted_args = args
quoted_args = map(_quote_evaluated_arg, args)
else
kwargs_expr = Expr(:parameters, [Expr(:kw, k, v) for (k, v) in kwargs]...)
quoted_args = [kwargs_expr, args...]
kwargs_expr = Expr(:parameters, [Expr(:kw, k, _quote_evaluated_arg(v)) for (k, v) in kwargs]...)
quoted_args = Any[kwargs_expr, map(_quote_evaluated_arg, args)...]
end

# Properly render broadcast function call syntax, e.g. `(==).(1, 2)` or `Base.:(==).(1, 2)`.
Expand Down
21 changes: 21 additions & 0 deletions stdlib/Test/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,13 @@ let fails = @testset NoThrowTestSet begin
@test_throws r"sqrt\([Cc]omplx" sqrt(-1)
@test_throws str->occursin("a T", str) error("a test")
@test_throws ["BoundsError", "acquire", "1-element", "at index [2]"] [1][2]
# 34-36 - Fail - symbol, expr, quotenode
sym_var = :sym
expr_var = :(a + b)
qn_var = QuoteNode(:sym)
@test sym_var == 1
@test expr_var == 1
@test qn_var == 1
end
for fail in fails
@test fail isa Test.Fail
Expand Down Expand Up @@ -597,6 +604,20 @@ let fails = @testset NoThrowTestSet begin
@test occursin(r"Message: \"BoundsError.* 1-element.*at index \[2\]", str)
end

let str = sprint(show, fails[34])
@test occursin("Expression: sym_var == 1", str)
@test occursin("Evaluated: :sym == 1", str)
end

let str = sprint(show, fails[35])
@test occursin("Expression: expr_var == 1", str)
@test occursin("Evaluated: :(a + b) == 1", str)
end

let str = sprint(show, fails[36])
@test occursin("Expression: qn_var == 1", str)
@test occursin("Evaluated: :(:sym) == 1", str)
end
end

struct BadError <: Exception end
Expand Down