Skip to content

Commit fdf2e5a

Browse files
committed
filtering: add pass and fail patterns
1 parent 6ba3ed5 commit fdf2e5a

File tree

4 files changed

+73
-9
lines changed

4 files changed

+73
-9
lines changed

src/ReTest.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module ReTest
22

3-
export retest, @testset, @testset_macro, not, interpolated, reachable, depth
3+
export retest, @testset, @testset_macro, not, interpolated, reachable, depth, pass, fail
44

55
using Distributed
66
using Base.Threads: nthreads

src/patterns.jl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ end
5656
struct Interpolated <: Pattern end
5757

5858

59+
### pass/fail
60+
61+
struct Pass <: Pattern end
62+
const pass = Pass()
63+
64+
struct Fail <: Pattern end
65+
const fail = Fail()
66+
67+
5968
## alwaysmatches
6069

6170
alwaysmatches(pat::And, d) = all(p -> alwaysmatches(p, d), pat.xs)
@@ -75,6 +84,8 @@ alwaysmatches(rx::Regex, _) = isempty(rx.pattern)
7584
alwaysmatches(id::Integer, _) = false
7685
alwaysmatches(pat::Reachable, d) = alwaysmatches(pat.x, d)
7786
alwaysmatches(dep::Depth, d) = dep.d == d
87+
alwaysmatches(::Pass, _) = false
88+
alwaysmatches(::Fail, _) = false
7889

7990

8091
## matches
@@ -116,6 +127,12 @@ end
116127

117128
matches(d::Depth, _, ts) = d.d == tsdepth(ts)
118129

130+
matches(::Pass, subj::AbstractString, ts) = get(ts.pastresults, subj, false)
131+
matches(::Fail, subj::AbstractString, ts) = !get(ts.pastresults, subj, true)
132+
# TODO: test method below
133+
matches(::Union{Pass,Fail}, ::Missing, ts) =
134+
isempty(ts.pastresults) ? false : missing
135+
119136

120137
## make_pattern
121138

@@ -156,6 +173,8 @@ hasinteger(pat::Not) = hasinteger(pat.x)
156173
hasinteger(::Interpolated) = false
157174
hasinteger(pat::Reachable) = hasinteger(pat.x)
158175
hasinteger(::Depth) = false
176+
hasinteger(::Pass) = false
177+
hasinteger(::Fail) = false
159178

160179

161180
## exported pattern functions & singletons
@@ -477,3 +496,14 @@ julia> Depth.runtests(dry=true, verbose=3, depth.(2:3))
477496
```
478497
"""
479498
depth(x::Integer) = Depth(Int(x))
499+
500+
"""
501+
pass
502+
fail
503+
504+
Filtering patterns which match any testset which already ran,
505+
succesfully for `pass` or with at least one error for `fail`.
506+
The pattern `[pass, fail]` therefore matches any testset
507+
which already ran.
508+
"""
509+
pass, fail

src/testset.jl

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ mutable struct ReTestSet <: AbstractTestSet
6565
subject::String
6666
id::Int64
6767
overall::Bool # TODO: could be conveyed by having self.mod == ""
68+
pastresults::Dict{String,Bool}
6869
results::Vector
6970
n_passed::Int
7071
anynonpass::Bool
@@ -74,11 +75,12 @@ mutable struct ReTestSet <: AbstractTestSet
7475
end
7576

7677
function ReTestSet(mod, desc::String, id::Integer=0;
77-
overall=false, verbose=true, parent=nothing)
78+
overall=false, verbose=true, parent=nothing,
79+
pastresults=Dict{String,Bool}())
7880
parentsubj = parent === nothing ? "" : parent.subject
7981
subject = string(parentsubj, '/', desc)
80-
ReTestSet(mod, parent, desc, subject, id, overall, [], 0, false,
81-
verbose, NamedTuple(), nothing)
82+
ReTestSet(mod, parent, desc, subject, id, overall, pastresults, [],
83+
0, false, verbose, NamedTuple(), nothing)
8284
end
8385

8486
# For a non-passed result, simply store the result
@@ -443,11 +445,11 @@ default_rng() = isdefined(Random, :default_rng) ?
443445
Random.default_rng() :
444446
Random.GLOBAL_RNG
445447

446-
function make_retestset(mod, desc, id, verbose, remove_last=false)
448+
function make_retestset(mod, desc, id, verbose, pastresults, remove_last=false)
447449
_testsets = get(task_local_storage(), :__BASETESTNEXT__, Test.AbstractTestSet[])
448450
@assert !(remove_last && isempty(_testsets))
449451
testsets = @view _testsets[1:end-remove_last]
450-
ReTestSet(mod, desc, id; verbose=verbose,
452+
ReTestSet(mod, desc, id; verbose=verbose, pastresults=pastresults,
451453
parent = isempty(testsets) ? nothing : testsets[end])
452454
end
453455

@@ -490,7 +492,8 @@ function testset_beginend(mod::Module, isfinal::Bool, pat::Pattern, id::Int64, d
490492
# action (such as reporting the results)
491493
desc = esc(desc)
492494
ex = quote
493-
local ts = make_retestset($mod, $desc, $id, $(options.transient_verbose))
495+
local ts = make_retestset($mod, $desc, $id, $(options.transient_verbose),
496+
$pastresults)
494497

495498
if !$isfinal || matches($pat, ts.subject, ts)
496499
local ret
@@ -547,7 +550,7 @@ function testset_forloop(mod::Module, isfinal::Bool, pat::Pattern, id::Int64,
547550
desc = esc(desc)
548551
blk = quote
549552
local ts0 = make_retestset($mod, $desc, $id, $(options.transient_verbose),
550-
!first_iteration)
553+
$pastresults, !first_iteration)
551554

552555
if !$isfinal || matches($pat, ts0.subject, ts0)
553556
# Trick to handle `break` and `continue` in the test code before

test/runtests.jl

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1039,9 +1039,40 @@ using ReTest
10391039
@testset "has fails" begin
10401040
@test false
10411041
end
1042+
@testset "also has passes" begin
1043+
@test true
1044+
end
1045+
@testset "unrun" begin
1046+
@test true
1047+
end
1048+
10421049
end # Failing
10431050

1044-
@chapter Failing @test_throws Test.TestSetException retest(Failing)
1051+
@chapter Failing begin
1052+
@test_throws Test.TestSetException retest(Failing)
1053+
retest(Failing, "passes")
1054+
1055+
check(Failing, dry=true, marks=true, -fail, [], output="""
1056+
2| also has passes ✔
1057+
3| unrun
1058+
""")
1059+
check(Failing, dry=true, marks=true, pass, [], output="""
1060+
2| also has passes ✔
1061+
""")
1062+
check(Failing, dry=true, marks=true, [pass, fail], [], output="""
1063+
1| has fails ✘
1064+
2| also has passes ✔
1065+
""")
1066+
check(Failing, dry=true, marks=true, -pass, -fail, [], output="""
1067+
3| unrun
1068+
""")
1069+
1070+
check(Failing, dry=true, marks=true, fail, [], output="1| has fails ✘")
1071+
check(Failing, dry=true, marks=true, -pass, [], output="""
1072+
1| has fails ✘
1073+
3| unrun
1074+
""")
1075+
end
10451076

10461077
# * Duplicate ................................................................
10471078

0 commit comments

Comments
 (0)