Skip to content

support nesting Test.@testset within ReTest.@testset #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 6, 2021
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
6 changes: 6 additions & 0 deletions InlineTest/src/InlineTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ arguments of `@testset` can be:
Invocations of `@testset` can be nested, but qualified invocations of
`ReTest.@testset` can't.

A `@testset` can contain a nested `Test.@testset`, or call a function
which defines a `Test.@testset`: in this case, the `Test.@testset`
will be run whenever the parent testset is run, but `retest` won't
know about it: it won't be taken into account
during the filtering phase, and won't be printed in dry mode.

Internally, `@testset` expressions are converted to an equivalent of
`Test.@testset` at execution time.
"""
Expand Down
13 changes: 10 additions & 3 deletions src/testset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ function ReTestSet(mod, desc::String, id::Integer=0;
0, false, verbose, NamedTuple(), nothing)
end

# constructor for nested Test.@testset, which is called with desc and kwargs
ReTestSet(desc::String; verbose::Bool=false) =
ReTestSet(Testset, # fake, but is .mod still used?
desc; verbose=verbose) # doesn't seem necessary to set .parent via get_testset

# For a non-passed result, simply store the result
record(ts::ReTestSet, t::Union{Broken,Fail,Error}) = (push!(ts.results, t); t)
# For a passed result, do not store the result since it uses a lot of memory
Expand Down Expand Up @@ -233,7 +238,9 @@ end

# Called at the end of a @testset, behaviour depends on whether
# this is a child of another testset, or the "root" testset
function finish(ts::ReTestSet, chan)
function finish(ts::ReTestSet, chan=nothing)
# chan == nothing: only when ts was created from Test.@testset, and is nested

# If we are a nested test set, do not print a full summary
# now - let the parent test set do the printing
if get_testset_depth() != 0
Expand Down Expand Up @@ -342,9 +349,9 @@ function print_counts(ts::ReTestSet, fmt::Format, depth, align,
# Print test set header, with an alignment that ensures all
# the test results appear above each other

style = bold ? (bold=bold, color=:white) : NamedTuple()
print_id(ts.id, maxidw)
printstyled(rpad(string(" "^depth, ts.description), align, " "); style...)
printstyled(rpad(string(" "^depth, ts.description), align, " ");
bold=bold, color = ts.mod === Testset ? :cyan : :white)

np = passes + c_passes
nf = fails + c_fails
Expand Down
25 changes: 25 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1515,6 +1515,31 @@ end # DryRun2
end


# * Test_Testset

module Test_Testset
using ReTest, ..Trace
import Test

@testset "a" begin
trace("a")
Test.@testset "b" begin
trace("b")
end
Test.@testset "c" begin
trace("c")
Test.@testset "d$i" for i=1:2
trace("d$i")
end
end
end
end

@chapter Test_Testset begin
check(Test_Testset, verbose=4, ["a", "b", "c", "d1", "d2"])
end


# * @testset_macro ...........................................................


Expand Down