Skip to content

Commit b9e1bbf

Browse files
committed
retest: allow to pass tag=not(:sym) to remove :sym label
1 parent adc9f9d commit b9e1bbf

File tree

3 files changed

+43
-12
lines changed

3 files changed

+43
-12
lines changed

src/ReTest.jl

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,8 @@ Filtering `pattern`s can be specified to run only a subset of the tests.
666666
* The `tag` keyword allows to tag a testset with labels, encoded as symbols.
667667
When `tag` is a list of symbols, tag all matching testsets with these.
668668
When `tag` is a symbol, tag all matching testsets with it.
669+
Instead of a symbol `:sym`, it's possible to instead pass `not(:sym)` in
670+
order to remove the `:sym` label from matching testsets.
669671
Currently, `tag` has an effect only if `dry` is `true`.
670672
* When `spin` is `true`, the description of the testset being currently executed
671673
is shown (if there is only one), as well as a "spinner". This is disabled when
@@ -813,15 +815,16 @@ function retest(@nospecialize(args::ArgType...);
813815

814816
maxidw[] = id ? maxidw[] : 0
815817

816-
if tag isa Symbol
818+
if tag isa Symbol || tag isa Not && tag.x isa Symbol
817819
tag = [tag]
818-
elseif !(tag isa Vector{Symbol})
819-
tag = vec(collect(Symbol, tag))
820+
elseif !(tag isa Vector{<:Union{Symbol,Not}})
821+
tag = vec(collect(Union{Symbol,Not}, tag))
820822
end
821823
if !dry && !isempty(tag)
822824
@warn "tag keyword: labels can be added only in dry mode"
823825
end
824-
for label in tag
826+
for t in tag
827+
label::Symbol = t isa Symbol ? t : t.x
825828
startswith(String(label), '_') &&
826829
throw(ArgumentError("tag keyword: labels can't start with an underscore"))
827830
end
@@ -1524,7 +1527,7 @@ hasmany(tests) = length(tests) > 1 || isfor(tests[1])
15241527
function dryrun(mod::Module, ts::TestsetExpr, pat::Pattern, align::Int=0,
15251528
parentsubj::Union{Missing, String}=""
15261529
# external calls:
1527-
; maxidw::Int, marks::Bool, tag::Vector{Symbol}, clear::Bool,
1530+
; maxidw::Int, marks::Bool, tag::Vector, clear::Bool,
15281531
# only recursive calls:
15291532
evaldesc=true, repeated=nothing, show::Bool=true)
15301533
@assert ts.run
@@ -1556,7 +1559,13 @@ function dryrun(mod::Module, ts::TestsetExpr, pat::Pattern, align::Int=0,
15561559
end
15571560
if subject !== missing
15581561
for mark=tag
1559-
ismatch && addmark!(ts.marks, subject, mark)
1562+
if ismatch
1563+
if mark isa Symbol
1564+
addmark!(ts.marks, subject, mark)
1565+
else
1566+
delmark!(ts.marks, subject, mark.x)
1567+
end
1568+
end
15601569
end
15611570
end
15621571

test/runtests.jl

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,7 @@ x ⋯
11301130
retest(Marks, r"a$", dry=true, tag=[:a3 :a4])
11311131
retest(Marks, r"a$", dry=true, tag=(:a5, :a6))
11321132
@test_throws ArgumentError retest(Marks, r"a$", dry=true, tag=:_underscored)
1133+
@test_throws ArgumentError retest(Marks, r"a$", dry=true, tag=[not(:_underscored)])
11331134

11341135
check(Marks, "-l", -4, dry=true, verbose=9, id=false, marks=true, [], output="""
11351136
a a1 a2 a3 a4 a5 a6 ✔
@@ -1166,8 +1167,8 @@ x
11661167
z3
11671168
z4
11681169
""")
1169-
check(Marks, "-l", -4, reachable("x"), not(:ylabel), dry=true, verbose=9, id=false,
1170-
marks=true, [], output="""
1170+
check(Marks, "-l", -4, reachable("x"), not(:ylabel), dry=true, verbose=9, id=false,
1171+
marks=true, [], output="""
11711172
x
11721173
y1 ylabel
11731174
y2
@@ -1177,6 +1178,27 @@ x
11771178
z4
11781179
""")
11791180
end
1181+
check(Marks, -4, [r"y1$", "z3"], dry=true, marks=true, id=false, tag=not(:ylabel),
1182+
verbose=9, [], output="""
1183+
x
1184+
y1
1185+
z3
1186+
y2
1187+
z3
1188+
""")
1189+
check(Marks, 8:12, dry=true, verbose=9, id=false, marks=true, [], output="""
1190+
x
1191+
y1
1192+
z1 ylabel
1193+
z2 ylabel
1194+
z3
1195+
z4 ylabel
1196+
y2
1197+
z1
1198+
z2
1199+
z3
1200+
z4
1201+
""")
11801202
end
11811203

11821204

test/setup.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function check(x...; runtests=false, output::Union{Nothing,String}=nothing,
2020
verbose=ReTest.def(:verbose), stats=ReTest.def(:stats), dry=ReTest.def(:dry),
2121
strict::Bool=ReTest.def(:strict), recursive=ReTest.def(:recursive),
2222
static=ReTest.def(:static), id=ReTest.def(:id), load=ReTest.def(:load),
23-
marks::Bool=false, clear::Bool=ReTest.def(:clear))
23+
marks::Bool=false, tag=ReTest.def(:tag), clear::Bool=ReTest.def(:clear))
2424
@assert !(runtests & (output !== nothing)) "unimplemented"
2525
args = x[1:end-1]
2626
expected = x[end]
@@ -32,17 +32,17 @@ function check(x...; runtests=false, output::Union{Nothing,String}=nothing,
3232
if runtests
3333
getfield(args[1], :runtests)(args[2:end]...; verbose=verbose, stats=stats, dry=dry,
3434
strict=strict, recursive=recursive, static=static,
35-
id=id, load=load, marks=marks, clear=clear)
35+
id=id, load=load, marks=marks, tag=tag, clear=clear)
3636
elseif output === nothing
3737
retest(args...; verbose=verbose, stats=stats, dry=dry, strict=strict,
3838
recursive=recursive, static=static, id=id, load=load, marks=marks,
39-
clear=clear)
39+
tag=tag, clear=clear)
4040
else
4141
mktemp() do path, io
4242
redirect_stdout(io) do
4343
retest(args...; verbose=verbose, stats=stats, dry=dry, strict=strict,
4444
recursive=recursive, static=static, id=id, load=load, marks=marks,
45-
clear=clear)
45+
tag=tag, clear=clear)
4646
end
4747
seekstart(io)
4848
printed = join(map(rstrip, split(readchomp(io), '\n')), '\n')

0 commit comments

Comments
 (0)