Skip to content
This repository was archived by the owner on Jan 18, 2025. It is now read-only.

Commit a735bd4

Browse files
tkfKristofferC
authored andcommitted
Fix a bug with break/continue/return in at-testset begin end (JuliaLang/julia#36046)
(cherry picked from commit 9eaa948)
1 parent 6567fcf commit a735bd4

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

src/Test.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,6 +1100,7 @@ function testset_beginend(args, tests, source)
11001100
# action (such as reporting the results)
11011101
ex = quote
11021102
_check_testset($testsettype, $(QuoteNode(testsettype.args[1])))
1103+
local ret
11031104
local ts = $(testsettype)($desc; $options...)
11041105
push_testset(ts)
11051106
# we reproduce the logic of guardseed, but this function
@@ -1120,9 +1121,10 @@ function testset_beginend(args, tests, source)
11201121
record(ts, Error(:nontest_error, Expr(:tuple), err, Base.catch_stack(), $(QuoteNode(source))))
11211122
finally
11221123
copy!(RNG, oldrng)
1124+
pop_testset()
1125+
ret = finish(ts)
11231126
end
1124-
pop_testset()
1125-
finish(ts)
1127+
ret
11261128
end
11271129
# preserve outer location if possible
11281130
if tests isa Expr && tests.head === :block && !isempty(tests.args) && tests.args[1] isa LineNumberNode

test/runtests.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,3 +919,14 @@ end
919919
# Issue 20620
920920
@test @inferred(.![true, false]) == [false, true]
921921
@test @inferred([3, 4] .- [1, 2] .+ [-2, -2]) == [0, 0]
922+
923+
@testset "push/pop_testset invariance (Issue 32937)" begin
924+
io = IOBuffer()
925+
path = joinpath(@__DIR__(), "test_pop_testset_exec.jl")
926+
cmd = `$(Base.julia_cmd()) $path`
927+
ok = !success(pipeline(cmd; stdout = io, stderr = io))
928+
if !ok
929+
@error "push/pop_testset invariance test failed" cmd Text(String(take!(io)))
930+
end
931+
@test ok
932+
end

test/test_pop_testset_exec.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
using Test
2+
3+
@testset begin
4+
@test false
5+
return
6+
end

0 commit comments

Comments
 (0)