Skip to content

Commit 88d1e1a

Browse files
committed
Add ability for ponytest to exclude tests based on name
Adds --exclude command line option that can be used to exclude any tests whose name starts with the given prefix. As part of this change, I think it makes sense to introduce a breaking change to rename the "filter" option. It's currently use to only run those tests that match the filter argument. Based on the existence of "exclude", I think it makes sense to change "filter" to "only". "Filter" is very generic. The "exclude" option is itself a filter. I think the options are: 1) I amend this commit to rename filter. 2) We merge this as is and do another commit to rename filter 3) We merge this as is and put the filter rename through an RFC
1 parent 011641c commit 88d1e1a

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

packages/ponytest/pony_test.pony

+21-3
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ Arbitrary strings can be used for these names, but for large projects it is
7575
strongly recommended to use a hierarchical naming scheme to make it easier to
7676
select groups of tests.
7777
78+
You can skip any tests whose names start with a given string by using the
79+
`--exclude=[prefix]` command line option.
80+
81+
You can run only tests whose names start with a given string by using the
82+
`--filter=[prefix]` command line option.
83+
7884
## Aggregation
7985
8086
Often it is desirable to run a collection of unit tests from multiple different
@@ -207,7 +213,6 @@ actor PonyTest
207213
let _env: Env
208214
let _timers: Timers = Timers
209215
var _do_nothing: Bool = false
210-
var _filter: String = ""
211216
var _verbose: Bool = false
212217
var _sequential: Bool = false
213218
var _no_prog: Bool = false
@@ -216,6 +221,10 @@ actor PonyTest
216221
var _finished: USize = 0
217222
var _any_found: Bool = false
218223
var _all_started: Bool = false
224+
225+
// Filtering options
226+
var _exclude: String = ""
227+
var _filter: String = ""
219228
var _label: String = ""
220229

221230
new create(env: Env, list: TestList tag) =>
@@ -231,14 +240,19 @@ actor PonyTest
231240

232241
be apply(test: UnitTest iso) =>
233242
"""
234-
Run the given test, subject to our filter and options.
243+
Run the given test, subject to our filters and options.
235244
"""
236245
if _do_nothing then
237246
return
238247
end
239248

240249
var name = test.name()
241250

251+
// Ignore any tests that satisfy our "exclude" filter
252+
if name.at(_exclude, 0) then
253+
return
254+
end
255+
242256
// Ignore any tests that don't satisfy our filter
243257
if not name.at(_filter, 0) then
244258
return
@@ -337,7 +351,7 @@ actor PonyTest
337351
end
338352

339353
if not _any_found then
340-
// No tests matched our filter, print special message.
354+
// No tests left after applying our filters
341355
_env.out.print("No tests found")
342356
return
343357
end
@@ -376,6 +390,8 @@ actor PonyTest
376390
_no_prog = true
377391
elseif arg == "--list" then
378392
_list_only = true
393+
elseif arg.compare_sub("--exclude=", 10) is Equal then
394+
_filter = arg.substring(9)
379395
elseif arg.compare_sub("--filter=", 9) is Equal then
380396
_filter = arg.substring(9)
381397
elseif arg.compare_sub("--label=", 8) is Equal then
@@ -387,6 +403,8 @@ actor PonyTest
387403
_env.out.print(" " + exe_name + " [options]")
388404
_env.out.print("")
389405
_env.out.print("Options:")
406+
_env.out.print(" --exclude=prefix - Don't run tests whose names " +
407+
"start with the given prefix.")
390408
_env.out.print(" --filter=prefix - Only run tests whose names " +
391409
"start with the given prefix.")
392410
_env.out.print(" --verbose - Show all test output.")

0 commit comments

Comments
 (0)