| 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 test.runner.configuration; | 5 library test.runner.configuration; |
| 6 | 6 |
| 7 import 'dart:io'; | 7 import 'dart:io'; |
| 8 import 'dart:math' as math; | 8 import 'dart:math' as math; |
| 9 | 9 |
| 10 import 'package:args/args.dart'; | 10 import 'package:args/args.dart'; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 'compact': 'A single line, updated continuously.', | 71 'compact': 'A single line, updated continuously.', |
| 72 'expanded': 'A separate line for each update.' | 72 'expanded': 'A separate line for each update.' |
| 73 }); | 73 }); |
| 74 parser.addFlag("verbose-trace", negatable: false, | 74 parser.addFlag("verbose-trace", negatable: false, |
| 75 help: 'Whether to emit stack traces with core library frames.'); | 75 help: 'Whether to emit stack traces with core library frames.'); |
| 76 parser.addFlag("js-trace", negatable: false, | 76 parser.addFlag("js-trace", negatable: false, |
| 77 help: 'Whether to emit raw JavaScript stack traces for browser tests.'); | 77 help: 'Whether to emit raw JavaScript stack traces for browser tests.'); |
| 78 parser.addFlag("color", defaultsTo: null, | 78 parser.addFlag("color", defaultsTo: null, |
| 79 help: 'Whether to use terminal colors.\n(auto-detected by default)'); | 79 help: 'Whether to use terminal colors.\n(auto-detected by default)'); |
| 80 parser.addOption("tags", | 80 parser.addOption("tags", |
| 81 abbr: 't', |
| 81 help: 'Comma-separated list of tags to run', | 82 help: 'Comma-separated list of tags to run', |
| 82 allowMultiple: true, | 83 allowMultiple: true, |
| 83 splitCommas: true); | 84 splitCommas: true); |
| 85 parser.addOption("tag", |
| 86 hide: true, |
| 87 help: 'Same as --tags', |
| 88 allowMultiple: true, |
| 89 splitCommas: true); |
| 84 | 90 |
| 85 return parser; | 91 return parser; |
| 86 })(); | 92 })(); |
| 87 | 93 |
| 88 /// The usage string for the command-line arguments. | 94 /// The usage string for the command-line arguments. |
| 89 static String get usage => _parser.usage; | 95 static String get usage => _parser.usage; |
| 90 | 96 |
| 91 /// Whether `--help` was passed. | 97 /// Whether `--help` was passed. |
| 92 final bool help; | 98 final bool help; |
| 93 | 99 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 final bool explicitPaths; | 134 final bool explicitPaths; |
| 129 | 135 |
| 130 /// The pattern to match against test names to decide which to run, or `null` | 136 /// The pattern to match against test names to decide which to run, or `null` |
| 131 /// if all tests should be run. | 137 /// if all tests should be run. |
| 132 final Pattern pattern; | 138 final Pattern pattern; |
| 133 | 139 |
| 134 /// The set of platforms on which to run tests. | 140 /// The set of platforms on which to run tests. |
| 135 final List<TestPlatform> platforms; | 141 final List<TestPlatform> platforms; |
| 136 | 142 |
| 137 /// Restricts the set of tests to a set of tags | 143 /// Restricts the set of tests to a set of tags |
| 138 final List<String> tags; | 144 final Set<String> tags; |
| 139 | 145 |
| 140 /// The global test metadata derived from this configuration. | 146 /// The global test metadata derived from this configuration. |
| 141 Metadata get metadata => | 147 Metadata get metadata => |
| 142 new Metadata( | 148 new Metadata( |
| 143 timeout: pauseAfterLoad ? Timeout.none : null, | 149 timeout: pauseAfterLoad ? Timeout.none : null, |
| 144 verboseTrace: verboseTrace); | 150 verboseTrace: verboseTrace); |
| 145 | 151 |
| 146 /// Parses the configuration from [args]. | 152 /// Parses the configuration from [args]. |
| 147 /// | 153 /// |
| 148 /// Throws a [FormatException] if [args] are invalid. | 154 /// Throws a [FormatException] if [args] are invalid. |
| 149 factory Configuration.parse(List<String> args) { | 155 factory Configuration.parse(List<String> args) { |
| 150 var options = _parser.parse(args); | 156 var options = _parser.parse(args); |
| 151 | 157 |
| 152 var pattern; | 158 var pattern; |
| 153 if (options['name'] != null) { | 159 if (options['name'] != null) { |
| 154 if (options["plain-name"] != null) { | 160 if (options["plain-name"] != null) { |
| 155 throw new FormatException( | 161 throw new FormatException( |
| 156 "--name and --plain-name may not both be passed."); | 162 "--name and --plain-name may not both be passed."); |
| 157 } | 163 } |
| 158 | 164 |
| 159 pattern = _wrapFormatException( | 165 pattern = _wrapFormatException( |
| 160 options, 'name', (value) => new RegExp(value)); | 166 options, 'name', (value) => new RegExp(value)); |
| 161 } else if (options['plain-name'] != null) { | 167 } else if (options['plain-name'] != null) { |
| 162 pattern = options['plain-name']; | 168 pattern = options['plain-name']; |
| 163 } | 169 } |
| 164 | 170 |
| 171 var tags = new Set<String>(); |
| 172 if (options['tags'] != null) { |
| 173 tags.addAll(options['tags']); |
| 174 } |
| 175 if (options['tag'] != null) { |
| 176 tags.addAll(options['tag']); |
| 177 } |
| 165 return new Configuration( | 178 return new Configuration( |
| 166 help: options['help'], | 179 help: options['help'], |
| 167 version: options['version'], | 180 version: options['version'], |
| 168 verboseTrace: options['verbose-trace'], | 181 verboseTrace: options['verbose-trace'], |
| 169 jsTrace: options['js-trace'], | 182 jsTrace: options['js-trace'], |
| 170 pauseAfterLoad: options['pause-after-load'], | 183 pauseAfterLoad: options['pause-after-load'], |
| 171 color: options['color'], | 184 color: options['color'], |
| 172 packageRoot: options['package-root'], | 185 packageRoot: options['package-root'], |
| 173 reporter: options['reporter'], | 186 reporter: options['reporter'], |
| 174 pubServePort: _wrapFormatException(options, 'pub-serve', int.parse), | 187 pubServePort: _wrapFormatException(options, 'pub-serve', int.parse), |
| 175 concurrency: _wrapFormatException(options, 'concurrency', int.parse, | 188 concurrency: _wrapFormatException(options, 'concurrency', int.parse, |
| 176 orElse: () => _defaultConcurrency), | 189 orElse: () => _defaultConcurrency), |
| 177 pattern: pattern, | 190 pattern: pattern, |
| 178 platforms: options['platform'].map(TestPlatform.find), | 191 platforms: options['platform'].map(TestPlatform.find), |
| 179 paths: options.rest.isEmpty ? null : options.rest, | 192 paths: options.rest.isEmpty ? null : options.rest, |
| 180 tags: options['tags']); | 193 tags: tags); |
| 181 } | 194 } |
| 182 | 195 |
| 183 /// Runs [parse] on the value of the option [name], and wraps any | 196 /// Runs [parse] on the value of the option [name], and wraps any |
| 184 /// [FormatException] it throws with additional information. | 197 /// [FormatException] it throws with additional information. |
| 185 static _wrapFormatException(ArgResults options, String name, parse(value), | 198 static _wrapFormatException(ArgResults options, String name, parse(value), |
| 186 {orElse()}) { | 199 {orElse()}) { |
| 187 var value = options[name]; | 200 var value = options[name]; |
| 188 if (value == null) return orElse == null ? null : orElse(); | 201 if (value == null) return orElse == null ? null : orElse(); |
| 189 | 202 |
| 190 try { | 203 try { |
| 191 return parse(value); | 204 return parse(value); |
| 192 } on FormatException catch (error) { | 205 } on FormatException catch (error) { |
| 193 throw new FormatException('Couldn\'t parse --$name "${options[name]}": ' | 206 throw new FormatException('Couldn\'t parse --$name "${options[name]}": ' |
| 194 '${error.message}'); | 207 '${error.message}'); |
| 195 } | 208 } |
| 196 } | 209 } |
| 197 | 210 |
| 198 Configuration({this.help: false, this.version: false, | 211 Configuration({this.help: false, this.version: false, |
| 199 this.verboseTrace: false, this.jsTrace: false, | 212 this.verboseTrace: false, this.jsTrace: false, |
| 200 bool pauseAfterLoad: false, bool color, String packageRoot, | 213 bool pauseAfterLoad: false, bool color, String packageRoot, |
| 201 String reporter, int pubServePort, int concurrency, this.pattern, | 214 String reporter, int pubServePort, int concurrency, this.pattern, |
| 202 Iterable<TestPlatform> platforms, Iterable<String> paths, | 215 Iterable<TestPlatform> platforms, Iterable<String> paths, |
| 203 List<String> tags}) | 216 Set<String> tags}) |
| 204 : pauseAfterLoad = pauseAfterLoad, | 217 : pauseAfterLoad = pauseAfterLoad, |
| 205 color = color == null ? canUseSpecialChars : color, | 218 color = color == null ? canUseSpecialChars : color, |
| 206 packageRoot = packageRoot == null | 219 packageRoot = packageRoot == null |
| 207 ? p.join(p.current, 'packages') | 220 ? p.join(p.current, 'packages') |
| 208 : packageRoot, | 221 : packageRoot, |
| 209 reporter = reporter == null ? 'compact' : reporter, | 222 reporter = reporter == null ? 'compact' : reporter, |
| 210 pubServeUrl = pubServePort == null | 223 pubServeUrl = pubServePort == null |
| 211 ? null | 224 ? null |
| 212 : Uri.parse("http://localhost:$pubServePort"), | 225 : Uri.parse("http://localhost:$pubServePort"), |
| 213 concurrency = pauseAfterLoad | 226 concurrency = pauseAfterLoad |
| 214 ? 1 | 227 ? 1 |
| 215 : (concurrency == null ? _defaultConcurrency : concurrency), | 228 : (concurrency == null ? _defaultConcurrency : concurrency), |
| 216 platforms = platforms == null ? [TestPlatform.vm] : platforms.toList(), | 229 platforms = platforms == null ? [TestPlatform.vm] : platforms.toList(), |
| 217 paths = paths == null ? ["test"] : paths.toList(), | 230 paths = paths == null ? ["test"] : paths.toList(), |
| 218 explicitPaths = paths != null, | 231 explicitPaths = paths != null, |
| 219 this.tags = tags == null | 232 this.tags = tags; |
| 220 ? const <String>[] | |
| 221 : tags; | |
| 222 } | 233 } |
| OLD | NEW |