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

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: cr Created 5 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 unified diff | Download patch
« no previous file with comments | « 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
44 -N, --plain-name A plain-text substring of the name of the test to run.
41 -p, --platform The platform(s) on which to run the tests. 45 -p, --platform The platform(s) on which to run the tests.
42 [vm (default), chrome] 46 [vm (default), chrome]
43 47
44 --[no-]color Whether to use terminal colors. 48 --[no-]color Whether to use terminal colors.
45 (auto-detected by default) 49 (auto-detected by default)
46 """; 50 """;
47 51
48 void main() { 52 void main() {
49 setUp(() { 53 setUp(() {
50 _sandbox = Directory.systemTemp.createTempSync('unittest_').path; 54 _sandbox = Directory.systemTemp.createTempSync('unittest_').path;
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 test("directly", () { 261 test("directly", () {
258 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_failure); 262 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_failure);
259 var result = _runDart([ 263 var result = _runDart([
260 "--package-root=${p.join(packageDir, 'packages')}", 264 "--package-root=${p.join(packageDir, 'packages')}",
261 "test.dart" 265 "test.dart"
262 ]); 266 ]);
263 expect(result.stdout, contains("Some tests failed.")); 267 expect(result.stdout, contains("Some tests failed."));
264 }); 268 });
265 }); 269 });
266 270
267 group("flags", () { 271 group("flags:", () {
268 test("with the --color flag, uses colors", () { 272 test("with the --color flag, uses colors", () {
269 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_failure); 273 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_failure);
270 var result = _runUnittest(["--color", "test.dart"]); 274 var result = _runUnittest(["--color", "test.dart"]);
271 // This is the color code for red. 275 // This is the color code for red.
272 expect(result.stdout, contains("\u001b[31m")); 276 expect(result.stdout, contains("\u001b[31m"));
273 }); 277 });
278
279 group("with the --name flag,", () {
280 test("selects tests with matching names", () {
281 new File(p.join(_sandbox, "test.dart")).writeAsStringSync("""
282 import 'dart:async';
283
284 import 'package:unittest/unittest.dart';
285
286 void main() {
287 test("selected 1", () {});
288 test("nope", () => throw new TestFailure("oh no"));
289 test("selected 2", () {});
290 }
291 """);
292
293 var result = _runUnittest(["--name", "selected", "test.dart"]);
294 expect(result.stdout, contains("+2: All tests passed!"));
295 expect(result.exitCode, equals(0));
296 });
297
298 test("supports RegExp syntax", () {
299 new File(p.join(_sandbox, "test.dart")).writeAsStringSync("""
300 import 'dart:async';
301
302 import 'package:unittest/unittest.dart';
303
304 void main() {
305 test("test 1", () {});
306 test("test 2", () => throw new TestFailure("oh no"));
307 test("test 3", () {});
308 }
309 """);
310
311 var result = _runUnittest(["--name", "test [13]", "test.dart"]);
312 expect(result.stdout, contains("+2: All tests passed!"));
313 expect(result.exitCode, equals(0));
314 });
315
316 test("produces an error when no tests match", () {
317 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success);
318
319 var result = _runUnittest(["--name", "no match", "test.dart"]);
320 expect(result.stderr,
321 contains('No tests match regular expression "no match".'));
322 expect(result.exitCode, equals(exit_codes.data));
323 });
324 });
325
326 group("with the --plain-name flag,", () {
327 test("selects tests with matching names", () {
328 new File(p.join(_sandbox, "test.dart")).writeAsStringSync("""
329 import 'dart:async';
330
331 import 'package:unittest/unittest.dart';
332
333 void main() {
334 test("selected 1", () {});
335 test("nope", () => throw new TestFailure("oh no"));
336 test("selected 2", () {});
337 }
338 """);
339
340 var result = _runUnittest(["--plain-name", "selected", "test.dart"]);
341 expect(result.stdout, contains("+2: All tests passed!"));
342 expect(result.exitCode, equals(0));
343 });
344
345 test("doesn't support RegExp syntax", () {
346 new File(p.join(_sandbox, "test.dart")).writeAsStringSync("""
347 import 'dart:async';
348
349 import 'package:unittest/unittest.dart';
350
351 void main() {
352 test("test 1", () => throw new TestFailure("oh no"));
353 test("test 2", () => throw new TestFailure("oh no"));
354 test("test [12]", () {});
355 }
356 """);
357
358 var result = _runUnittest(["--plain-name", "test [12]", "test.dart"]);
359 expect(result.stdout, contains("+1: All tests passed!"));
360 expect(result.exitCode, equals(0));
361 });
362
363 test("produces an error when no tests match", () {
364 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success);
365
366 var result = _runUnittest(["--plain-name", "no match", "test.dart"]);
367 expect(result.stderr,
368 contains('No tests match "no match".'));
369 expect(result.exitCode, equals(exit_codes.data));
370 });
371 });
274 }); 372 });
275 } 373 }
276 374
277 ProcessResult _runUnittest(List<String> args) => 375 ProcessResult _runUnittest(List<String> args) =>
278 runUnittest(args, workingDirectory: _sandbox); 376 runUnittest(args, workingDirectory: _sandbox);
279 377
280 ProcessResult _runDart(List<String> args) => 378 ProcessResult _runDart(List<String> args) =>
281 runDart(args, workingDirectory: _sandbox); 379 runDart(args, workingDirectory: _sandbox);
OLDNEW
« no previous file with comments | « pubspec.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698