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

Side by Side Diff: test/runner_test.dart

Issue 961003005: Add a flag to control the use of color in the test runner. (Closed) Base URL: git@github.com:dart-lang/unittest@master
Patch Set: Code review changes 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
« no previous file with comments | « lib/src/util/io.dart ('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 import 'dart:io'; 5 import 'dart:io';
6 6
7 import 'package:path/path.dart' as p; 7 import 'package:path/path.dart' as p;
8 import 'package:unittest/src/util/exit_codes.dart' as exit_codes; 8 import 'package:unittest/src/util/exit_codes.dart' as exit_codes;
9 import 'package:unittest/unittest.dart'; 9 import 'package:unittest/unittest.dart';
10 10
(...skipping 14 matching lines...) Expand all
25 final _failure = """ 25 final _failure = """
26 import 'dart:async'; 26 import 'dart:async';
27 27
28 import 'package:unittest/unittest.dart'; 28 import 'package:unittest/unittest.dart';
29 29
30 void main() { 30 void main() {
31 test("failure", () => throw new TestFailure("oh no")); 31 test("failure", () => throw new TestFailure("oh no"));
32 } 32 }
33 """; 33 """;
34 34
35 final _usage = """
36 Usage: pub run unittest:unittest [files or directories...]
37
38 -h, --help Shows this usage information.
39 --[no-]color Whether to use terminal colors.
40 (auto-detected by default)
41 """;
42
35 void main() { 43 void main() {
36 setUp(() { 44 setUp(() {
37 _sandbox = Directory.systemTemp.createTempSync('unittest_').path; 45 _sandbox = Directory.systemTemp.createTempSync('unittest_').path;
38 }); 46 });
39 47
40 tearDown(() { 48 tearDown(() {
41 new Directory(_sandbox).deleteSync(recursive: true); 49 new Directory(_sandbox).deleteSync(recursive: true);
42 }); 50 });
43 51
44 test("prints help information", () { 52 test("prints help information", () {
45 var result = _runUnittest(["--help"]); 53 var result = _runUnittest(["--help"]);
46 expect(result.stdout, equals(""" 54 expect(result.stdout, equals("""
47 Runs tests in this package. 55 Runs tests in this package.
48 56
49 Usage: pub run unittest:unittest [files or directories...] 57 $_usage"""));
50
51 -h, --help Shows this usage information.
52 """));
53 expect(result.exitCode, equals(exit_codes.success)); 58 expect(result.exitCode, equals(exit_codes.success));
54 }); 59 });
55 60
56 group("fails gracefully if", () { 61 group("fails gracefully if", () {
57 test("an invalid option is passed", () { 62 test("an invalid option is passed", () {
58 var result = _runUnittest(["--asdf"]); 63 var result = _runUnittest(["--asdf"]);
59 expect(result.stderr, equals(""" 64 expect(result.stderr, equals("""
60 Could not find an option named "asdf". 65 Could not find an option named "asdf".
61 66
62 Usage: pub run unittest:unittest [files or directories...] 67 $_usage"""));
63
64 -h, --help Shows this usage information.
65 """));
66 expect(result.exitCode, equals(exit_codes.usage)); 68 expect(result.exitCode, equals(exit_codes.usage));
67 }); 69 });
68 70
69 test("a non-existent file is passed", () { 71 test("a non-existent file is passed", () {
70 var result = _runUnittest(["file"]); 72 var result = _runUnittest(["file"]);
71 expect(result.stderr, equals('Failed to load "file": Does not exist.\n')); 73 expect(result.stderr, equals('Failed to load "file": Does not exist.\n'));
72 expect(result.exitCode, equals(exit_codes.data)); 74 expect(result.exitCode, equals(exit_codes.data));
73 }); 75 });
74 76
75 test("the default directory doesn't exist", () { 77 test("the default directory doesn't exist", () {
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 210
209 test("directly", () { 211 test("directly", () {
210 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_failure); 212 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_failure);
211 var result = _runDart([ 213 var result = _runDart([
212 "--package-root=${p.join(packageDir, 'packages')}", 214 "--package-root=${p.join(packageDir, 'packages')}",
213 "test.dart" 215 "test.dart"
214 ]); 216 ]);
215 expect(result.stdout, contains("Some tests failed.")); 217 expect(result.stdout, contains("Some tests failed."));
216 }); 218 });
217 }); 219 });
220
221 group("flags", () {
222 test("with the --color flag, uses colors", () {
223 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_failure);
224 var result = _runUnittest(["--color", "test.dart"]);
225 // This is the color code for red.
226 expect(result.stdout, contains("\u001b[31m"));
227 });
228 });
218 } 229 }
219 230
220 ProcessResult _runUnittest(List<String> args) => 231 ProcessResult _runUnittest(List<String> args) =>
221 runUnittest(args, workingDirectory: _sandbox); 232 runUnittest(args, workingDirectory: _sandbox);
222 233
223 ProcessResult _runDart(List<String> args) => 234 ProcessResult _runDart(List<String> args) =>
224 runDart(args, workingDirectory: _sandbox); 235 runDart(args, workingDirectory: _sandbox);
OLDNEW
« no previous file with comments | « lib/src/util/io.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698