Skip to content

Commit

Permalink
Fix a bug with break/continue/return in at-testset begin end (JuliaLa…
Browse files Browse the repository at this point in the history
…ng/julia#36046)

(cherry picked from commit 9eaa948)
  • Loading branch information
tkf authored and KristofferC committed Jun 4, 2020
1 parent 6567fcf commit a735bd4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
11 changes: 11 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions test/test_pop_testset_exec.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
using Test

@testset begin
@test false
return
end

0 comments on commit a735bd4

Please sign in to comment.