Chromium Code Reviews| Index: pkg/unittest/lib/unittest.dart |
| =================================================================== |
| --- pkg/unittest/lib/unittest.dart (revision 22046) |
| +++ pkg/unittest/lib/unittest.dart (working copy) |
| @@ -214,6 +214,13 @@ |
| final List<TestCase> testCases = new UnmodifiableListView<TestCase>(_testCases); |
| /** |
| + * The set of tests to run can be restricted by using soloTest and soloGroup. |
|
Siggi Cherem (dart-lang)
2013/04/26 03:38:23
soloTest => [solo_test]
soloGroup => [solo_group]
gram
2013/04/26 17:35:44
Done.
|
| + * As groups can be nested we use a counter to keep track of the nest level |
| + * of soloing. We use -1 to indicate that there are no solo tests. |
| + */ |
| +int _solo_level = -1; |
|
Siggi Cherem (dart-lang)
2013/04/26 03:38:23
nit: _solo_level => _soloLevel;
gram
2013/04/26 17:35:44
Done.
|
| + |
| +/** |
| * Setup and teardown functions for a group and its parents, the latter |
| * for chaining. |
| */ |
| @@ -307,9 +314,6 @@ |
| const FAIL = 'fail'; |
| const ERROR = 'error'; |
| -/** If set, then all other test cases will be ignored. */ |
| -TestCase _soloTest; |
| - |
| /** |
| * A map that can be used to communicate state between a test driver |
| * or main() function and the tests, particularly when these two |
| @@ -326,32 +330,45 @@ |
| */ |
| void test(String spec, TestFunction body) { |
| ensureInitialized(); |
| - _testCases.add(new TestCase._internal(testCases.length + 1, _fullSpec(spec), |
| - body)); |
| + if (_solo_level != 0) { |
|
Siggi Cherem (dart-lang)
2013/04/26 03:38:23
I wonder if we can make this logic a bit more read
gram
2013/04/26 17:35:44
Done.
|
| + var testcase = new TestCase._internal(testCases.length + 1, _fullSpec(spec), |
| + body); |
| + _testCases.add(testcase); |
| + } |
| } |
| +/** Convenience function for skipping a test. */ |
| +void skip_test(String spec, TestFunction body){} |
| + |
| /** |
| * Creates a new test case with the given description and body. The |
| * description will include the descriptions of any surrounding group() |
| * calls. |
| * |
| - * "solo_" means that this will be the only test that is run. All other tests |
| - * will be skipped. This is a convenience function to let you quickly isolate |
| - * a single test by adding "solo_" before it to temporarily disable all other |
| - * tests. |
| + * If we use [solo_test] (or [solo_group]) instead of test, then all non-solo |
| + * tests will be disabled. Note that if we use [solo_group], all tests in |
| + * the group will be enabled, regardless of whether they use [test] or |
| + * [skip_test], or whether they are in a nested [group] vs [solo_group]. Put |
|
Siggi Cherem (dart-lang)
2013/04/26 03:38:23
skip_test => solo_test (skip test will always be s
gram
2013/04/26 17:35:44
Done.
|
| + * another way, if there are any calls to [solo_test] or [solo_group] in a test |
| + * file, all tests that are not inside a [solo_group] will be disabled unless |
| + * they are [solo_test]s. |
| + * |
| + * [skip_test] and [skip_group] take precedence over soloing, by virtue of the |
| + * fact that they are effectively no-ops. |
| */ |
| void solo_test(String spec, TestFunction body) { |
| - // TODO(rnystrom): Support multiple solos. If more than one test is solo-ed, |
| - // all of the solo-ed tests and none of the non-solo-ed ones should run. |
| - if (_soloTest != null) { |
| - throw new Exception('Only one test can be soloed right now.'); |
| + ensureInitialized(); |
| + if (_solo_level < 0) { |
| + _solo_level = 0; |
| + // This is the first solo-ed test. Discard all tests up to now. |
| + _testCases.clear(); |
| } |
| - |
| - ensureInitialized(); |
| - |
| - _soloTest = new TestCase._internal(testCases.length + 1, _fullSpec(spec), |
| - body); |
| - _testCases.add(_soloTest); |
| + ++_solo_level; |
| + try { |
| + test(spec, body); |
| + } finally { |
| + --_solo_level; |
| + } |
| } |
| /** Sentinel value for [_SpreadArgsHelper]. */ |
| @@ -595,6 +612,25 @@ |
| } |
| } |
| +/** Like [skip_test], but for groups. */ |
| +void skip_group(String description, void body()) {} |
| + |
| +/** Like [solo_test], but for groups. */ |
| +void solo_group(String description, void body()) { |
| + ensureInitialized(); |
| + if (_solo_level < 0) { |
| + _solo_level = 0; |
| + // This is the first solo-ed group. Discard all tests up to now. |
| + _testCases.clear(); |
| + } |
| + ++_solo_level; |
| + try { |
| + group(description, body); |
| + } finally { |
| + --_solo_level; |
| + } |
| +} |
| + |
| /** |
| * Register a [setUp] function for a test [group]. This function will |
| * be called before each test in the group is run. |
| @@ -668,11 +704,6 @@ |
| _ensureInitialized(false); |
| _currentTestCaseIndex = 0; |
| - // If we are soloing a test, remove all the others. |
| - if (_soloTest != null) { |
| - filterTests((t) => t == _soloTest); |
| - } |
| - |
| _config.onStart(); |
| runAsync(() { |
| @@ -803,7 +834,9 @@ |
| void setSoloTest(int id) { |
| for (var i = 0; i < testCases.length; i++) { |
|
Siggi Cherem (dart-lang)
2013/04/26 03:38:23
now that collections have improved, you can simply
gram
2013/04/26 17:35:44
Done.
|
| if (testCases[i].id == id) { |
| - _soloTest = testCases[i]; |
| + var testCase = testCases[i]; |
| + _testCases.clear(); |
| + _testCases.add(testCase); |
| break; |
| } |
| } |