Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions stdlib/Test/src/Test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1726,6 +1726,10 @@ end
trigger_test_failure_break(@nospecialize(err)) =
ccall(:jl_test_failure_breakpoint, Cvoid, (Any,), err)

is_failfast_error(err::FailFastError) = true
is_failfast_error(err::LoadError) = is_failfast_error(err.error) # handle `include` barrier
is_failfast_error(err) = false

"""
Generate the code for an `@testset` with a `let` argument.
"""
Expand Down Expand Up @@ -1837,7 +1841,7 @@ function testset_beginend_call(args, tests, source)
# something in the test block threw an error. Count that as an
# error in this test set
trigger_test_failure_break(err)
if err isa FailFastError
if is_failfast_error(err)
get_testset_depth() > 1 ? rethrow() : failfast_print()
else
record(ts, Error(:nontest_error, Expr(:tuple), err, Base.current_exceptions(), $(QuoteNode(source))))
Expand Down Expand Up @@ -1925,7 +1929,9 @@ function testset_forloop(args, testloop, source)
# Something in the test block threw an error. Count that as an
# error in this test set
trigger_test_failure_break(err)
if !isa(err, FailFastError)
if is_failfast_error(err)
get_testset_depth() > 1 ? rethrow() : failfast_print()
else
record(ts, Error(:nontest_error, Expr(:tuple), err, Base.current_exceptions(), $(QuoteNode(source))))
end
end
Expand Down
28 changes: 27 additions & 1 deletion stdlib/Test/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1394,7 +1394,7 @@ end
@test occursin(expected, result)
end
end
@testset "failfast" begin
@testset "failfast begin-end" begin
expected = r"""
Test Summary: \| Fail Total +Time
Foo \| 1 1 \s*\d*\.\ds
Expand All @@ -1419,6 +1419,32 @@ end
@test occursin(expected, result)
end
end
@testset "failfast for-loop" begin
expected = r"""
Test Summary: \| Fail Total +Time
Foo \| 1 1 \s*\d*\.\ds
1 \| 1 1 \s*\d*\.\ds
"""
mktemp() do f, _
write(f,
"""
using Test

@testset "Foo" failfast=true begin
@testset "\$x" for x in 1:2
@test false
end
@testset "Bar" begin
@test false
@test true
end
end
""")
cmd = `$(Base.julia_cmd()) --startup-file=no --color=no $f`
result = read(pipeline(ignorestatus(cmd), stderr=devnull), String)
@test occursin(expected, result)
end
end
@testset "failfast passes to child testsets" begin
expected = r"""
Test Summary: \| Fail Total +Time
Expand Down