diff --git a/src/Test.jl b/src/Test.jl index 3fb64bd..2081425 100644 --- a/src/Test.jl +++ b/src/Test.jl @@ -1100,6 +1100,7 @@ function testset_beginend(args, tests, source) # action (such as reporting the results) ex = quote _check_testset($testsettype, $(QuoteNode(testsettype.args[1]))) + local ret local ts = $(testsettype)($desc; $options...) push_testset(ts) # we reproduce the logic of guardseed, but this function @@ -1120,9 +1121,10 @@ function testset_beginend(args, tests, source) record(ts, Error(:nontest_error, Expr(:tuple), err, Base.catch_stack(), $(QuoteNode(source)))) finally copy!(RNG, oldrng) + pop_testset() + ret = finish(ts) end - pop_testset() - finish(ts) + ret end # preserve outer location if possible if tests isa Expr && tests.head === :block && !isempty(tests.args) && tests.args[1] isa LineNumberNode diff --git a/test/runtests.jl b/test/runtests.jl index f3c0d49..3307fd4 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -919,3 +919,14 @@ end # Issue 20620 @test @inferred(.![true, false]) == [false, true] @test @inferred([3, 4] .- [1, 2] .+ [-2, -2]) == [0, 0] + +@testset "push/pop_testset invariance (Issue 32937)" begin + io = IOBuffer() + path = joinpath(@__DIR__(), "test_pop_testset_exec.jl") + cmd = `$(Base.julia_cmd()) $path` + ok = !success(pipeline(cmd; stdout = io, stderr = io)) + if !ok + @error "push/pop_testset invariance test failed" cmd Text(String(take!(io))) + end + @test ok +end diff --git a/test/test_pop_testset_exec.jl b/test/test_pop_testset_exec.jl new file mode 100644 index 0000000..3c5fde6 --- /dev/null +++ b/test/test_pop_testset_exec.jl @@ -0,0 +1,6 @@ +using Test + +@testset begin + @test false + return +end