@@ -217,14 +217,19 @@ struct Error <: Result
217
217
context:: Union{Nothing, String}
218
218
source:: LineNumberNode
219
219
220
- function Error (test_type:: Symbol , orig_expr, value, bt, source:: LineNumberNode , context:: Union{Nothing, String} = nothing )
221
- if test_type === :test_error
222
- bt = scrub_exc_stack (bt, nothing , extract_file (source))
223
- end
224
- if test_type === :test_error || test_type === :nontest_error
225
- bt_str = try # try the latest world for this, since we might have eval'd new code for show
220
+ function Error (test_type:: Symbol , orig_expr, value, excs:: Union{Base.ExceptionStack,Nothing} ,
221
+ source:: LineNumberNode , context:: Union{Nothing, String} = nothing )
222
+ @nospecialize orig_expr value
223
+ bt_str = " "
224
+ if ! isnothing (excs)
225
+ if test_type === :test_error
226
+ excs = scrub_exc_stack (excs, nothing , extract_file (source))
227
+ end
228
+ if test_type === :test_error || test_type === :nontest_error
229
+ bt_str = try
230
+ # try the latest world for this, since we might have eval'd new code for show
226
231
# Apply REPL backtrace scrubbing to hide REPL internals, similar to how REPL.jl handles it
227
- Base. invokelatest (sprint, Base. show_exception_stack, Base. scrub_repl_backtrace (bt ); context= stdout )
232
+ Base. invokelatest (sprint, Base. show_exception_stack, Base. scrub_repl_backtrace (excs ); context= stdout )
228
233
catch ex
229
234
" #=ERROR showing exception stack=# " *
230
235
try
@@ -233,8 +238,7 @@ struct Error <: Result
233
238
" of type " * string (typeof (ex))
234
239
end
235
240
end
236
- else
237
- bt_str = " "
241
+ end
238
242
end
239
243
value = try # try the latest world for this, since we might have eval'd new code for show
240
244
Base. invokelatest (sprint, show, value, context = :limit => true )
346
350
347
351
struct Threw <: ExecutionResult
348
352
exception
349
- backtrace :: Union{Nothing,Vector{Any}}
353
+ current_exceptions :: Base.ExceptionStack
350
354
source:: LineNumberNode
351
355
end
352
356
746
750
747
751
# An internal function, called by the code generated by the @test
748
752
# macro to actually perform the evaluation and manage the result.
749
- function do_test (result:: ExecutionResult , orig_expr)
753
+ function do_test (result:: ExecutionResult , @nospecialize orig_expr)
750
754
# get_testset() returns the most recently added test set
751
755
# We then call record() with this test set and the test result
752
756
if isa (result, Returned)
@@ -768,13 +772,13 @@ function do_test(result::ExecutionResult, orig_expr)
768
772
# The predicate couldn't be evaluated without throwing an
769
773
# exception, so that is an Error and not a Fail
770
774
@assert isa (result, Threw)
771
- testres = Error (:test_error , orig_expr, result. exception, result. backtrace :: Vector{Any} , result. source, nothing )
775
+ testres = Error (:test_error , orig_expr, result. exception, result. current_exceptions , result. source, nothing )
772
776
end
773
777
isa (testres, Pass) || trigger_test_failure_break (result)
774
778
record (get_testset (), testres)
775
779
end
776
780
777
- function do_broken_test (result:: ExecutionResult , orig_expr)
781
+ function do_broken_test (result:: ExecutionResult , @nospecialize orig_expr)
778
782
testres = Broken (:test , orig_expr)
779
783
# Assume the test is broken and only change if the result is true
780
784
if isa (result, Returned)
860
864
861
865
# An internal function, called by the code generated by @test_throws
862
866
# to evaluate and catch the thrown exception - if it exists
863
- function do_test_throws (result:: ExecutionResult , orig_expr, extype)
867
+ function do_test_throws (result:: ExecutionResult , @nospecialize ( orig_expr) , extype)
864
868
if isa (result, Threw)
865
869
# Check that the right type of exception was thrown
866
870
success = false
@@ -908,20 +912,17 @@ function do_test_throws(result::ExecutionResult, orig_expr, extype)
908
912
if success
909
913
testres = Pass (:test_throws , orig_expr, extype, exc, result. source, message_only)
910
914
else
911
- if result. backtrace != = nothing
912
- bt = scrub_exc_stack (result. backtrace, nothing , extract_file (result. source))
913
- bt_str = try # try the latest world for this, since we might have eval'd new code for show
914
- Base. invokelatest (sprint, Base. show_exception_stack, bt; context= stdout )
915
- catch ex
916
- " #=ERROR showing exception stack=# " *
917
- try
918
- sprint (Base. showerror, ex, catch_backtrace (); context= stdout )
919
- catch
920
- " of type " * string (typeof (ex))
921
- end
922
- end
923
- else
924
- bt_str = nothing
915
+ excs = result. current_exceptions
916
+ bt = scrub_exc_stack (excs, nothing , extract_file (result. source))
917
+ bt_str = try # try the latest world for this, since we might have eval'd new code for show
918
+ Base. invokelatest (sprint, Base. show_exception_stack, bt; context= stdout )
919
+ catch ex
920
+ " #=ERROR showing exception stack=# " *
921
+ try
922
+ sprint (Base. showerror, ex, catch_backtrace (); context= stdout )
923
+ catch
924
+ " of type " * string (typeof (ex))
925
+ end
925
926
end
926
927
testres = Fail (:test_throws_wrong , orig_expr, extype, exc, nothing , result. source, message_only, bt_str)
927
928
end
@@ -1073,7 +1074,7 @@ end
1073
1074
A simple fallback test set that throws immediately on a failure.
1074
1075
"""
1075
1076
struct FallbackTestSet <: AbstractTestSet end
1076
- fallback_testset = FallbackTestSet ()
1077
+ const fallback_testset = FallbackTestSet ()
1077
1078
1078
1079
struct FallbackTestSetException <: Exception
1079
1080
msg:: String
0 commit comments