From 0c83a231bfc70ed82854a01592670425f749bd2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Belmant?= Date: Fri, 5 May 2023 08:47:57 +0200 Subject: [PATCH] Don't assume macro expansion info is present in stacktrace (#49633) --- stdlib/Test/src/Test.jl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/stdlib/Test/src/Test.jl b/stdlib/Test/src/Test.jl index 48b37ef8047fe..811477e7d767c 100644 --- a/stdlib/Test/src/Test.jl +++ b/stdlib/Test/src/Test.jl @@ -64,9 +64,9 @@ function test_callsite(bt, file_ts, file_t) # For that, we retrieve locations from lower to higher stack elements # and only traverse parts of the backtrace which we haven't traversed before. # The order will always be -> `@test` -> `@testset`. - internal = macrocall_location(bt, @__FILE__)::Int + internal = @something(macrocall_location(bt, @__FILE__), return nothing) test = internal - 1 + findfirst(ip -> any(frame -> in_file(frame, file_t), StackTraces.lookup(ip)), @view bt[internal:end])::Int - testset = test - 1 + macrocall_location(@view(bt[test:end]), file_ts)::Int + testset = test - 1 + @something(macrocall_location(@view(bt[test:end]), file_ts), return nothing) # If stacktrace locations differ, include frames until the `@testset` appears. test != testset && return testset @@ -74,7 +74,8 @@ function test_callsite(bt, file_ts, file_t) # This may happen if `@test` occurred directly in scope of the testset, # or if `@test` occurred in a function that has been inlined in the testset. frames = StackTraces.lookup(bt[testset]) - outer_frame = findfirst(frame -> in_file(frame, file_ts) && frame.func == Symbol("macro expansion"), frames)::Int + outer_frame = findfirst(frame -> in_file(frame, file_ts) && frame.func == Symbol("macro expansion"), frames) + isnothing(outer_frame) && return nothing # The `@test` call occurred directly in scope of a `@testset`. # The __source__ from `@test` will be printed in the test message upon failure. # There is no need to include more frames, but always include at least the internal macrocall location in the stacktrace.