Skip to content

Commit

Permalink
Allow Ponytest to exclude or include tests by name
Browse files Browse the repository at this point in the history
Adds --exclude command line option that can be used to
exclude any tests whose name starts with the given prefix.

Renames existing --filter command line option to --only to provide
better symmetry with --exclude.
  • Loading branch information
SeanTAllen committed Mar 29, 2017
1 parent 171ea72 commit 5850e0e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ All notable changes to the Pony compiler and standard library will be documented
### Changed

- Arrays as sequences (PR #1741)
- Add ability for ponytest to exclude tests based on name (PR #1717)

### Changed

- Renamed ponytest "filter" flag to "only" (PR #1717)


## [0.11.4] - 2017-03-23
Expand Down
34 changes: 26 additions & 8 deletions packages/ponytest/pony_test.pony
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ Arbitrary strings can be used for these names, but for large projects it is
strongly recommended to use a hierarchical naming scheme to make it easier to
select groups of tests.
You can skip any tests whose names start with a given string by using the
`--exclude=[prefix]` command line option.
You can run only tests whose names start with a given string by using the
`--only=[prefix]` command line option.
## Aggregation
Often it is desirable to run a collection of unit tests from multiple different
Expand Down Expand Up @@ -207,7 +213,6 @@ actor PonyTest
let _env: Env
let _timers: Timers = Timers
var _do_nothing: Bool = false
var _filter: String = ""
var _verbose: Bool = false
var _sequential: Bool = false
var _no_prog: Bool = false
Expand All @@ -216,7 +221,11 @@ actor PonyTest
var _finished: USize = 0
var _any_found: Bool = false
var _all_started: Bool = false

// Filtering options
var _exclude: String = ""
var _label: String = ""
var _only: String = ""

new create(env: Env, list: TestList tag) =>
"""
Expand All @@ -231,16 +240,21 @@ actor PonyTest

be apply(test: UnitTest iso) =>
"""
Run the given test, subject to our filter and options.
Run the given test, subject to our filters and options.
"""
if _do_nothing then
return
end

var name = test.name()

// Ignore any tests that don't satisfy our filter
if not name.at(_filter, 0) then
// Ignore any tests that satisfy our "exclude" filter
if name.at(_exclude, 0) then
return
end

// Ignore any tests that don't satisfy our "only" filter
if not name.at(_only, 0) then
return
end

Expand Down Expand Up @@ -337,7 +351,7 @@ actor PonyTest
end

if not _any_found then
// No tests matched our filter, print special message.
// No tests left after applying our filters
_env.out.print("No tests found")
return
end
Expand Down Expand Up @@ -376,18 +390,22 @@ actor PonyTest
_no_prog = true
elseif arg == "--list" then
_list_only = true
elseif arg.compare_sub("--filter=", 9) is Equal then
_filter = arg.substring(9)
elseif arg.compare_sub("--exclude=", 10) is Equal then
_exclude = arg.substring(10)
elseif arg.compare_sub("--label=", 8) is Equal then
_label = arg.substring(8)
elseif arg.compare_sub("--only=", 9) is Equal then
_filter = arg.substring(8)
else
_env.out.print("Unrecognised argument \"" + arg + "\"")
_env.out.print("")
_env.out.print("Usage:")
_env.out.print(" " + exe_name + " [options]")
_env.out.print("")
_env.out.print("Options:")
_env.out.print(" --filter=prefix - Only run tests whose names " +
_env.out.print(" --exclude=prefix - Don't run tests whose names " +
"start with the given prefix.")
_env.out.print(" --only=prefix - Only run tests whose names " +
"start with the given prefix.")
_env.out.print(" --verbose - Show all test output.")
_env.out.print(" --sequential - Run tests sequentially.")
Expand Down

0 comments on commit 5850e0e

Please sign in to comment.