Skip to content

Commit 7b2e465

Browse files
authored
Update test runner for Julia 1.13. (#663)
1 parent 46d8ad0 commit 7b2e465

File tree

2 files changed

+88
-62
lines changed

2 files changed

+88
-62
lines changed

test/runtests.jl

Lines changed: 69 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -401,69 +401,82 @@ println("Testing finished in $elapsed")
401401

402402
# construct a testset to render the test results
403403
o_ts = Test.DefaultTestSet("Overall")
404-
Test.push_testset(o_ts)
405-
completed_tests = Set{String}()
406-
for (testname, (resp,)) in results
407-
push!(completed_tests, testname)
408-
if isa(resp, Test.DefaultTestSet)
409-
Test.push_testset(resp)
410-
Test.record(o_ts, resp)
411-
Test.pop_testset()
412-
elseif isa(resp, Tuple{Int,Int})
413-
fake = Test.DefaultTestSet(testname)
414-
for i in 1:resp[1]
415-
Test.record(fake, Test.Pass(:test, nothing, nothing, nothing, nothing))
416-
end
417-
for i in 1:resp[2]
418-
Test.record(fake, Test.Broken(:test, nothing))
419-
end
420-
Test.push_testset(fake)
421-
Test.record(o_ts, fake)
422-
Test.pop_testset()
423-
elseif isa(resp, RemoteException) && isa(resp.captured.ex, Test.TestSetException)
424-
println("Worker $(resp.pid) failed running test $(testname):")
425-
Base.showerror(stdout, resp.captured)
426-
println()
427-
fake = Test.DefaultTestSet(testname)
428-
for i in 1:resp.captured.ex.pass
429-
Test.record(fake, Test.Pass(:test, nothing, nothing, nothing, nothing))
430-
end
431-
for i in 1:resp.captured.ex.broken
432-
Test.record(fake, Test.Broken(:test, nothing))
433-
end
434-
for t in resp.captured.ex.errors_and_fails
435-
Test.record(fake, t)
436-
end
437-
Test.push_testset(fake)
438-
Test.record(o_ts, fake)
439-
Test.pop_testset()
404+
function with_testset(f, testset)
405+
@static if VERSION >= v"1.13.0-DEV.1044"
406+
Test.@with_testset testset f()
440407
else
441-
if !isa(resp, Exception)
442-
resp = ErrorException(string("Unknown result type : ", typeof(resp)))
408+
Test.push_testset(testset)
409+
try
410+
f()
411+
finally
412+
Test.pop_testset()
443413
end
444-
# If this test raised an exception that is not a remote testset exception,
445-
# i.e. not a RemoteException capturing a TestSetException that means
446-
# the test runner itself had some problem, so we may have hit a segfault,
447-
# deserialization errors or something similar. Record this testset as Errored.
448-
fake = Test.DefaultTestSet(testname)
449-
Test.record(fake, Test.Error(:nontest_error, testname, nothing, Any[(resp, [])], LineNumberNode(1)))
450-
Test.push_testset(fake)
451-
Test.record(o_ts, fake)
452-
Test.pop_testset()
453414
end
454415
end
455-
for test in all_tests
456-
(test in completed_tests) && continue
457-
fake = Test.DefaultTestSet(test)
458-
Test.record(fake, Test.Error(:test_interrupted, test, nothing,
459-
[("skipped", [])], LineNumberNode(1)))
460-
Test.push_testset(fake)
461-
Test.record(o_ts, fake)
462-
Test.pop_testset()
416+
with_testset(o_ts) do
417+
completed_tests = Set{String}()
418+
for (testname, (resp,)) in results
419+
push!(completed_tests, testname)
420+
if isa(resp, Test.DefaultTestSet)
421+
with_testset(resp) do
422+
Test.record(o_ts, resp)
423+
end
424+
elseif isa(resp, Tuple{Int,Int})
425+
fake = Test.DefaultTestSet(testname)
426+
for i in 1:resp[1]
427+
Test.record(fake, Test.Pass(:test, nothing, nothing, nothing, nothing))
428+
end
429+
for i in 1:resp[2]
430+
Test.record(fake, Test.Broken(:test, nothing))
431+
end
432+
with_testset(fake) do
433+
Test.record(o_ts, fake)
434+
end
435+
elseif isa(resp, RemoteException) && isa(resp.captured.ex, Test.TestSetException)
436+
println("Worker $(resp.pid) failed running test $(testname):")
437+
Base.showerror(stdout, resp.captured)
438+
println()
439+
fake = Test.DefaultTestSet(testname)
440+
for i in 1:resp.captured.ex.pass
441+
Test.record(fake, Test.Pass(:test, nothing, nothing, nothing, nothing))
442+
end
443+
for i in 1:resp.captured.ex.broken
444+
Test.record(fake, Test.Broken(:test, nothing))
445+
end
446+
for t in resp.captured.ex.errors_and_fails
447+
Test.record(fake, t)
448+
end
449+
with_testset(fake) do
450+
Test.record(o_ts, fake)
451+
end
452+
else
453+
if !isa(resp, Exception)
454+
resp = ErrorException(string("Unknown result type : ", typeof(resp)))
455+
end
456+
# If this test raised an exception that is not a remote testset exception,
457+
# i.e. not a RemoteException capturing a TestSetException that means
458+
# the test runner itself had some problem, so we may have hit a segfault,
459+
# deserialization errors or something similar. Record this testset as Errored.
460+
fake = Test.DefaultTestSet(testname)
461+
Test.record(fake, Test.Error(:nontest_error, testname, nothing, Base.ExceptionStack([(exception=resp,backtrace=[])]), LineNumberNode(1)))
462+
with_testset(fake) do
463+
Test.record(o_ts, fake)
464+
end
465+
end
466+
end
467+
for test in all_tests
468+
(test in completed_tests) && continue
469+
fake = Test.DefaultTestSet(test)
470+
Test.record(fake, Test.Error(:test_interrupted, test, nothing, Base.ExceptionStack([(exception="skipped",backtrace=[])]), LineNumberNode(1)))
471+
with_testset(fake) do
472+
Test.record(o_ts, fake)
473+
end
474+
end
463475
end
464476
println()
465477
Test.print_test_results(o_ts, 1)
466-
if !o_ts.anynonpass
478+
if (VERSION >= v"1.13.0-DEV.1037" && !Test.anynonpass(o_ts)) ||
479+
(VERSION < v"1.13.0-DEV.1037" && !o_ts.anynonpass)
467480
println(" \033[32;1mSUCCESS\033[0m")
468481
else
469482
println(" \033[31;1mFAILURE\033[0m\n")

test/setup.jl

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ const shader_validation = get(ENV, "MTL_SHADER_VALIDATION", "0") != "0"
1919

2020
using Random
2121

22+
if VERSION >= v"1.13.0-DEV.1044"
23+
using Base.ScopedValues
24+
end
25+
2226

2327
## entry point
2428

2529
function runtests(f, name)
26-
old_print_setting = Test.TESTSET_PRINT_ENABLE[]
27-
Test.TESTSET_PRINT_ENABLE[] = false
28-
29-
try
30+
function inner()
3031
# generate a temporary module to execute the tests in
3132
mod_name = Symbol("Test", rand(1:100), "Main_", replace(name, '/' => '_'))
3233
mod = @eval(Main, module $mod_name end)
@@ -70,8 +71,20 @@ function runtests(f, name)
7071

7172
GC.gc(true)
7273
res
73-
finally
74-
Test.TESTSET_PRINT_ENABLE[] = old_print_setting
74+
end
75+
76+
@static if VERSION >= v"1.13.0-DEV.1044"
77+
@with Test.TESTSET_PRINT_ENABLE=>false begin
78+
inner()
79+
end
80+
else
81+
old_print_setting = Test.TESTSET_PRINT_ENABLE[]
82+
Test.TESTSET_PRINT_ENABLE[] = false
83+
try
84+
inner()
85+
finally
86+
Test.TESTSET_PRINT_ENABLE[] = old_print_setting
87+
end
7588
end
7689
end
7790

0 commit comments

Comments
 (0)