Skip to content

Commit

Permalink
FieldError shim to avoid breaks in tests (#54809)
Browse files Browse the repository at this point in the history
Original commit introducing FieldError exception is 7e5d9a3. Since
existing packages were using `ErrorException` to capture `no field`
errors, we need to have a shim to avoid test breaks for external
packages with such uses until they update to `FieldError`.

addressing `need shim for FieldError` #54807

---------

Co-authored-by: Lilith Orion Hafner <[email protected]>
  • Loading branch information
arhik and LilithHafner committed Jun 15, 2024
1 parent 0ae5b32 commit 319d890
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions stdlib/Test/src/Test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,9 @@ function do_test_throws(result::ExecutionResult, orig_expr, extype)
if from_macroexpand && extype == LoadError && exc isa Exception
Base.depwarn("macroexpand no longer throws a LoadError so `@test_throws LoadError ...` is deprecated and passed without checking the error type!", :do_test_throws)
true
elseif extype == ErrorException && isa(exc, FieldError)
Base.depwarn(lazy"ErrorException should no longer be used to test field access; FieldError should be used instead!", :do_test_throws)
true
else
isa(exc, extype)
end
Expand Down
16 changes: 16 additions & 0 deletions stdlib/Test/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1534,6 +1534,22 @@ end
@test_throws LoadError("file", 111, ErrorException("Real error")) @macroexpand @test_macro_throw_2
end

# Issue 54807
struct FEexc
a::Nothing
b::Nothing
end

@testset "FieldError Shim tests and Softdeprecation of @test_throws ErrorException" begin
feexc = FEexc(nothing, nothing)
# This is redundant regular test for FieldError
@test_throws FieldError feexc.c
# This should raise ErrorException
@test_throws ErrorException feexc.a = 1
# This is test for FieldError shim and deprecation
@test_deprecated @test_throws ErrorException feexc.c
end

# Issue 25483
mutable struct PassInformationTestSet <: Test.AbstractTestSet
results::Vector
Expand Down

2 comments on commit 319d890

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily package evaluation, I will reply here when finished:

@nanosoldier runtests(isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The package evaluation job you requested has completed - possible new issues were detected.
The full report is available.

Please sign in to comment.