Skip to content

Commit 2e821a8

Browse files
committed
@remote_testset macro
1 parent 1d32fd7 commit 2e821a8

2 files changed

Lines changed: 40 additions & 7 deletions

File tree

src/ParallelTestRunner.jl

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,8 @@ function runtest(::Type{TestRecord}, f, name, init_code, color)
220220
function inner()
221221
# generate a temporary module to execute the tests in
222222
mod = @eval(Main, module $(gensym(name)) end)
223-
@eval(mod, import ParallelTestRunner: Test, Random, RemoteTestSet)
224-
@eval(mod, using .Test, .Random)
225-
@eval(mod, using .Test: DefaultTestSet) # Necessary because VERSION <= v"1.10.0-" does not support unexported TestSets the @testset
223+
@eval(mod, import ParallelTestRunner: Test, Random, RemoteTestSets)
224+
@eval(mod, using .Test, .Random, .RemoteTestSets)
226225

227226
Core.eval(mod, init_code)
228227

@@ -233,10 +232,8 @@ function runtest(::Type{TestRecord}, f, name, init_code, color)
233232
mktemp() do path, io
234233
stats = redirect_stdio(stdout=io, stderr=io) do
235234
@timed try
236-
@testset RemoteTestSet "wrapper" begin
237-
@testset DefaultTestSet $name begin
238-
$f
239-
end
235+
@remote_testset $name begin
236+
$f
240237
end
241238
catch err
242239
isa(err, Test.TestSetException) || rethrow()

src/remotetestset.jl

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,40 @@ end
6060
Test.anynonpass(ts::RemoteTestSet) = Test.anynonpass(ts.ts)
6161
end
6262

63+
macro remote_testset(args...)
64+
testsettype = nothing
65+
otherargs = []
66+
67+
for arg in args[1:end-1]
68+
if isa(arg, Symbol) || Base.isexpr(arg, :.)
69+
testsettype = arg
70+
else
71+
push!(otherargs, arg)
72+
end
73+
end
74+
75+
source = args[end]
76+
if isnothing(testsettype)
77+
testsettype = :(Test.DefaultTestSet)
78+
end
79+
80+
# Build the inner @testset call
81+
inner_testset = Expr(:macrocall,
82+
:(Test.var"@testset"),
83+
LineNumberNode(@__LINE__, @__FILE__),
84+
testsettype,
85+
otherargs...,
86+
source)
87+
88+
# Build the outer @testset call with RemoteTestSet
89+
outer_testset = Expr(:macrocall,
90+
:(Test.var"@testset"),
91+
LineNumberNode(@__LINE__, @__FILE__),
92+
:RemoteTestSet,
93+
"wrapper",
94+
Expr(:block, inner_testset))
95+
96+
return esc(outer_testset)
97+
end
98+
6399
end

0 commit comments

Comments
 (0)