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

Side by Side Diff: test/runner/runner_test.dart

Issue 1041503002: Allow tests to be selected by name. (Closed) Base URL: git@github.com:dart-lang/unittest@master
Patch Set: Created 5 years, 9 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 unified diff | Download patch
« pubspec.yaml ('K') | « pubspec.yaml ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 @TestOn("vm") 5 @TestOn("vm")
6 6
7 import 'dart:io'; 7 import 'dart:io';
8 8
9 import 'package:path/path.dart' as p; 9 import 'package:path/path.dart' as p;
10 import 'package:unittest/src/util/exit_codes.dart' as exit_codes; 10 import 'package:unittest/src/util/exit_codes.dart' as exit_codes;
(...skipping 20 matching lines...) Expand all
31 31
32 void main() { 32 void main() {
33 test("failure", () => throw new TestFailure("oh no")); 33 test("failure", () => throw new TestFailure("oh no"));
34 } 34 }
35 """; 35 """;
36 36
37 final _usage = """ 37 final _usage = """
38 Usage: pub run unittest:unittest [files or directories...] 38 Usage: pub run unittest:unittest [files or directories...]
39 39
40 -h, --help Shows this usage information. 40 -h, --help Shows this usage information.
41 -n, --name A substring of the name of the test to run.
42 Regular expression syntax is supported.
43
41 -p, --platform The platform(s) on which to run the tests. 44 -p, --platform The platform(s) on which to run the tests.
42 [vm (default), chrome] 45 [vm (default), chrome]
43 46
44 --[no-]color Whether to use terminal colors. 47 --[no-]color Whether to use terminal colors.
45 (auto-detected by default) 48 (auto-detected by default)
46 """; 49 """;
47 50
48 void main() { 51 void main() {
49 setUp(() { 52 setUp(() {
50 _sandbox = Directory.systemTemp.createTempSync('unittest_').path; 53 _sandbox = Directory.systemTemp.createTempSync('unittest_').path;
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 test("directly", () { 260 test("directly", () {
258 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_failure); 261 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_failure);
259 var result = _runDart([ 262 var result = _runDart([
260 "--package-root=${p.join(packageDir, 'packages')}", 263 "--package-root=${p.join(packageDir, 'packages')}",
261 "test.dart" 264 "test.dart"
262 ]); 265 ]);
263 expect(result.stdout, contains("Some tests failed.")); 266 expect(result.stdout, contains("Some tests failed."));
264 }); 267 });
265 }); 268 });
266 269
267 group("flags", () { 270 group("flags:", () {
268 test("with the --color flag, uses colors", () { 271 test("with the --color flag, uses colors", () {
269 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_failure); 272 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_failure);
270 var result = _runUnittest(["--color", "test.dart"]); 273 var result = _runUnittest(["--color", "test.dart"]);
271 // This is the color code for red. 274 // This is the color code for red.
272 expect(result.stdout, contains("\u001b[31m")); 275 expect(result.stdout, contains("\u001b[31m"));
273 }); 276 });
277
278 group("with the --name flag,", () {
279 test("selects tests with matching names", () {
280 new File(p.join(_sandbox, "test.dart")).writeAsStringSync("""
281 import 'dart:async';
282
283 import 'package:unittest/unittest.dart';
284
285 void main() {
286 test("selected 1", () {});
287 test("nope", () => throw new TestFailure("oh no"));
288 test("selected 2", () {});
289 }
290 """);
291
292 var result = _runUnittest(["--name", "selected", "test.dart"]);
293 expect(result.stdout, contains("+2: All tests passed!"));
294 expect(result.exitCode, equals(0));
295 });
296
297 test("supports RegExp syntax", () {
298 new File(p.join(_sandbox, "test.dart")).writeAsStringSync("""
299 import 'dart:async';
300
301 import 'package:unittest/unittest.dart';
302
303 void main() {
304 test("test 1", () {});
305 test("test 2", () => throw new TestFailure("oh no"));
306 test("test 3", () {});
307 }
308 """);
309
310 var result = _runUnittest(["--name", "test [13]", "test.dart"]);
311 expect(result.stdout, contains("+2: All tests passed!"));
312 expect(result.exitCode, equals(0));
313 });
314
315 test("produces an error when no tests match", () {
316 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success);
317
318 var result = _runUnittest(["--name", "no match", "test.dart"]);
319 expect(result.stderr, contains('No tests match "no match".'));
320 expect(result.exitCode, equals(exit_codes.data));
321 });
322 });
274 }); 323 });
275 } 324 }
276 325
277 ProcessResult _runUnittest(List<String> args) => 326 ProcessResult _runUnittest(List<String> args) =>
278 runUnittest(args, workingDirectory: _sandbox); 327 runUnittest(args, workingDirectory: _sandbox);
279 328
280 ProcessResult _runDart(List<String> args) => 329 ProcessResult _runDart(List<String> args) =>
281 runDart(args, workingDirectory: _sandbox); 330 runDart(args, workingDirectory: _sandbox);
OLDNEW
« pubspec.yaml ('K') | « pubspec.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698