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

Unified Diff: pkg/unittest/unittest.dart

Issue 10897016: Testrunner for 3rd parties. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 4 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 | « pkg/unittest/test_case.dart ('k') | utils/testrunner/configuration.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/unittest/unittest.dart
===================================================================
--- pkg/unittest/unittest.dart (revision 11393)
+++ pkg/unittest/unittest.dart (working copy)
@@ -156,9 +156,12 @@
/** [Configuration] used by the unittest library. */
Configuration _config = null;
+Configuration get config => _config;
+
/**
* Set the [Configuration] used by the unittest library. Returns any
* previous configuration.
+ * TODO: consider deprecating in favor of a setter now we have a getter.
*/
Configuration configure(Configuration config) {
Configuration _oldConfig = _config;
@@ -174,11 +177,14 @@
*/
String _currentGroup = '';
+/** Separator used between group names and test names. */
+String groupSep = ' ';
+
/** Tests executed in this suite. */
List<TestCase> _tests;
/** Get the list of tests. */
-get testCases() => _tests;
+get testCases => _tests;
/**
* Callback used to run tests. Entrypoints can replace this with their own
@@ -236,20 +242,12 @@
}
/**
- * The regexp pattern filter which constrains which tests to run
- * based on their descriptions.
- */
-
-String filter = null;
-
-/**
* Creates a new test case with the given description and body. The
* description will include the descriptions of any surrounding group()
* calls.
*/
void test(String spec, TestFunction body) {
ensureInitialized();
-
_tests.add(new TestCase(_tests.length + 1, _fullSpec(spec), body, 0));
}
@@ -562,12 +560,11 @@
*/
void group(String description, void body()) {
ensureInitialized();
-
// Concatenate the new group.
final parentGroup = _currentGroup;
if (_currentGroup != '') {
// Add a space.
- _currentGroup = '$_currentGroup $description';
+ _currentGroup = '$_currentGroup$groupSep$description';
} else {
// The first group.
_currentGroup = description;
@@ -693,6 +690,24 @@
runTests();
}
+/**
+ * Filter the tests. [testFilter] can be a [RegExp], a [String] or a
+ * predicate function. This is different to enabling/disabling tests
+ * in that it removes the tests completely.
+ */
+void filterTests(testFilter) {
+ var filterFunction;
+ if (testFilter is String) {
+ RegExp re = new RegExp(testFilter);
+ filterFunction = (t) => re.hasMatch(t.description);
+ } else if (testFilter is RegExp) {
+ filterFunction = (t) => testFilter.hasMatch(t.description);
+ } else if (testFilter is Function) {
+ filterFunction = testFilter;
+ }
+ _tests = _tests.filter(filterFunction);
+}
+
/** Runs all queued tests, one at a time. */
runTests() {
_currentTest = 0;
@@ -700,14 +715,9 @@
// If we are soloing a test, remove all the others.
if (_soloTest != null) {
- _tests = _tests.filter((t) => t == _soloTest);
+ filterTests((t) => t == _soloTest);
}
- if (filter != null) {
- RegExp re = new RegExp(filter);
- _tests = _tests.filter((t) => re.hasMatch(t.description));
- }
-
_config.onStart();
_defer(() {
@@ -796,7 +806,7 @@
String _fullSpec(String spec) {
if (spec === null) return '$_currentGroup';
- return _currentGroup != '' ? '$_currentGroup $spec' : spec;
+ return _currentGroup != '' ? '$_currentGroup$groupSep$spec' : spec;
}
void _fail(String message) {
@@ -807,7 +817,9 @@
* Lazily initializes the test library if not already initialized.
*/
ensureInitialized() {
- if (_initialized) return;
+ if (_initialized) {
+ return;
+ }
_initialized = true;
_tests = <TestCase>[];
« no previous file with comments | « pkg/unittest/test_case.dart ('k') | utils/testrunner/configuration.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698