From 4aee213ce68149d619cbbe5f3c5b5356cba79c55 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Tue, 17 Aug 2021 11:05:46 -0400 Subject: [PATCH] Address review comments Co-authored by: Jameson Nash Co-authored by: Takafumi Arakaki --- stdlib/Test/src/Test.jl | 25 +++++++++++++------------ stdlib/Test/test/runtests.jl | 2 ++ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/stdlib/Test/src/Test.jl b/stdlib/Test/src/Test.jl index 8afbdc2bc78c59..5ca6b792a9724a 100644 --- a/stdlib/Test/src/Test.jl +++ b/stdlib/Test/src/Test.jl @@ -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 @@ -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 diff --git a/stdlib/Test/test/runtests.jl b/stdlib/Test/test/runtests.jl index 36d7c75d2fe0ae..d260c5840d6262 100644 --- a/stdlib/Test/test/runtests.jl +++ b/stdlib/Test/test/runtests.jl @@ -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")