OLD | NEW |
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 test.test; |
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/backend/test_platform.dart'; | 14 import 'package:test/src/backend/test_platform.dart'; |
15 import 'package:unittest/src/runner/reporter/compact.dart'; | 15 import 'package:test/src/runner/reporter/compact.dart'; |
16 import 'package:unittest/src/runner/load_exception.dart'; | 16 import 'package:test/src/runner/load_exception.dart'; |
17 import 'package:unittest/src/runner/loader.dart'; | 17 import 'package:test/src/runner/loader.dart'; |
18 import 'package:unittest/src/util/exit_codes.dart' as exit_codes; | 18 import 'package:test/src/util/exit_codes.dart' as exit_codes; |
19 import 'package:unittest/src/util/io.dart'; | 19 import 'package:test/src/util/io.dart'; |
20 import 'package:unittest/src/utils.dart'; | 20 import 'package:test/src/utils.dart'; |
21 | 21 |
22 /// The argument parser used to parse the executable arguments. | 22 /// The argument parser used to parse the executable arguments. |
23 final _parser = new ArgParser(allowTrailingOptions: true); | 23 final _parser = new ArgParser(allowTrailingOptions: true); |
24 | 24 |
25 void main(List<String> args) { | 25 void main(List<String> args) { |
26 _parser.addFlag("help", abbr: "h", negatable: false, | 26 _parser.addFlag("help", abbr: "h", negatable: false, |
27 help: "Shows this usage information."); | 27 help: "Shows this usage information."); |
28 _parser.addOption("package-root", hide: true); | 28 _parser.addOption("package-root", hide: true); |
29 _parser.addOption("name", | 29 _parser.addOption("name", |
30 abbr: 'n', | 30 abbr: 'n', |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 } | 129 } |
130 | 130 |
131 exitCode = error.innerError is IOException | 131 exitCode = error.innerError is IOException |
132 ? exit_codes.io | 132 ? exit_codes.io |
133 : exit_codes.data; | 133 : exit_codes.data; |
134 } else { | 134 } else { |
135 stderr.writeln(getErrorMessage(error)); | 135 stderr.writeln(getErrorMessage(error)); |
136 stderr.writeln(new Trace.from(stackTrace).terse); | 136 stderr.writeln(new Trace.from(stackTrace).terse); |
137 stderr.writeln( | 137 stderr.writeln( |
138 "This is an unexpected error. Please file an issue at " | 138 "This is an unexpected error. Please file an issue at " |
139 "http://github.com/dart-lang/unittest\n" | 139 "http://github.com/dart-lang/test\n" |
140 "with the stack trace and instructions for reproducing the error."); | 140 "with the stack trace and instructions for reproducing the error."); |
141 exitCode = exit_codes.software; | 141 exitCode = exit_codes.software; |
142 } | 142 } |
143 }).whenComplete(() { | 143 }).whenComplete(() { |
144 return loader.close().then((_) { | 144 return loader.close().then((_) { |
145 // If we're on a Dart version that doesn't support Isolate.kill(), we have | 145 // If we're on a Dart version that doesn't support Isolate.kill(), we have |
146 // to manually exit so that dangling isolates don't prevent it. | 146 // to manually exit so that dangling isolates don't prevent it. |
147 if (!supportsIsolateKill) exit(exitCode); | 147 if (!supportsIsolateKill) exit(exitCode); |
148 }); | 148 }); |
149 }); | 149 }); |
150 } | 150 } |
151 | 151 |
152 /// Print usage information for this command. | 152 /// Print usage information for this command. |
153 /// | 153 /// |
154 /// If [error] is passed, it's used in place of the usage message and the whole | 154 /// If [error] is passed, it's used in place of the usage message and the whole |
155 /// thing is printed to stderr instead of stdout. | 155 /// thing is printed to stderr instead of stdout. |
156 void _printUsage([String error]) { | 156 void _printUsage([String error]) { |
157 var output = stdout; | 157 var output = stdout; |
158 | 158 |
159 var message = "Runs tests in this package."; | 159 var message = "Runs tests in this package."; |
160 if (error != null) { | 160 if (error != null) { |
161 message = error; | 161 message = error; |
162 output = stderr; | 162 output = stderr; |
163 } | 163 } |
164 | 164 |
165 output.write("""$message | 165 output.write("""$message |
166 | 166 |
167 Usage: pub run unittest:unittest [files or directories...] | 167 Usage: pub run test:test [files or directories...] |
168 | 168 |
169 ${_parser.usage} | 169 ${_parser.usage} |
170 """); | 170 """); |
171 } | 171 } |
OLD | NEW |