Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show evaluated test arguments for set/char/numeric comparison functions #57820

Closed
wants to merge 6 commits into from
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
36 changes: 31 additions & 5 deletions stdlib/Test/src/Test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,40 @@ using InteractiveUtils: gen_call_with_extracted_types
using Base: typesplit, remove_linenums!
using Serialization: Serialization

# Whitelist boolean functions which show their evaluated arguments when the test fails
const DISPLAY_FAILED = (
:isequal,
:isapprox,
:≈,
:occursin,
:startswith,
:contains,
:endswith,
:isapprox,
:isascii,
:iscntrl,
:isdigit,
:isdisjoint,
:isletter,
:islowercase,
:isempty,
:contains
:isequal,
:isfinite,
:isinf,
:isinteger,
:ismissing,
:isnothing,
:isnumeric,
:isprint,
:ispunct,
:isnan,
:isone,
:isreal,
:issetequal,
:isspace,
:issubset,
:isuppercase,
:isvalid,
:isxdigit,
:iszero,
:occursin,
:startswith,
)

const FAIL_FAST = Ref{Bool}(false)
Expand Down Expand Up @@ -1623,6 +1648,7 @@ julia> @testset let logi = log(im)
end
Test Failed at none:3
Expression: !(iszero(real(logi)))
Evaluated: !(iszero(0.0))
Context: logi = 0.0 + 1.5707963267948966im

ERROR: There was an error during testing
Expand Down
9 changes: 9 additions & 0 deletions stdlib/Test/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ 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]
# 27 - Fail - issetequal
a = [1, 2]
b = [1, 3]
@test issetequal(a, b)
end
for fail in fails
@test fail isa Test.Fail
Expand Down Expand Up @@ -298,6 +302,11 @@ let fails = @testset NoThrowTestSet begin
@test occursin(r"Message: \"BoundsError.* 1-element.*at index \[2\]", str)
end

let str = sprint(show, fails[27])
@test occursin("Expression: issetequal(a, b)", str)
@test occursin("Evaluated: issetequal([1, 2], [1, 3])", str)
end

end

struct BadError <: Exception end
Expand Down