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

Side by Side Diff: bin/unittest.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 | « no previous file | lib/src/runner/console_reporter.dart » ('j') | 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 library unittest.unittest; 5 library unittest.unittest;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:io'; 8 import 'dart:io';
9 import 'dart:isolate'; 9 import 'dart:isolate';
10 10
11 import 'package:args/args.dart'; 11 import 'package:args/args.dart';
12 import 'package:stack_trace/stack_trace.dart'; 12 import 'package:stack_trace/stack_trace.dart';
13 13
14 import 'package:unittest/src/runner/console_reporter.dart'; 14 import 'package:unittest/src/runner/console_reporter.dart';
15 import 'package:unittest/src/runner/load_exception.dart'; 15 import 'package:unittest/src/runner/load_exception.dart';
16 import 'package:unittest/src/runner/loader.dart'; 16 import 'package:unittest/src/runner/loader.dart';
17 import 'package:unittest/src/util/exit_codes.dart' as exit_codes; 17 import 'package:unittest/src/util/exit_codes.dart' as exit_codes;
18 import 'package:unittest/src/util/io.dart'; 18 import 'package:unittest/src/util/io.dart';
19 import 'package:unittest/src/utils.dart'; 19 import 'package:unittest/src/utils.dart';
20 20
21 /// The argument parser used to parse the executable arguments. 21 /// The argument parser used to parse the executable arguments.
22 final _parser = new ArgParser(); 22 final _parser = new ArgParser();
23 23
24 void main(List<String> args) { 24 void main(List<String> args) {
25 _parser.addFlag("help", abbr: "h", negatable: false, 25 _parser.addFlag("help", abbr: "h", negatable: false,
26 help: "Shows this usage information."); 26 help: "Shows this usage information.");
27 _parser.addOption("package-root", hide: true); 27 _parser.addOption("package-root", hide: true);
28 _parser.addFlag("color", defaultsTo: null,
29 help: 'Whether to use terminal colors.\n(auto-detected by default)');
28 30
29 var options; 31 var options;
30 try { 32 try {
31 options = _parser.parse(args); 33 options = _parser.parse(args);
32 } on FormatException catch (error) { 34 } on FormatException catch (error) {
33 _printUsage(error.message); 35 _printUsage(error.message);
34 exitCode = exit_codes.usage; 36 exitCode = exit_codes.usage;
35 return; 37 return;
36 } 38 }
37 39
(...skipping 13 matching lines...) Expand all
51 } 53 }
52 paths = ["test"]; 54 paths = ["test"];
53 } 55 }
54 56
55 return Future.wait(paths.map((path) { 57 return Future.wait(paths.map((path) {
56 if (new Directory(path).existsSync()) return loader.loadDir(path); 58 if (new Directory(path).existsSync()) return loader.loadDir(path);
57 if (new File(path).existsSync()) return loader.loadFile(path); 59 if (new File(path).existsSync()) return loader.loadFile(path);
58 throw new LoadException(path, 'Does not exist.'); 60 throw new LoadException(path, 'Does not exist.');
59 })); 61 }));
60 }).then((suites) { 62 }).then((suites) {
61 var reporter = new ConsoleReporter(flatten(suites)); 63 var color = options["color"];
64 if (color == null) color = canUseSpecialChars;
65 var reporter = new ConsoleReporter(flatten(suites), color: color);
62 return reporter.run().then((success) { 66 return reporter.run().then((success) {
63 exitCode = success ? 0 : 1; 67 exitCode = success ? 0 : 1;
64 }).whenComplete(() => reporter.close()); 68 }).whenComplete(() => reporter.close());
65 }).catchError((error, stackTrace) { 69 }).catchError((error, stackTrace) {
66 if (error is LoadException) { 70 if (error is LoadException) {
67 // TODO(nweiz): color this message? 71 // TODO(nweiz): color this message?
68 stderr.writeln(getErrorMessage(error)); 72 stderr.writeln(getErrorMessage(error));
69 73
70 // Only print stack traces for load errors that come from the user's 74 // Only print stack traces for load errors that come from the user's
71 if (error.innerError is! IOException && 75 if (error.innerError is! IOException &&
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 output = stderr; 112 output = stderr;
109 } 113 }
110 114
111 output.write("""$message 115 output.write("""$message
112 116
113 Usage: pub run unittest:unittest [files or directories...] 117 Usage: pub run unittest:unittest [files or directories...]
114 118
115 ${_parser.usage} 119 ${_parser.usage}
116 """); 120 """);
117 } 121 }
OLDNEW
« no previous file with comments | « no previous file | lib/src/runner/console_reporter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698