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

Restore support for checking for UndefVarError variable name in at-test_throws #56231

Merged
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
6 changes: 5 additions & 1 deletion stdlib/Test/src/Test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,11 @@ function do_test_throws(result::ExecutionResult, orig_expr, extype)
if extype isa LoadError && !(exc isa LoadError) && typeof(extype.error) == typeof(exc)
extype = extype.error # deprecated
end
if isa(exc, typeof(extype))
# Support `UndefVarError(:x)` meaning `UndefVarError(:x, scope)` for any `scope`.
# Retains the behaviour from pre-v1.11 when `UndefVarError` didn't have `scope`.
if isa(extype, UndefVarError) && !isdefined(extype, :scope)
success = exc isa UndefVarError && exc.var == extype.var
else isa(exc, typeof(extype))
success = true
for fld in 1:nfields(extype)
if !isequal(getfield(extype, fld), getfield(exc, fld))
Expand Down
17 changes: 17 additions & 0 deletions stdlib/Test/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1736,3 +1736,20 @@ end
This is deprecated and may error in the future."""
@test_deprecated msg2 @macroexpand @testset DefaultTestSet DefaultTestSet begin end
end

# Issue #54082
module M54082 end
@testset "@test_throws UndefVarError(:var)" begin
# Single-arg `UndefVarError` should match all `UndefVarError` for the
# same variable name, regardless of scope, to keep pre-v1.11 behaviour.
f54082() = var
@test_throws UndefVarError(:var) f54082()
# But if scope is set, then it has to match.
@test_throws UndefVarError(:var, M54082) M54082.var
let result = @testset NoThrowTestSet begin
# Wrong module scope
@test_throws UndefVarError(:var, Main) M54082.var
end
@test only(result) isa Test.Fail
end
end