Skip to content

Commit

Permalink
Fix a bug with break/continue/return in at-testset begin end (#36046)
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf authored Jun 1, 2020
1 parent 7301dc6 commit 932a1ec
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
6 changes: 4 additions & 2 deletions stdlib/Test/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 stdlib/Test/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 stdlib/Test/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 932a1ec

Please sign in to comment.