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 help: 'Comma-separated list of tags to run', | 81 abbr: 't', |
82 allowMultiple: true, | 82 help: 'Comma-separated list of tags to run', |
83 splitCommas: true); | 83 allowMultiple: true, |
84 splitCommas: true); | |
85 parser.addOption("tag", | |
86 hide: true, | |
87 help: 'Same as --tags', | |
nweiz
2015/11/16 21:59:44
There's no need for help on a hidden option.
yjbanov
2015/11/26 06:30:27
Done.
| |
88 allowMultiple: true, | |
89 splitCommas: true); | |
90 parser.addOption("exclude-tags", | |
91 abbr: 'e', | |
nweiz
2015/11/16 21:59:44
Let's make this "x".
yjbanov
2015/11/26 06:30:27
Done.
| |
92 help: 'Comma-separated list of tags not to run', | |
93 allowMultiple: true, | |
94 splitCommas: true); | |
95 parser.addOption("exclude-tag", | |
96 hide: true, | |
97 help: 'Same as --exclude-tag', | |
98 allowMultiple: true, | |
99 splitCommas: true); | |
84 | 100 |
85 return parser; | 101 return parser; |
86 })(); | 102 })(); |
87 | 103 |
88 /// The usage string for the command-line arguments. | 104 /// The usage string for the command-line arguments. |
89 static String get usage => _parser.usage; | 105 static String get usage => _parser.usage; |
90 | 106 |
91 /// Whether `--help` was passed. | 107 /// Whether `--help` was passed. |
92 final bool help; | 108 final bool help; |
93 | 109 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 final bool explicitPaths; | 144 final bool explicitPaths; |
129 | 145 |
130 /// The pattern to match against test names to decide which to run, or `null` | 146 /// The pattern to match against test names to decide which to run, or `null` |
131 /// if all tests should be run. | 147 /// if all tests should be run. |
132 final Pattern pattern; | 148 final Pattern pattern; |
133 | 149 |
134 /// The set of platforms on which to run tests. | 150 /// The set of platforms on which to run tests. |
135 final List<TestPlatform> platforms; | 151 final List<TestPlatform> platforms; |
136 | 152 |
137 /// Restricts the set of tests to a set of tags | 153 /// Restricts the set of tests to a set of tags |
138 final List<String> tags; | 154 final Set<String> tags; |
155 | |
156 /// Does not run tests with tags from this set | |
157 final Set<String> excludeTags; | |
139 | 158 |
140 /// The global test metadata derived from this configuration. | 159 /// The global test metadata derived from this configuration. |
141 Metadata get metadata => | 160 Metadata get metadata => |
142 new Metadata( | 161 new Metadata( |
143 timeout: pauseAfterLoad ? Timeout.none : null, | 162 timeout: pauseAfterLoad ? Timeout.none : null, |
144 verboseTrace: verboseTrace); | 163 verboseTrace: verboseTrace); |
145 | 164 |
146 /// Parses the configuration from [args]. | 165 /// Parses the configuration from [args]. |
147 /// | 166 /// |
148 /// Throws a [FormatException] if [args] are invalid. | 167 /// Throws a [FormatException] if [args] are invalid. |
149 factory Configuration.parse(List<String> args) { | 168 factory Configuration.parse(List<String> args) { |
150 var options = _parser.parse(args); | 169 var options = _parser.parse(args); |
151 | 170 |
152 var pattern; | 171 var pattern; |
153 if (options['name'] != null) { | 172 if (options['name'] != null) { |
154 if (options["plain-name"] != null) { | 173 if (options["plain-name"] != null) { |
155 throw new FormatException( | 174 throw new FormatException( |
156 "--name and --plain-name may not both be passed."); | 175 "--name and --plain-name may not both be passed."); |
157 } | 176 } |
158 | 177 |
159 pattern = _wrapFormatException( | 178 pattern = _wrapFormatException( |
160 options, 'name', (value) => new RegExp(value)); | 179 options, 'name', (value) => new RegExp(value)); |
161 } else if (options['plain-name'] != null) { | 180 } else if (options['plain-name'] != null) { |
162 pattern = options['plain-name']; | 181 pattern = options['plain-name']; |
163 } | 182 } |
164 | 183 |
184 var tags = new Set<String>(); | |
185 if (options['tags'] != null) { | |
186 tags.addAll(options['tags']); | |
187 } | |
188 if (options['tag'] != null) { | |
189 tags.addAll(options['tag']); | |
190 } | |
191 | |
192 var excludeTags = new Set<String>(); | |
193 if (options['exclude-tags'] != null) { | |
194 excludeTags.addAll(options['exclude-tags']); | |
195 } | |
196 if (options['exclude-tag'] != null) { | |
197 excludeTags.addAll(options['exclude-tag']); | |
nweiz
2015/11/16 21:59:44
It's safe to use ?? here, which should clean this
yjbanov
2015/11/26 06:30:27
Done.
| |
198 } | |
199 | |
200 var tagIntersection = tags.intersection(excludeTags); | |
201 if (tagIntersection.isNotEmpty) { | |
202 throw new FormatException('Included and excluded tag sets may not' | |
203 ' intersect. Found intersection: ${tagIntersection.join(', ')}'); | |
204 } | |
205 | |
165 return new Configuration( | 206 return new Configuration( |
166 help: options['help'], | 207 help: options['help'], |
167 version: options['version'], | 208 version: options['version'], |
168 verboseTrace: options['verbose-trace'], | 209 verboseTrace: options['verbose-trace'], |
169 jsTrace: options['js-trace'], | 210 jsTrace: options['js-trace'], |
170 pauseAfterLoad: options['pause-after-load'], | 211 pauseAfterLoad: options['pause-after-load'], |
171 color: options['color'], | 212 color: options['color'], |
172 packageRoot: options['package-root'], | 213 packageRoot: options['package-root'], |
173 reporter: options['reporter'], | 214 reporter: options['reporter'], |
174 pubServePort: _wrapFormatException(options, 'pub-serve', int.parse), | 215 pubServePort: _wrapFormatException(options, 'pub-serve', int.parse), |
175 concurrency: _wrapFormatException(options, 'concurrency', int.parse, | 216 concurrency: _wrapFormatException(options, 'concurrency', int.parse, |
176 orElse: () => _defaultConcurrency), | 217 orElse: () => _defaultConcurrency), |
177 pattern: pattern, | 218 pattern: pattern, |
178 platforms: options['platform'].map(TestPlatform.find), | 219 platforms: options['platform'].map(TestPlatform.find), |
179 paths: options.rest.isEmpty ? null : options.rest, | 220 paths: options.rest.isEmpty ? null : options.rest, |
180 tags: options['tags']); | 221 tags: tags, |
222 excludeTags: excludeTags); | |
181 } | 223 } |
182 | 224 |
183 /// Runs [parse] on the value of the option [name], and wraps any | 225 /// Runs [parse] on the value of the option [name], and wraps any |
184 /// [FormatException] it throws with additional information. | 226 /// [FormatException] it throws with additional information. |
185 static _wrapFormatException(ArgResults options, String name, parse(value), | 227 static _wrapFormatException(ArgResults options, String name, parse(value), |
186 {orElse()}) { | 228 {orElse()}) { |
187 var value = options[name]; | 229 var value = options[name]; |
188 if (value == null) return orElse == null ? null : orElse(); | 230 if (value == null) return orElse == null ? null : orElse(); |
189 | 231 |
190 try { | 232 try { |
191 return parse(value); | 233 return parse(value); |
192 } on FormatException catch (error) { | 234 } on FormatException catch (error) { |
193 throw new FormatException('Couldn\'t parse --$name "${options[name]}": ' | 235 throw new FormatException('Couldn\'t parse --$name "${options[name]}": ' |
194 '${error.message}'); | 236 '${error.message}'); |
195 } | 237 } |
196 } | 238 } |
197 | 239 |
198 Configuration({this.help: false, this.version: false, | 240 Configuration({this.help: false, this.version: false, |
199 this.verboseTrace: false, this.jsTrace: false, | 241 this.verboseTrace: false, this.jsTrace: false, |
200 bool pauseAfterLoad: false, bool color, String packageRoot, | 242 bool pauseAfterLoad: false, bool color, String packageRoot, |
201 String reporter, int pubServePort, int concurrency, this.pattern, | 243 String reporter, int pubServePort, int concurrency, this.pattern, |
202 Iterable<TestPlatform> platforms, Iterable<String> paths, | 244 Iterable<TestPlatform> platforms, Iterable<String> paths, |
203 List<String> tags}) | 245 Set<String> tags, Set<String> excludeTags}) |
204 : pauseAfterLoad = pauseAfterLoad, | 246 : pauseAfterLoad = pauseAfterLoad, |
205 color = color == null ? canUseSpecialChars : color, | 247 color = color == null ? canUseSpecialChars : color, |
206 packageRoot = packageRoot == null | 248 packageRoot = packageRoot == null |
207 ? p.join(p.current, 'packages') | 249 ? p.join(p.current, 'packages') |
208 : packageRoot, | 250 : packageRoot, |
209 reporter = reporter == null ? 'compact' : reporter, | 251 reporter = reporter == null ? 'compact' : reporter, |
210 pubServeUrl = pubServePort == null | 252 pubServeUrl = pubServePort == null |
211 ? null | 253 ? null |
212 : Uri.parse("http://localhost:$pubServePort"), | 254 : Uri.parse("http://localhost:$pubServePort"), |
213 concurrency = pauseAfterLoad | 255 concurrency = pauseAfterLoad |
214 ? 1 | 256 ? 1 |
215 : (concurrency == null ? _defaultConcurrency : concurrency), | 257 : (concurrency == null ? _defaultConcurrency : concurrency), |
216 platforms = platforms == null ? [TestPlatform.vm] : platforms.toList(), | 258 platforms = platforms == null ? [TestPlatform.vm] : platforms.toList(), |
217 paths = paths == null ? ["test"] : paths.toList(), | 259 paths = paths == null ? ["test"] : paths.toList(), |
218 explicitPaths = paths != null, | 260 explicitPaths = paths != null, |
219 this.tags = tags == null | 261 this.tags = tags, |
220 ? const <String>[] | 262 this.excludeTags = excludeTags; |
221 : tags; | |
222 } | 263 } |
OLD | NEW |