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

@test_throws: don't throw an error if the same field is undefined in both the observed exception and the expected exception #54084

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 16 additions & 1 deletion stdlib/Test/src/Test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,22 @@ function do_test_throws(result::ExecutionResult, orig_expr, extype)
if isa(exc, typeof(extype))
success = true
for fld in 1:nfields(extype)
if !isequal(getfield(extype, fld), getfield(exc, fld))
# We check three cases.
if isdefined(extype, fld) && isdefined(exc, fld)
# Case 1: extype.fld is defined and exc.fld is defined.
# In this case, we compare the two values.
# It is a success iff extype.fld is equal to exc.fld
if !isequal(getfield(extype, fld), getfield(exc, fld))
success = false
break
end
elseif !isdefined(extype, fld) && !isdefined(exc, fld)
# Case 2: extype.fld is undefined and exc.fld is undefined.
# In this case, because both of the fields are undefined,
# we consider this case to be a success.
else
# Case 3: one is defined and the other is undefined.
# We consider this case to be a failure.
success = false
break
end
Expand Down