Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(283)

Unified Diff: pkg/unittest/lib/unittest.dart

Issue 14180015: Added support for solo groups, multiple solo tests, and (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/unittest/test/unittest_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.
+ * 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;
+
+/**
* 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,42 @@
*/
void test(String spec, TestFunction body) {
ensureInitialized();
- _testCases.add(new TestCase._internal(testCases.length + 1, _fullSpec(spec),
- body));
+ if (_solo_level != 0) {
+ 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
+ * 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;
+ test(spec, body);
kevmoo-old 2013/04/25 21:56:34 DBR: try...finally?
gram 2013/04/25 22:01:16 Done.
+ --_solo_level;
}
/** Sentinel value for [_SpreadArgsHelper]. */
@@ -595,6 +609,22 @@
}
}
+/** 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;
+ group(description, body);
kevmoo-old 2013/04/25 21:56:34 DBR: try...finally?
gram 2013/04/25 22:01:16 Done.
+ --_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 +698,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 +828,9 @@
void setSoloTest(int id) {
for (var i = 0; i < testCases.length; i++) {
if (testCases[i].id == id) {
- _soloTest = testCases[i];
+ var testCase = testCases[i];
+ _testCases.clear();
+ _testCases.add(testCase);
break;
}
}
« no previous file with comments | « no previous file | pkg/unittest/test/unittest_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698