Chromium Code Reviews| Index: lib/unittest/unittest.dart |
| =================================================================== |
| --- lib/unittest/unittest.dart (revision 8995) |
| +++ lib/unittest/unittest.dart (working copy) |
| @@ -213,6 +213,9 @@ |
| /** If set, then all other test cases will be ignored. */ |
| TestCase _soloTest; |
| +/** If set, then only tests whose names match this pattern will be run. */ |
|
eub
2012/06/21 20:58:45
s/pattern/regexp/ to be clear.
eub
2012/06/21 20:58:45
Also, s/name/description/ globally unless that's a
gram
2012/06/21 21:18:03
Done.
|
| +String _filter = null; |
| + |
| /** |
| * (Deprecated) Evaluates the [function] and validates that it throws an |
| * exception. If [callback] is provided, then it will be invoked with the |
| @@ -241,6 +244,16 @@ |
| if (threw != true) _fail('An expected exception was not thrown.'); |
| } |
| +/** Sets the filter which constrains which tests to run based on their names. */ |
| +void setFilter(String filter) { |
| + if (filter == '') filter = null; |
| + _filter = filter; |
| +} |
| + |
| +/** Gets the filter which constrains which tests to run based on their names. */ |
| +String getFilter() { |
| + return _filter; |
| +} |
| /** |
| * Creates a new test case with the given description and body. The |
| * description will include the descriptions of any surrounding group() |
| @@ -641,6 +654,23 @@ |
| if (_soloTest != null) { |
| _tests = _tests.filter((t) => t == _soloTest); |
| } |
| + if (_filter == null) { // check arguments for a --filter spec. |
| + var options = new Options().arguments; |
| + if (options != null) { |
| + for (var i = 0; i < options.length; i++) { |
| + if (options[i].startsWith('--filter=')) { |
|
eub
2012/06/21 20:58:45
Another one for the Great Flag Parsing Unification
|
| + var filter = options[i].substring(10); |
|
eub
2012/06/21 20:58:45
This chops off the first character, or did I misco
gram
2012/06/21 21:18:03
Correct, I was assuming this is quoted. But you're
|
| + filter = filter.substring(0, filter.length-1); |
|
eub
2012/06/21 20:58:45
And this chops off the last character, so we're co
|
| + setFilter(filter); |
| + break; |
| + } |
| + } |
| + } |
| + } |
| + if (_filter != null) { |
| + RegExp re = new RegExp(_filter); |
| + _tests = _tests.filter((t) => re.hasMatch(t.description)); |
| + } |
| _config.onStart(); |