diff --git a/stdlib/Test/src/Test.jl b/stdlib/Test/src/Test.jl index 1957e9a3baabb..e440367a1f68c 100644 --- a/stdlib/Test/src/Test.jl +++ b/stdlib/Test/src/Test.jl @@ -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 + + 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 @@ -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 @@ -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)`. diff --git a/stdlib/Test/test/runtests.jl b/stdlib/Test/test/runtests.jl index fe7d82e1b737b..2550738d7dce6 100644 --- a/stdlib/Test/test/runtests.jl +++ b/stdlib/Test/test/runtests.jl @@ -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 @@ -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