@@ -109,18 +109,47 @@ macro testset(args...)
109
109
end
110
110
111
111
"""
112
- runtests([m::Module]; [wrap::Bool])
112
+ runtests([m::Module], pattern = r"" ; [wrap::Bool])
113
113
114
114
Run all the tests declared in `@testset` blocks, within `m` if specified,
115
115
or within all currently loaded modules otherwise.
116
- The `wrap` keyword specifies whether the collection of `@testset` blocks derived
117
- from `@testset` declarations should be grouped within a top-level `@testset`.
116
+ The `wrap` keyword specifies whether the collection of `@testset` expressions
117
+ should be grouped according to the parent modules within a top-level `@testset`.
118
118
The default is `wrap=false` when `m` is specified, `true` otherwise.
119
119
120
- Note: this function executes each (top-level) `@testset` block using `eval` *within* the module
121
- in which it was written (e.g. `m`, when specified).
120
+ It's possible to filter run testsets by specifying `pattern`: the "subject" of a
121
+ testset is the concatenation of the subject of its parent `@testset`, if any,
122
+ with `"/\$ description"` where `description` is the testset's description.
123
+ For example:
124
+ ```julia
125
+ @testset "a" begin # subject == "/a"
126
+ @testset "b" begin # subject is "/a/b"
127
+ end
128
+ @testset "c\$ i" for i=1:2 # subjects are "/a/c1" & "/a/c2"
129
+ end
130
+ end
131
+ ```
132
+ A testset is guaranteed to run only when its parent's subject "partially matches"
133
+ `pattern::Regex` (in PCRE2 parlance, i.e. `subject` might be the prefix of a string
134
+ matched by `pattern`) and its subject matches `pattern`.
135
+
136
+ If the passed `pattern` is a string, then it is wrapped in a `Regex` prefixed with
137
+ `".*"`, and must match literally the subjects.
138
+ This means for example that `"a|b"` will match a subject like `"a|b"` but not like `"a"`.
139
+ The `".*"` prefix is intended to allow matching subjects of nested testsets,
140
+ e.g. in the example above, `r".*b"` partially matches the subject `"/a"` and
141
+ matches the subject `"/a/b"` (so the corresponding nested testset is run),
142
+ whereas `r"b"` does not partially match `"/a"`, even if it matches `"/a/b"`,
143
+ so the testset is not run.
144
+
145
+ Note: this function executes each (top-level) `@testset` block using `eval` *within* the
146
+ module in which it was written (e.g. `m`, when specified).
122
147
"""
123
- function runtests (m:: Module , regex:: Regex = r" " ; wrap:: Bool = false )
148
+ function runtests (m:: Module , pattern:: Union{AbstractString,Regex} = r" " ; wrap:: Bool = false )
149
+ regex = pattern isa Regex ?
150
+ pattern :
151
+ r" .*" * pattern
152
+
124
153
partial = partialize (regex)
125
154
matches (desc, final) = Testset. partialoccursin ((partial, regex)[1 + final],
126
155
string (' /' , desc, final ? " " : " /" ))
0 commit comments