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

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

Issue 1604043003: Add support for a timeout flag. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Code review changes Created 4 years, 10 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
« no previous file with comments | « lib/src/frontend/timeout.dart ('k') | pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 import 'dart:io'; 5 import 'dart:io';
6 import 'dart:math' as math; 6 import 'dart:math' as math;
7 7
8 import 'package:args/args.dart'; 8 import 'package:args/args.dart';
9 import 'package:path/path.dart' as p; 9 import 'package:path/path.dart' as p;
10 10
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 defaultsTo: 'vm', 65 defaultsTo: 'vm',
66 allowMultiple: true); 66 allowMultiple: true);
67 parser.addOption("concurrency", 67 parser.addOption("concurrency",
68 abbr: 'j', 68 abbr: 'j',
69 help: 'The number of concurrent test suites run.\n' 69 help: 'The number of concurrent test suites run.\n'
70 '(defaults to $_defaultConcurrency)', 70 '(defaults to $_defaultConcurrency)',
71 valueHelp: 'threads'); 71 valueHelp: 'threads');
72 parser.addOption("pub-serve", 72 parser.addOption("pub-serve",
73 help: 'The port of a pub serve instance serving "test/".', 73 help: 'The port of a pub serve instance serving "test/".',
74 valueHelp: 'port'); 74 valueHelp: 'port');
75
76 // Note: although we list the 30s default timeout as though it were a
77 // default value for this argument, it's actually encoded in the [Invoker]'s
78 // call to [Timeout.apply].
79 parser.addOption("timeout",
80 help: 'The default test timeout. For example: 15s, 2x, none\n'
81 '(defaults to 30s)');
75 parser.addFlag("pause-after-load", 82 parser.addFlag("pause-after-load",
76 help: 'Pauses for debugging before any tests execute.\n' 83 help: 'Pauses for debugging before any tests execute.\n'
77 'Implies --concurrency=1.\n' 84 'Implies --concurrency=1 and --timeout=none.\n'
78 'Currently only supported for browser tests.', 85 'Currently only supported for browser tests.',
79 negatable: false); 86 negatable: false);
80 87
81 parser.addSeparator("======== Output"); 88 parser.addSeparator("======== Output");
82 parser.addOption("reporter", 89 parser.addOption("reporter",
83 abbr: 'r', 90 abbr: 'r',
84 help: 'The runner used to print test results.', 91 help: 'The runner used to print test results.',
85 allowed: ['compact', 'expanded', 'json'], 92 allowed: ['compact', 'expanded', 'json'],
86 defaultsTo: Platform.isWindows ? 'expanded' : 'compact', 93 defaultsTo: Platform.isWindows ? 'expanded' : 'compact',
87 allowedHelp: { 94 allowedHelp: {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 /// The package root for resolving "package:" URLs. 129 /// The package root for resolving "package:" URLs.
123 final String packageRoot; 130 final String packageRoot;
124 131
125 /// The name of the reporter to use to display results. 132 /// The name of the reporter to use to display results.
126 final String reporter; 133 final String reporter;
127 134
128 /// The URL for the `pub serve` instance from which to load tests, or `null` 135 /// The URL for the `pub serve` instance from which to load tests, or `null`
129 /// if tests should be loaded from the filesystem. 136 /// if tests should be loaded from the filesystem.
130 final Uri pubServeUrl; 137 final Uri pubServeUrl;
131 138
139 /// The default test timeout.
140 final Timeout timeout;
141
132 /// Whether to use command-line color escapes. 142 /// Whether to use command-line color escapes.
133 final bool color; 143 final bool color;
134 144
135 /// How many tests to run concurrently. 145 /// How many tests to run concurrently.
136 final int concurrency; 146 final int concurrency;
137 147
138 /// The from which to load tests. 148 /// The from which to load tests.
139 final List<String> paths; 149 final List<String> paths;
140 150
141 /// Whether the load paths were passed explicitly or the default was used. 151 /// Whether the load paths were passed explicitly or the default was used.
142 final bool explicitPaths; 152 final bool explicitPaths;
143 153
144 /// The pattern to match against test names to decide which to run, or `null` 154 /// The pattern to match against test names to decide which to run, or `null`
145 /// if all tests should be run. 155 /// if all tests should be run.
146 final Pattern pattern; 156 final Pattern pattern;
147 157
148 /// The set of platforms on which to run tests. 158 /// The set of platforms on which to run tests.
149 final List<TestPlatform> platforms; 159 final List<TestPlatform> platforms;
150 160
151 /// Restricts the set of tests to a set of tags 161 /// Restricts the set of tests to a set of tags
152 final Set<String> tags; 162 final Set<String> tags;
153 163
154 /// Does not run tests with tags from this set 164 /// Does not run tests with tags from this set
155 final Set<String> excludeTags; 165 final Set<String> excludeTags;
156 166
157 /// The global test metadata derived from this configuration. 167 /// The global test metadata derived from this configuration.
158 Metadata get metadata => 168 Metadata get metadata =>
159 new Metadata( 169 new Metadata(timeout: timeout, verboseTrace: verboseTrace);
160 timeout: pauseAfterLoad ? Timeout.none : null,
161 verboseTrace: verboseTrace);
162 170
163 /// Parses the configuration from [args]. 171 /// Parses the configuration from [args].
164 /// 172 ///
165 /// Throws a [FormatException] if [args] are invalid. 173 /// Throws a [FormatException] if [args] are invalid.
166 factory Configuration.parse(List<String> args) { 174 factory Configuration.parse(List<String> args) {
167 var options = _parser.parse(args); 175 var options = _parser.parse(args);
168 176
169 var pattern; 177 var pattern;
170 if (options['name'] != null) { 178 if (options['name'] != null) {
171 if (options["plain-name"] != null) { 179 if (options["plain-name"] != null) {
(...skipping 29 matching lines...) Expand all
201 version: options['version'], 209 version: options['version'],
202 verboseTrace: options['verbose-trace'], 210 verboseTrace: options['verbose-trace'],
203 jsTrace: options['js-trace'], 211 jsTrace: options['js-trace'],
204 pauseAfterLoad: options['pause-after-load'], 212 pauseAfterLoad: options['pause-after-load'],
205 color: options['color'], 213 color: options['color'],
206 packageRoot: options['package-root'], 214 packageRoot: options['package-root'],
207 reporter: options['reporter'], 215 reporter: options['reporter'],
208 pubServePort: _wrapFormatException(options, 'pub-serve', int.parse), 216 pubServePort: _wrapFormatException(options, 'pub-serve', int.parse),
209 concurrency: _wrapFormatException(options, 'concurrency', int.parse, 217 concurrency: _wrapFormatException(options, 'concurrency', int.parse,
210 orElse: () => _defaultConcurrency), 218 orElse: () => _defaultConcurrency),
219 timeout: _wrapFormatException(options, 'timeout',
220 (value) => new Timeout.parse(value),
221 orElse: () => new Timeout.factor(1)),
211 pattern: pattern, 222 pattern: pattern,
212 platforms: options['platform'].map(TestPlatform.find), 223 platforms: options['platform'].map(TestPlatform.find),
213 paths: options.rest.isEmpty ? null : options.rest, 224 paths: options.rest.isEmpty ? null : options.rest,
214 tags: tags, 225 tags: tags,
215 excludeTags: excludeTags); 226 excludeTags: excludeTags);
216 } 227 }
217 228
218 /// Runs [parse] on the value of the option [name], and wraps any 229 /// Runs [parse] on the value of the option [name], and wraps any
219 /// [FormatException] it throws with additional information. 230 /// [FormatException] it throws with additional information.
220 static _wrapFormatException(ArgResults options, String name, parse(value), 231 static _wrapFormatException(ArgResults options, String name, parse(value),
221 {orElse()}) { 232 {orElse()}) {
222 var value = options[name]; 233 var value = options[name];
223 if (value == null) return orElse == null ? null : orElse(); 234 if (value == null) return orElse == null ? null : orElse();
224 235
225 try { 236 try {
226 return parse(value); 237 return parse(value);
227 } on FormatException catch (error) { 238 } on FormatException catch (error) {
228 throw new FormatException('Couldn\'t parse --$name "${options[name]}": ' 239 throw new FormatException('Couldn\'t parse --$name "${options[name]}": '
229 '${error.message}'); 240 '${error.message}');
230 } 241 }
231 } 242 }
232 243
233 Configuration({this.help: false, this.version: false, 244 Configuration({this.help: false, this.version: false,
234 this.verboseTrace: false, this.jsTrace: false, 245 this.verboseTrace: false, this.jsTrace: false,
235 bool pauseAfterLoad: false, bool color, String packageRoot, 246 bool pauseAfterLoad: false, bool color, String packageRoot,
236 String reporter, int pubServePort, int concurrency, this.pattern, 247 String reporter, int pubServePort, int concurrency, Timeout timeout,
237 Iterable<TestPlatform> platforms, Iterable<String> paths, 248 this.pattern, Iterable<TestPlatform> platforms,
238 Set<String> tags, Set<String> excludeTags}) 249 Iterable<String> paths, Set<String> tags, Set<String> excludeTags})
239 : pauseAfterLoad = pauseAfterLoad, 250 : pauseAfterLoad = pauseAfterLoad,
240 color = color == null ? canUseSpecialChars : color, 251 color = color == null ? canUseSpecialChars : color,
241 packageRoot = packageRoot == null 252 packageRoot = packageRoot == null
242 ? p.join(p.current, 'packages') 253 ? p.join(p.current, 'packages')
243 : packageRoot, 254 : packageRoot,
244 reporter = reporter == null ? 'compact' : reporter, 255 reporter = reporter == null ? 'compact' : reporter,
245 pubServeUrl = pubServePort == null 256 pubServeUrl = pubServePort == null
246 ? null 257 ? null
247 : Uri.parse("http://localhost:$pubServePort"), 258 : Uri.parse("http://localhost:$pubServePort"),
248 concurrency = pauseAfterLoad 259 concurrency = pauseAfterLoad
249 ? 1 260 ? 1
250 : (concurrency == null ? _defaultConcurrency : concurrency), 261 : (concurrency == null ? _defaultConcurrency : concurrency),
262 timeout = pauseAfterLoad
263 ? Timeout.none
264 : (timeout == null ? new Timeout.factor(1) : timeout),
251 platforms = platforms == null ? [TestPlatform.vm] : platforms.toList(), 265 platforms = platforms == null ? [TestPlatform.vm] : platforms.toList(),
252 paths = paths == null ? ["test"] : paths.toList(), 266 paths = paths == null ? ["test"] : paths.toList(),
253 explicitPaths = paths != null, 267 explicitPaths = paths != null,
254 this.tags = tags, 268 this.tags = tags,
255 this.excludeTags = excludeTags; 269 this.excludeTags = excludeTags;
256 } 270 }
OLDNEW
« no previous file with comments | « lib/src/frontend/timeout.dart ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698