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

Unified Diff: lib/unittest/unittest.dart

Issue 10627008: Added the ability to filter which tests are run by name, using a --filter (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 6 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
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();

Powered by Google App Engine
This is Rietveld 408576698