Skip to content

Commit dbb0a40

Browse files
committed
more precise filtering, by making isfinal "dynamic"
I.e. even testsets which have children can now be `isfinal`, provided `resolve!` has decided none of them will run this time. The filtering is then more precise because only `isfinal` testsets are filtered at run time, after `resolve!` is done.
1 parent ca31d6b commit dbb0a40

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/ReTest.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ mutable struct TestsetExpr
9191
end
9292

9393
isfor(ts::TestsetExpr) = ts.loops !== nothing
94-
isfinal(ts::TestsetExpr) = isempty(ts.children)
94+
95+
# ts has no children, or at least none which will run this time
96+
isfinal(ts::TestsetExpr) = all(tsc -> !tsc.run, ts.children)
9597

9698
function tsdepth(ts::Union{TestsetExpr,Testset.ReTestSet})
9799
d = 1
@@ -467,7 +469,8 @@ eval_desc(mod, ts, x) =
467469
function make_ts(ts::TestsetExpr, pat::Pattern, stats, chan)
468470
ts.run || return nothing
469471

470-
if isfinal(ts)
472+
if isempty(ts.children) # not isfinal(ts), so that children which don't run
473+
# are removed from the AST
471474
body = ts.body
472475
else
473476
body = make_ts(ts.body, pat, stats, chan)

test/runtests.jl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,31 @@ Main.MiscSubmoduleHeader.Sub
868868
""")
869869
end
870870

871+
872+
module MiscIsFinal
873+
using ReTest, ..Trace
874+
875+
@testset "outer$i" for i=1:2
876+
# "outer$i" is apparently non-final, but with the proper filtering pattern,
877+
# it can become final: then, test that filtering actually happens
878+
# (once `resolve!` is done, no more filtering happens except for `isfinal` testsets;
879+
# so here we check that `isfinal` applies to "outer")
880+
trace(i)
881+
@testset "inner" begin
882+
trace(-1)
883+
end
884+
end
885+
886+
end # MiscIsFinal
887+
888+
@chapter MiscIsFinal begin
889+
check(MiscIsFinal, r"outer1$", [1])
890+
check(MiscIsFinal, r"outer1$", dry=true, id=false, [], output="outer1")
891+
check(MiscIsFinal, r"outer2$", [2])
892+
check(MiscIsFinal, r"outer2$", dry=true, id=false, [], output="outer2")
893+
end
894+
895+
871896
module Bugs
872897
using ReTest
873898
@testset "macros with nothing" begin

0 commit comments

Comments
 (0)