You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Show evaluated test arguments for most functions (#57825)
When using `@test` any function call, except for broadcast calls, will
always display the evaluated arguments. Having this makes it much easier
at a glance to debug the problem:
```julia
julia> using Test
julia> x = [1,2];
julia> y = [1,3];
julia> @test issubset(x, y)
Test Failed at REPL[5]:1
Expression: issubset(x, y)
Evaluated: issubset([1, 2], [1, 3])
ERROR: There was an error during testing
```
Alternatively, users could use `@testset let` however it can be quite
tedious to add those blocks to test suites.
Copy file name to clipboardexpand all lines: stdlib/Test/src/Test.jl
+15-14
Original file line number
Diff line number
Diff line change
@@ -30,17 +30,6 @@ using InteractiveUtils: gen_call_with_extracted_types
30
30
using Base: typesplit, remove_linenums!
31
31
using Serialization: Serialization
32
32
33
-
const DISPLAY_FAILED = (
34
-
:isequal,
35
-
:isapprox,
36
-
:≈,
37
-
:occursin,
38
-
:startswith,
39
-
:endswith,
40
-
:isempty,
41
-
:contains
42
-
)
43
-
44
33
const FAIL_FAST =Ref{Bool}(false)
45
34
46
35
const record_passes =OncePerProcess{Bool}() do
@@ -201,7 +190,7 @@ function Base.show(io::IO, t::Fail)
201
190
print(io, "\n Expected: ", data)
202
191
print(io, "\n No exception thrown")
203
192
elseif t.test_type ===:test
204
-
if data !==nothing
193
+
if data !==nothing&& t.orig_expr != data
205
194
# The test was an expression, so display the term-by-term
206
195
# evaluated version as well
207
196
print(io, "\n Evaluated: ", data)
@@ -587,6 +576,16 @@ macro test_skip(ex, kws...)
587
576
return :(record(get_testset(), $testres))
588
577
end
589
578
579
+
function_can_escape_call(@nospecialize ex)
580
+
ex.head ===:call||returnfalse
581
+
582
+
# Broadcasted functions are not currently supported
583
+
first(string(ex.args[1])) !='.'||returnfalse
584
+
585
+
# At least one positional argument or keyword
586
+
returnlength(ex.args) >1
587
+
end
588
+
590
589
# An internal function, called by the code generated by the @test
591
590
# macro to get results of the test expression.
592
591
# In the special case of a comparison, e.g. x == 5, generate code to
@@ -623,7 +622,7 @@ function get_test_result(ex, source)
623
622
$(QuoteNode(source)),
624
623
$negate,
625
624
))
626
-
elseifisa(ex, Expr) &&ex.head ===:call&& ex.args[1] in DISPLAY_FAILED
625
+
elseifisa(ex, Expr) &&_can_escape_call(ex)
627
626
escaped_func =esc(ex.args[1])
628
627
quoted_func =QuoteNode(ex.args[1])
629
628
@@ -820,7 +819,7 @@ function do_test_throws(result::ExecutionResult, orig_expr, extype)
820
819
Base.depwarn("macroexpand no longer throws a LoadError so `@test_throws LoadError ...` is deprecated and passed without checking the error type!", :do_test_throws)
0 commit comments