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

Side by Side Diff: lib/src/runner/configuration.dart

Issue 1405633004: feature: tag tests; choose tags on command line Base URL: git@github.com:yjbanov/test.git@tags
Patch Set: Created 5 years, 2 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
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 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 allowedHelp: { 70 allowedHelp: {
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",
nweiz 2015/10/13 23:28:12 Add a "t" abbreviation, too.
yjbanov 2015/10/30 20:14:00 Done.
81 help: 'Comma-separated list of tags to run',
82 allowMultiple: true,
83 splitCommas: true);
80 84
nweiz 2015/10/13 23:28:12 Add a hidden --tag flag too, to help prevent frust
yjbanov 2015/10/30 20:13:59 Done.
81 return parser; 85 return parser;
82 })(); 86 })();
83 87
84 /// The usage string for the command-line arguments. 88 /// The usage string for the command-line arguments.
85 static String get usage => _parser.usage; 89 static String get usage => _parser.usage;
86 90
87 /// Whether `--help` was passed. 91 /// Whether `--help` was passed.
88 final bool help; 92 final bool help;
89 93
90 /// Whether `--version` was passed. 94 /// Whether `--version` was passed.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 /// Whether the load paths were passed explicitly or the default was used. 127 /// Whether the load paths were passed explicitly or the default was used.
124 final bool explicitPaths; 128 final bool explicitPaths;
125 129
126 /// The pattern to match against test names to decide which to run, or `null` 130 /// The pattern to match against test names to decide which to run, or `null`
127 /// if all tests should be run. 131 /// if all tests should be run.
128 final Pattern pattern; 132 final Pattern pattern;
129 133
130 /// The set of platforms on which to run tests. 134 /// The set of platforms on which to run tests.
131 final List<TestPlatform> platforms; 135 final List<TestPlatform> platforms;
132 136
137 /// Restricts the set of tests to a set of tags
138 final List<String> tags;
139
133 /// The global test metadata derived from this configuration. 140 /// The global test metadata derived from this configuration.
134 Metadata get metadata => 141 Metadata get metadata =>
135 new Metadata( 142 new Metadata(
136 timeout: pauseAfterLoad ? Timeout.none : null, 143 timeout: pauseAfterLoad ? Timeout.none : null,
137 verboseTrace: verboseTrace); 144 verboseTrace: verboseTrace);
138 145
139 /// Parses the configuration from [args]. 146 /// Parses the configuration from [args].
140 /// 147 ///
141 /// Throws a [FormatException] if [args] are invalid. 148 /// Throws a [FormatException] if [args] are invalid.
142 factory Configuration.parse(List<String> args) { 149 factory Configuration.parse(List<String> args) {
(...skipping 19 matching lines...) Expand all
162 jsTrace: options['js-trace'], 169 jsTrace: options['js-trace'],
163 pauseAfterLoad: options['pause-after-load'], 170 pauseAfterLoad: options['pause-after-load'],
164 color: options['color'], 171 color: options['color'],
165 packageRoot: options['package-root'], 172 packageRoot: options['package-root'],
166 reporter: options['reporter'], 173 reporter: options['reporter'],
167 pubServePort: _wrapFormatException(options, 'pub-serve', int.parse), 174 pubServePort: _wrapFormatException(options, 'pub-serve', int.parse),
168 concurrency: _wrapFormatException(options, 'concurrency', int.parse, 175 concurrency: _wrapFormatException(options, 'concurrency', int.parse,
169 orElse: () => _defaultConcurrency), 176 orElse: () => _defaultConcurrency),
170 pattern: pattern, 177 pattern: pattern,
171 platforms: options['platform'].map(TestPlatform.find), 178 platforms: options['platform'].map(TestPlatform.find),
172 paths: options.rest.isEmpty ? null : options.rest); 179 paths: options.rest.isEmpty ? null : options.rest,
180 tags: options['tags']);
173 } 181 }
174 182
175 /// Runs [parse] on the value of the option [name], and wraps any 183 /// Runs [parse] on the value of the option [name], and wraps any
176 /// [FormatException] it throws with additional information. 184 /// [FormatException] it throws with additional information.
177 static _wrapFormatException(ArgResults options, String name, parse(value), 185 static _wrapFormatException(ArgResults options, String name, parse(value),
178 {orElse()}) { 186 {orElse()}) {
179 var value = options[name]; 187 var value = options[name];
180 if (value == null) return orElse == null ? null : orElse(); 188 if (value == null) return orElse == null ? null : orElse();
181 189
182 try { 190 try {
183 return parse(value); 191 return parse(value);
184 } on FormatException catch (error) { 192 } on FormatException catch (error) {
185 throw new FormatException('Couldn\'t parse --$name "${options[name]}": ' 193 throw new FormatException('Couldn\'t parse --$name "${options[name]}": '
186 '${error.message}'); 194 '${error.message}');
187 } 195 }
188 } 196 }
189 197
190 Configuration({this.help: false, this.version: false, 198 Configuration({this.help: false, this.version: false,
191 this.verboseTrace: false, this.jsTrace: false, 199 this.verboseTrace: false, this.jsTrace: false,
192 bool pauseAfterLoad: false, bool color, String packageRoot, 200 bool pauseAfterLoad: false, bool color, String packageRoot,
193 String reporter, int pubServePort, int concurrency, this.pattern, 201 String reporter, int pubServePort, int concurrency, this.pattern,
194 Iterable<TestPlatform> platforms, Iterable<String> paths}) 202 Iterable<TestPlatform> platforms, Iterable<String> paths,
203 List<String> tags})
195 : pauseAfterLoad = pauseAfterLoad, 204 : pauseAfterLoad = pauseAfterLoad,
196 color = color == null ? canUseSpecialChars : color, 205 color = color == null ? canUseSpecialChars : color,
197 packageRoot = packageRoot == null 206 packageRoot = packageRoot == null
198 ? p.join(p.current, 'packages') 207 ? p.join(p.current, 'packages')
199 : packageRoot, 208 : packageRoot,
200 reporter = reporter == null ? 'compact' : reporter, 209 reporter = reporter == null ? 'compact' : reporter,
201 pubServeUrl = pubServePort == null 210 pubServeUrl = pubServePort == null
202 ? null 211 ? null
203 : Uri.parse("http://localhost:$pubServePort"), 212 : Uri.parse("http://localhost:$pubServePort"),
204 concurrency = pauseAfterLoad 213 concurrency = pauseAfterLoad
205 ? 1 214 ? 1
206 : (concurrency == null ? _defaultConcurrency : concurrency), 215 : (concurrency == null ? _defaultConcurrency : concurrency),
207 platforms = platforms == null ? [TestPlatform.vm] : platforms.toList(), 216 platforms = platforms == null ? [TestPlatform.vm] : platforms.toList(),
208 paths = paths == null ? ["test"] : paths.toList(), 217 paths = paths == null ? ["test"] : paths.toList(),
209 explicitPaths = paths != null; 218 explicitPaths = paths != null,
219 this.tags = tags == null
220 ? const <String>[]
221 : tags;
210 } 222 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698