Skip to content

Commit 710db5f

Browse files
committed
at-testsetr: add a trailing '/' for non-final testsets
When the pattern starts with '/', then, the final '/' is partially matched, so this can increase the number of matches in some cases On the other hand, a pattern like r"^/a/b1" won't partially match a testset-chain like "^/a/b/...", which is desirable.
1 parent 36bcdf8 commit 710db5f

File tree

2 files changed

+55
-6
lines changed

2 files changed

+55
-6
lines changed

src/testset.jl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,10 @@ function testset_beginend(args, tests, source)
5656
# finally removing the testset and giving it a chance to take
5757
# action (such as reporting the results)
5858
ex = quote
59-
local current_str = get_testset_string() * '/' * $desc
60-
local rx = $(esc(REGEX[]))[1 + $(esc(FINAL[]))]
59+
local final = $(esc(FINAL[]))
60+
local current_str = string(get_testset_string(), '/', $desc,
61+
final ? "" : "/")
62+
local rx = $(esc(REGEX[]))[1 + final]
6163
if partialoccursin(rx, current_str)
6264
_check_testset($testsettype, $(QuoteNode(testsettype.args[1])))
6365
local ret
@@ -133,8 +135,11 @@ function testset_forloop(args, testloop, source)
133135
# wrapped in the outer loop provided by the user
134136
tests = testloop.args[2]
135137
blk = quote
136-
local current_str = get_testset_string(!first_iteration) * '/' * $desc
137-
local rx = $(esc(REGEX[]))[1 + $(esc(FINAL[]))]
138+
local final = $(esc(FINAL[]))
139+
local current_str = string(get_testset_string(!first_iteration), '/', $desc,
140+
final ? "" : "/")
141+
142+
local rx = $(esc(REGEX[]))[1 + final]
138143
if partialoccursin(rx, current_str)
139144
_check_testset($testsettype, $(QuoteNode(testsettype.args[1])))
140145
# Trick to handle `break` and `continue` in the test code before

test/runtests.jl

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ using .M: check
5858
check("a", ["a"])
5959
check("a1", []) # testset is "final", so we do a full match
6060
check("b", ["b1", "b2"])
61-
check("/b", ["b1", "b2"])
61+
check("/b", ["b1", "b2", "c", "f1"])
6262
check("b1", ["b1"])
6363
check("c1", []) # "c1" is *not* partially matched against "/c/"
6464
check("c/1", ["c"]) # "c" is partially matched, but nothing fully matches afterwards
6565
check("c/d1", ["c"])
6666
check("c/d", ["c", "d"])
67-
check("/c", ["c", "d", "e1", "e2"])
67+
check("/c", ["c", "d", "e1", "e2", "f1"])
6868
check(".*d", ["c", "d", "f1"])
6969
check(".*(e1|e2)", ["c", "e1", "e2", "f1"])
7070
check("f1", ["f1", "g", "h1", "h2"])
@@ -76,3 +76,47 @@ check(".*h\$", ["c", "f1"])
7676

7777
runtests(M, wrap=true) # TODO: more precise tests
7878
runtests(M, wrap=false)
79+
80+
module N
81+
using InlineTest
82+
83+
RUN = []
84+
85+
# testing non-final non-toplevel testsets
86+
@testset "i" begin
87+
push!(RUN, "i")
88+
@test true
89+
90+
@testset "j" begin
91+
push!(RUN, "j")
92+
@test true
93+
94+
@testset "k" begin
95+
push!(RUN, "k")
96+
@test true
97+
end
98+
end
99+
100+
@testset "l$i" for i=1:1
101+
push!(RUN, "l$i")
102+
@test true
103+
104+
@testset "m" begin
105+
push!(RUN, "m")
106+
@test true
107+
end
108+
end
109+
end
110+
111+
function check(rx, list)
112+
empty!(RUN)
113+
runtests(N, Regex(rx))
114+
@test sort(RUN) == sort(list)
115+
end
116+
end
117+
118+
import .N
119+
N.check(".*j1", ["i", "j", "l1"])
120+
N.check(".*j/1", ["i", "j", "l1"])
121+
N.check("^/i/j0", ["i"])
122+
N.check("^/i/l10", ["i"])

0 commit comments

Comments
 (0)