Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
Co-authored by: Jameson Nash <vtjnash@gmail.com>
Co-authored by: Takafumi Arakaki <aka.tkf@gmail.com>
  • Loading branch information
timholy committed Aug 17, 2021
1 parent ac4ec80 commit 4aee213
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
25 changes: 13 additions & 12 deletions stdlib/Test/src/Test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -725,9 +725,6 @@ function do_test_throws(result::ExecutionResult, orig_expr, extype)
orig_expr isa Expr &&
orig_expr.head in (:call, :macrocall) &&
orig_expr.args[1] in MACROEXPAND_LIKE
if extype isa LoadError && !(exc isa LoadError) && typeof(extype.error) == typeof(exc)
extype = extype.error # deprecated
end
if isa(extype, Type)
success =
if from_macroexpand && extype == LoadError && exc isa Exception
Expand All @@ -736,22 +733,26 @@ function do_test_throws(result::ExecutionResult, orig_expr, extype)
else
isa(exc, extype)
end
elseif isa(exc, typeof(extype))
success = true
for fld in 1:nfields(extype)
if !isequal(getfield(extype, fld), getfield(exc, fld))
success = false
break
elseif isa(extype, Exception) || !isa(exc, Exception)
if extype isa LoadError && !(exc isa LoadError) && typeof(extype.error) == typeof(exc)
extype = extype.error # deprecated
end
if isa(exc, typeof(extype))
success = true
for fld in 1:nfields(extype)
if !isequal(getfield(extype, fld), getfield(exc, fld))
success = false
break
end
end
end
elseif isa(extype, Exception)
else
message_only = true
exc = sprint(showerror, exc)
success = contains_warn(exc, extype)
exc = '"' * escape_string(exc) * '"'
exc = repr(exc)
if isa(extype, AbstractString)
extype = '"' * escape_string(extype) * '"'
extype = repr(extype)
elseif isa(extype, Function)
extype = "< match function >"
end
Expand Down
2 changes: 2 additions & 0 deletions stdlib/Test/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ end
"Message: \"a test\"")
@test endswith(sprint(show, @test_throws ["BoundsError", "access", "1-element", "at index [2]"] [1][2]),
"Message: \"BoundsError: attempt to access 1-element Vector{$Int} at index [2]\"")
@test_throws "\"" throw("\"")
@test_throws Returns(false) throw(Returns(false))
end
# Test printing of Fail results
include("nothrow_testset.jl")
Expand Down

0 comments on commit 4aee213

Please sign in to comment.