| 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 // TODO(nweiz): This is under lib so that it can be used by the unittest dummy | 5 // TODO(nweiz): This is under lib so that it can be used by the unittest dummy |
| 6 // package. Once that package is no longer being updated, move this back into | 6 // package. Once that package is no longer being updated, move this back into |
| 7 // bin. | 7 // bin. |
| 8 library test.executable; | 8 library test.executable; |
| 9 | 9 |
| 10 import 'dart:async'; | 10 import 'dart:async'; |
| 11 import 'dart:io'; | 11 import 'dart:io'; |
| 12 import 'dart:math' as math; | 12 import 'dart:math' as math; |
| 13 | 13 |
| 14 import 'package:args/args.dart'; | 14 import 'package:args/args.dart'; |
| 15 import 'package:stack_trace/stack_trace.dart'; | 15 import 'package:stack_trace/stack_trace.dart'; |
| 16 import 'package:yaml/yaml.dart'; | 16 import 'package:yaml/yaml.dart'; |
| 17 | 17 |
| 18 import 'backend/test_platform.dart'; | 18 import 'backend/test_platform.dart'; |
| 19 import 'runner/reporter/compact.dart'; | 19 import 'runner/reporter/compact.dart'; |
| 20 import 'runner/reporter/expanded.dart'; |
| 20 import 'runner/application_exception.dart'; | 21 import 'runner/application_exception.dart'; |
| 21 import 'runner/load_exception.dart'; | 22 import 'runner/load_exception.dart'; |
| 22 import 'runner/load_exception_suite.dart'; | 23 import 'runner/load_exception_suite.dart'; |
| 23 import 'runner/loader.dart'; | 24 import 'runner/loader.dart'; |
| 24 import 'util/exit_codes.dart' as exit_codes; | 25 import 'util/exit_codes.dart' as exit_codes; |
| 25 import 'util/io.dart'; | 26 import 'util/io.dart'; |
| 26 import 'utils.dart'; | 27 import 'utils.dart'; |
| 27 | 28 |
| 28 /// The argument parser used to parse the executable arguments. | 29 /// The argument parser used to parse the executable arguments. |
| 29 final _parser = new ArgParser(allowTrailingOptions: true); | 30 final _parser = new ArgParser(allowTrailingOptions: true); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 allowMultiple: true); | 99 allowMultiple: true); |
| 99 _parser.addOption("concurrency", | 100 _parser.addOption("concurrency", |
| 100 abbr: 'j', | 101 abbr: 'j', |
| 101 help: 'The number of concurrent test suites run.\n' | 102 help: 'The number of concurrent test suites run.\n' |
| 102 '(defaults to $_defaultConcurrency)', | 103 '(defaults to $_defaultConcurrency)', |
| 103 valueHelp: 'threads'); | 104 valueHelp: 'threads'); |
| 104 _parser.addOption("pub-serve", | 105 _parser.addOption("pub-serve", |
| 105 help: 'The port of a pub serve instance serving "test/".', | 106 help: 'The port of a pub serve instance serving "test/".', |
| 106 hide: !supportsPubServe, | 107 hide: !supportsPubServe, |
| 107 valueHelp: 'port'); | 108 valueHelp: 'port'); |
| 109 _parser.addOption("reporter", |
| 110 abbr: 'r', |
| 111 help: 'The runner used to print test results.', |
| 112 allowed: ['compact', 'expanded'], |
| 113 defaultsTo: Platform.isWindows ? 'expanded' : 'compact', |
| 114 allowedHelp: { |
| 115 'compact': 'A single line, updated continuously.', |
| 116 'expanded': 'A separate line for each update.' |
| 117 }); |
| 108 _parser.addFlag("color", defaultsTo: null, | 118 _parser.addFlag("color", defaultsTo: null, |
| 109 help: 'Whether to use terminal colors.\n(auto-detected by default)'); | 119 help: 'Whether to use terminal colors.\n(auto-detected by default)'); |
| 110 | 120 |
| 111 var options; | 121 var options; |
| 112 try { | 122 try { |
| 113 options = _parser.parse(args); | 123 options = _parser.parse(args); |
| 114 } on FormatException catch (error) { | 124 } on FormatException catch (error) { |
| 115 _printUsage(error.message); | 125 _printUsage(error.message); |
| 116 exitCode = exit_codes.usage; | 126 exitCode = exit_codes.usage; |
| 117 return; | 127 return; |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 if (pattern is RegExp) { | 240 if (pattern is RegExp) { |
| 231 stderr.writeln('regular expression "${pattern.pattern}".'); | 241 stderr.writeln('regular expression "${pattern.pattern}".'); |
| 232 } else { | 242 } else { |
| 233 stderr.writeln('"$pattern".'); | 243 stderr.writeln('"$pattern".'); |
| 234 } | 244 } |
| 235 exitCode = exit_codes.data; | 245 exitCode = exit_codes.data; |
| 236 return null; | 246 return null; |
| 237 } | 247 } |
| 238 } | 248 } |
| 239 | 249 |
| 240 var reporter = new CompactReporter(flatten(suites), | 250 var reporter = options["reporter"] == "compact" |
| 241 concurrency: concurrency, color: color); | 251 ? new CompactReporter(flatten(suites), |
| 252 concurrency: concurrency, color: color) |
| 253 : new ExpandedReporter(flatten(suites), |
| 254 concurrency: concurrency, color: color); |
| 242 | 255 |
| 243 // Override the signal handler to close [reporter]. [loader] will still be | 256 // Override the signal handler to close [reporter]. [loader] will still be |
| 244 // closed in the [whenComplete] below. | 257 // closed in the [whenComplete] below. |
| 245 signalSubscription.onData((_) { | 258 signalSubscription.onData((_) { |
| 246 signalSubscription.cancel(); | 259 signalSubscription.cancel(); |
| 247 closed = true; | 260 closed = true; |
| 248 | 261 |
| 249 // Wait a bit to print this message, since printing it eagerly looks weird | 262 // Wait a bit to print this message, since printing it eagerly looks weird |
| 250 // if the tests then finish immediately. | 263 // if the tests then finish immediately. |
| 251 var timer = new Timer(new Duration(seconds: 1), () { | 264 var timer = new Timer(new Duration(seconds: 1), () { |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 if (description is! Map) return false; | 372 if (description is! Map) return false; |
| 360 var path = description["path"]; | 373 var path = description["path"]; |
| 361 if (path is! String) return false; | 374 if (path is! String) return false; |
| 362 | 375 |
| 363 print("$version (from $path)"); | 376 print("$version (from $path)"); |
| 364 return true; | 377 return true; |
| 365 | 378 |
| 366 default: return false; | 379 default: return false; |
| 367 } | 380 } |
| 368 } | 381 } |
| OLD | NEW |