Skip to content

Commit 44cd3a1

Browse files
authored
support nesting Test.@testset within ReTest.@testset (#31)
1 parent e234de3 commit 44cd3a1

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

InlineTest/src/InlineTest.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ arguments of `@testset` can be:
6363
Invocations of `@testset` can be nested, but qualified invocations of
6464
`ReTest.@testset` can't.
6565
66+
A `@testset` can contain a nested `Test.@testset`, or call a function
67+
which defines a `Test.@testset`: in this case, the `Test.@testset`
68+
will be run whenever the parent testset is run, but `retest` won't
69+
know about it: it won't be taken into account
70+
during the filtering phase, and won't be printed in dry mode.
71+
6672
Internally, `@testset` expressions are converted to an equivalent of
6773
`Test.@testset` at execution time.
6874
"""

src/testset.jl

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ function ReTestSet(mod, desc::String, id::Integer=0;
8484
0, false, verbose, NamedTuple(), nothing)
8585
end
8686

87+
# constructor for nested Test.@testset, which is called with desc and kwargs
88+
ReTestSet(desc::String; verbose::Bool=false) =
89+
ReTestSet(Testset, # fake, but is .mod still used?
90+
desc; verbose=verbose) # doesn't seem necessary to set .parent via get_testset
91+
8792
# For a non-passed result, simply store the result
8893
record(ts::ReTestSet, t::Union{Broken,Fail,Error}) = (push!(ts.results, t); t)
8994
# For a passed result, do not store the result since it uses a lot of memory
@@ -233,7 +238,9 @@ end
233238

234239
# Called at the end of a @testset, behaviour depends on whether
235240
# this is a child of another testset, or the "root" testset
236-
function finish(ts::ReTestSet, chan)
241+
function finish(ts::ReTestSet, chan=nothing)
242+
# chan == nothing: only when ts was created from Test.@testset, and is nested
243+
237244
# If we are a nested test set, do not print a full summary
238245
# now - let the parent test set do the printing
239246
if get_testset_depth() != 0
@@ -342,9 +349,9 @@ function print_counts(ts::ReTestSet, fmt::Format, depth, align,
342349
# Print test set header, with an alignment that ensures all
343350
# the test results appear above each other
344351

345-
style = bold ? (bold=bold, color=:white) : NamedTuple()
346352
print_id(ts.id, maxidw)
347-
printstyled(rpad(string(" "^depth, ts.description), align, " "); style...)
353+
printstyled(rpad(string(" "^depth, ts.description), align, " ");
354+
bold=bold, color = ts.mod === Testset ? :cyan : :white)
348355

349356
np = passes + c_passes
350357
nf = fails + c_fails

test/runtests.jl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1515,6 +1515,31 @@ end # DryRun2
15151515
end
15161516

15171517

1518+
# * Test_Testset
1519+
1520+
module Test_Testset
1521+
using ReTest, ..Trace
1522+
import Test
1523+
1524+
@testset "a" begin
1525+
trace("a")
1526+
Test.@testset "b" begin
1527+
trace("b")
1528+
end
1529+
Test.@testset "c" begin
1530+
trace("c")
1531+
Test.@testset "d$i" for i=1:2
1532+
trace("d$i")
1533+
end
1534+
end
1535+
end
1536+
end
1537+
1538+
@chapter Test_Testset begin
1539+
check(Test_Testset, verbose=4, ["a", "b", "c", "d1", "d2"])
1540+
end
1541+
1542+
15181543
# * @testset_macro ...........................................................
15191544

15201545

0 commit comments

Comments
 (0)