Skip to content

Commit 25a22ba

Browse files
committed
Improve error reporting.
1 parent fdc79e1 commit 25a22ba

File tree

2 files changed

+70
-47
lines changed

2 files changed

+70
-47
lines changed

src/ParallelTestRunner.jl

Lines changed: 50 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ function runtests(ARGS; testfilter = Returns(true), RecordType = TestRecord,
751751
end
752752
end
753753

754-
# construct a testset to render the test results
754+
# construct a testset containing all results
755755
function create_testset(name; start=nothing, stop=nothing, kwargs...)
756756
if start === nothing
757757
testset = Test.DefaultTestSet(name; kwargs...)
@@ -780,68 +780,71 @@ function runtests(ARGS; testfilter = Returns(true), RecordType = TestRecord,
780780
end
781781
t1 = time()
782782
o_ts = create_testset("Overall"; start=t0, stop=t1, verbose=do_verbose)
783-
with_testset(o_ts) do
784-
completed_tests = Set{String}()
785-
for (testname, result, start, stop) in results
786-
push!(completed_tests, testname)
787-
788-
# decode or fake a testset
789-
if isa(result, AbstractTestRecord)
790-
testset = result.test
791-
else
792-
testset = create_testset(testname; start, stop)
793-
if isa(result, RemoteException) &&
794-
isa(result.captured.ex, Test.TestSetException)
795-
println(io_ctx.stderr, "Worker $(result.pid) failed running test $(testname):")
796-
Base.showerror(io_ctx.stderr, result.captured)
797-
println(io_ctx.stderr)
798-
799-
c = IOCapture.capture() do
783+
function collect_results()
784+
with_testset(o_ts) do
785+
completed_tests = Set{String}()
786+
for (testname, result, start, stop) in results
787+
push!(completed_tests, testname)
788+
789+
# decode or fake a testset
790+
if isa(result, AbstractTestRecord)
791+
testset = result.test
792+
else
793+
testset = create_testset(testname; start, stop)
794+
if isa(result, RemoteException) &&
795+
isa(result.captured.ex, Test.TestSetException)
800796
for i in 1:result.captured.ex.pass
801-
Test.record(testset, Test.Pass(:test, nothing, nothing, nothing, nothing))
797+
Test.record(testset, Test.Pass(:test, nothing, nothing, nothing, LineNumberNode(@__LINE__, @__FILE__)))
802798
end
803799
for i in 1:result.captured.ex.broken
804800
Test.record(testset, Test.Broken(:test, nothing))
805801
end
806802
for t in result.captured.ex.errors_and_fails
807803
Test.record(testset, t)
808804
end
805+
else
806+
if !isa(result, Exception)
807+
result = ErrorException(string("Unknown result type : ", typeof(result)))
808+
end
809+
# If this test raised an exception that is not a remote testset exception,
810+
# i.e. not a RemoteException capturing a TestSetException that means
811+
# the test runner itself had some problem, so we may have hit a segfault,
812+
# deserialization errors or something similar. Record this testset as Errored.
813+
Test.record(testset, Test.Error(:nontest_error, testname, nothing, Base.ExceptionStack(NamedTuple[(;exception = result, backtrace = [])]), LineNumberNode(1)))
809814
end
810-
print(io_ctx.stdout, c.output)
811-
else
812-
if !isa(result, Exception)
813-
result = ErrorException(string("Unknown result type : ", typeof(result)))
814-
end
815-
# If this test raised an exception that is not a remote testset exception,
816-
# i.e. not a RemoteException capturing a TestSetException that means
817-
# the test runner itself had some problem, so we may have hit a segfault,
818-
# deserialization errors or something similar. Record this testset as Errored.
819-
c = IOCapture.capture() do
820-
Test.record(testset, Test.Error(:nontest_error, testname, nothing, Base.ExceptionStack([(exception = result, backtrace = [])]), LineNumberNode(1)))
821-
end
822-
print(io_ctx.stdout, c.output)
823815
end
824-
end
825816

826-
# record the testset
827-
with_testset(testset) do
828-
Test.record(o_ts, testset)
817+
with_testset(testset) do
818+
Test.record(o_ts, testset)
819+
end
829820
end
830-
end
831821

832-
# mark remaining or running tests as interrupted
833-
for test in [tests; collect(keys(running_tests))]
834-
(test in completed_tests) && continue
835-
testset = create_testset(test)
836-
c = IOCapture.capture() do
837-
Test.record(testset, Test.Error(:test_interrupted, test, nothing, Base.ExceptionStack([(exception = "skipped", backtrace = [])]), LineNumberNode(1)))
838-
end
839-
# don't print the output of interrupted tests, it's not useful
840-
with_testset(testset) do
841-
Test.record(o_ts, testset)
822+
# mark remaining or running tests as interrupted
823+
for test in [tests; collect(keys(running_tests))]
824+
(test in completed_tests) && continue
825+
testset = create_testset(test)
826+
Test.record(testset, Test.Error(:test_interrupted, test, nothing, Base.ExceptionStack(NamedTuple[(;exception = "skipped", backtrace = [])]), LineNumberNode(1), nothing))
827+
with_testset(testset) do
828+
Test.record(o_ts, testset)
829+
end
842830
end
843831
end
844832
end
833+
@static if VERSION >= v"1.13.0-DEV.1044"
834+
@with Test.TESTSET_PRINT_ENABLE => false begin
835+
collect_results()
836+
end
837+
else
838+
old_print_setting = Test.TESTSET_PRINT_ENABLE[]
839+
Test.TESTSET_PRINT_ENABLE[] = false
840+
try
841+
collect_results()
842+
finally
843+
Test.TESTSET_PRINT_ENABLE[] = old_print_setting
844+
end
845+
end
846+
847+
# display the results
845848
println(io_ctx.stdout)
846849
if VERSION >= v"1.13.0-DEV.1033"
847850
Test.print_test_results(io_ctx.stdout, o_ts, 1)

test/runtests.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,26 @@ end
113113
@test contains(str, "This test throws an error")
114114
end
115115

116+
@testset "crashing test" begin
117+
custom_tests = Dict(
118+
"crash" => quote
119+
abort() = ccall(:abort, Nothing, ())
120+
abort()
121+
end
122+
)
123+
124+
io = IOBuffer()
125+
@test_throws Test.FallbackTestSetException("Test run finished with errors") begin
126+
runtests(["--verbose"]; custom_tests, stdout=io, stderr=io)
127+
end
128+
129+
str = String(take!(io))
130+
@test contains(str, r"crash .+ started at")
131+
@test contains(str, "FAILURE")
132+
@test contains(str, "Error During Test")
133+
@test contains(str, "ProcessExitedException")
134+
end
135+
116136
@testset "test output" begin
117137
custom_tests = Dict(
118138
"output" => quote

0 commit comments

Comments
 (0)