Skip to content

Commit 4997f7e

Browse files
committed
Show evaluated arguments for most function calls
1 parent c2627ad commit 4997f7e

File tree

2 files changed

+14
-66
lines changed

2 files changed

+14
-66
lines changed

stdlib/Test/src/Test.jl

+4-38
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,6 @@ using InteractiveUtils: gen_call_with_extracted_types
3030
using Base: typesplit, remove_linenums!
3131
using Serialization: Serialization
3232

33-
# Whitelist boolean functions which show their evaluated arguments when the test fails
34-
const DISPLAY_FAILED = (
35-
:isequal,
36-
:isapprox,
37-
:,
38-
:occursin,
39-
:startswith,
40-
:endswith,
41-
:isempty,
42-
:contains
43-
)
44-
4533
const FAIL_FAST = Ref{Bool}(false)
4634

4735
#-----------------------------------------------------------------------
@@ -584,35 +572,14 @@ macro test_skip(ex, kws...)
584572
return :(record(get_testset(), $testres))
585573
end
586574

587-
function _is_simple_call(@nospecialize ex)
575+
function _can_escape_call(@nospecialize ex)
588576
ex.head === :call || return false
589577

590578
# Broadcasted functions are not currently supported
591579
first(string(ex.args[1])) != '.' || return false
592580

593-
num_pargs = 0
594-
for x in ex.args[2:end]
595-
if isa(x, Expr) && x.head === :parameters
596-
return false
597-
elseif isa(x, Expr) && x.head === :kw
598-
return false
599-
elseif isa(x, Expr) && x.head === :...
600-
return false # Unable to determine number of arguments
601-
else
602-
num_pargs += 1
603-
end
604-
end
605-
606-
return 1 <= num_pargs <= 2
607-
end
608-
609-
function _function_name(@nospecialize ex)
610-
ex.head === :call || throw(ArgumentError("$ex is not a call expression"))
611-
if isa(ex.args[1], Expr) && ex.args[1].head === :.
612-
ex.args[1].args[2].value
613-
else
614-
ex.args[1]
615-
end
581+
# At least one positional argument or keyword
582+
return length(ex.args) > 1
616583
end
617584

618585
# An internal function, called by the code generated by the @test
@@ -651,8 +618,7 @@ function get_test_result(ex, source)
651618
$(QuoteNode(source)),
652619
$negate,
653620
))
654-
elseif isa(ex, Expr) && ex.head === :call &&
655-
(_is_simple_call(ex) || _function_name(ex) in DISPLAY_FAILED)
621+
elseif isa(ex, Expr) && _can_escape_call(ex)
656622
escaped_func = esc(ex.args[1])
657623
quoted_func = QuoteNode(ex.args[1])
658624

stdlib/Test/test/runtests.jl

+10-28
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

33
using Test, Random
4-
using Test: guardseed, _is_simple_call, _function_name
4+
using Test: guardseed, _can_escape_call
55
using Serialization
66
using Distributed: RemoteException
77

@@ -212,7 +212,7 @@ let fails = @testset NoThrowTestSet begin
212212

213213
let str = sprint(show, fails[8])
214214
@test occursin("Expression: (==)(1:2...)", str)
215-
@test !occursin("Evaluated", str)
215+
@test occursin("Evaluated: 1 == 2", str)
216216
end
217217

218218
let str = sprint(show, fails[9])
@@ -286,7 +286,6 @@ let fails = @testset NoThrowTestSet begin
286286
end
287287

288288
let str = sprint(show, fails[23])
289-
@test !(:issetequal in Test.DISPLAY_FAILED)
290289
@test occursin("Expression: issetequal(a, b)", str)
291290
@test occursin("Evaluated: issetequal([1, 2], [1, 3])", str)
292291
end
@@ -1794,30 +1793,13 @@ end
17941793
end
17951794
end
17961795

1797-
@testset "_is_simple_function" begin
1798-
@test !_is_simple_call(:(f()))
1799-
@test _is_simple_call(:(f(x)))
1800-
@test _is_simple_call(:(f(x, y)))
1801-
@test !_is_simple_call(:(f(x, y, z)))
1802-
1803-
@test !_is_simple_call(:(f(; x)))
1804-
@test !_is_simple_call(:(f(; x, y)))
1805-
@test !_is_simple_call(:(f(x=1)))
1806-
@test !_is_simple_call(:(f(x=1, y=2)))
1807-
1808-
@test !_is_simple_call(:(f(x, y=1)))
1809-
@test !_is_simple_call(:(f(x; y=1)))
1810-
1811-
@test !_is_simple_call(:(f(x...)))
1812-
@test !_is_simple_call(:(f(x, y...)))
1813-
@test !_is_simple_call(:(f(x; y...)))
1814-
1815-
@test _is_simple_call(:(x == y))
1816-
@test !_is_simple_call(:(x .== y))
1817-
end
1796+
@testset "_can_escape_call" begin
1797+
@test !_can_escape_call(:(f()))
1798+
@test _can_escape_call(:(f(x)))
1799+
@test _can_escape_call(:(f(; x)))
1800+
@test _can_escape_call(:(f(x=1)))
18181801

1819-
@testset "_function_name" begin
1820-
@test _function_name(:(isequal(x, y))) === :isequal
1821-
@test _function_name(:(Base.isequal(x.y))) === :isequal
1822-
@test _function_name(:(Base.Meta.isexpr(ex))) === :isexpr
1802+
@test _can_escape_call(:(x == y))
1803+
@test !_can_escape_call(:(x .== y))
1804+
@test !_can_escape_call(:((==).(x, y)))
18231805
end

0 commit comments

Comments
 (0)