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

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

Issue 1802133002: Add names and plain_names fields. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Code review changes Created 4 years, 9 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/runner/configuration.dart ('k') | lib/src/runner/configuration/load.dart » ('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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 6
7 import 'package:args/args.dart'; 7 import 'package:args/args.dart';
8 import 'package:boolean_selector/boolean_selector.dart'; 8 import 'package:boolean_selector/boolean_selector.dart';
9 9
10 import '../../backend/test_platform.dart'; 10 import '../../backend/test_platform.dart';
(...skipping 16 matching lines...) Expand all
27 parser.addOption("package-root", hide: true); 27 parser.addOption("package-root", hide: true);
28 28
29 // Note that defaultsTo declarations here are only for documentation purposes. 29 // Note that defaultsTo declarations here are only for documentation purposes.
30 // We pass null values rather than defaults to [new Configuration] so that it 30 // We pass null values rather than defaults to [new Configuration] so that it
31 // merges properly with the config file. 31 // merges properly with the config file.
32 32
33 parser.addSeparator("======== Selecting Tests"); 33 parser.addSeparator("======== Selecting Tests");
34 parser.addOption("name", 34 parser.addOption("name",
35 abbr: 'n', 35 abbr: 'n',
36 help: 'A substring of the name of the test to run.\n' 36 help: 'A substring of the name of the test to run.\n'
37 'Regular expression syntax is supported.'); 37 'Regular expression syntax is supported.\n'
38 'If passed multiple times, tests must match all substrings.',
39 allowMultiple: true,
40 splitCommas: false);
38 parser.addOption("plain-name", 41 parser.addOption("plain-name",
39 abbr: 'N', 42 abbr: 'N',
40 help: 'A plain-text substring of the name of the test to run.'); 43 help: 'A plain-text substring of the name of the test to run.\n'
41 // TODO(nweiz): Support the full platform-selector syntax for choosing which 44 'If passed multiple times, tests must match all substrings.',
42 // tags to run. In the shorter term, disallow non-"identifier" tags. 45 allowMultiple: true,
46 splitCommas: false);
43 parser.addOption("tags", 47 parser.addOption("tags",
44 abbr: 't', 48 abbr: 't',
45 help: 'Run only tests with all of the specified tags.\n' 49 help: 'Run only tests with all of the specified tags.\n'
46 'Supports boolean selector syntax.', 50 'Supports boolean selector syntax.',
47 allowMultiple: true); 51 allowMultiple: true);
48 parser.addOption("tag", hide: true, allowMultiple: true); 52 parser.addOption("tag", hide: true, allowMultiple: true);
49 parser.addOption("exclude-tags", 53 parser.addOption("exclude-tags",
50 abbr: 'x', 54 abbr: 'x',
51 help: "Don't run tests with any of the specified tags.\n" 55 help: "Don't run tests with any of the specified tags.\n"
52 "Supports boolean selector syntax.", 56 "Supports boolean selector syntax.",
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 108
105 /// The usage string for the command-line arguments. 109 /// The usage string for the command-line arguments.
106 String get usage => _parser.usage; 110 String get usage => _parser.usage;
107 111
108 /// Parses the configuration from [args]. 112 /// Parses the configuration from [args].
109 /// 113 ///
110 /// Throws a [FormatException] if [args] are invalid. 114 /// Throws a [FormatException] if [args] are invalid.
111 Configuration parse(List<String> args) { 115 Configuration parse(List<String> args) {
112 var options = _parser.parse(args); 116 var options = _parser.parse(args);
113 117
114 var pattern; 118 var patterns = options['name']
115 if (options['name'] != null) { 119 .map((value) => _wrapFormatException('name', () => new RegExp(value)))
116 if (options["plain-name"] != null) { 120 .toList()
117 throw new FormatException( 121 ..addAll(options['plain-name']);
118 "--name and --plain-name may not both be passed.");
119 }
120
121 pattern = _wrapFormatException(
122 options, 'name', (value) => new RegExp(value));
123 } else if (options['plain-name'] != null) {
124 pattern = options['plain-name'];
125 }
126 122
127 var includeTagSet = new Set.from(options['tags'] ?? []) 123 var includeTagSet = new Set.from(options['tags'] ?? [])
128 ..addAll(options['tag'] ?? []); 124 ..addAll(options['tag'] ?? []);
129 125
130 var includeTags = includeTagSet.fold(BooleanSelector.all, (selector, tag) { 126 var includeTags = includeTagSet.fold(BooleanSelector.all, (selector, tag) {
131 var tagSelector = new BooleanSelector.parse(tag); 127 var tagSelector = new BooleanSelector.parse(tag);
132 return selector.intersection(tagSelector); 128 return selector.intersection(tagSelector);
133 }); 129 });
134 130
135 var excludeTagSet = new Set.from(options['exclude-tags'] ?? []) 131 var excludeTagSet = new Set.from(options['exclude-tags'] ?? [])
(...skipping 11 matching lines...) Expand all
147 143
148 return new Configuration( 144 return new Configuration(
149 help: ifParsed('help'), 145 help: ifParsed('help'),
150 version: ifParsed('version'), 146 version: ifParsed('version'),
151 verboseTrace: ifParsed('verbose-trace'), 147 verboseTrace: ifParsed('verbose-trace'),
152 jsTrace: ifParsed('js-trace'), 148 jsTrace: ifParsed('js-trace'),
153 pauseAfterLoad: ifParsed('pause-after-load'), 149 pauseAfterLoad: ifParsed('pause-after-load'),
154 color: ifParsed('color'), 150 color: ifParsed('color'),
155 packageRoot: ifParsed('package-root'), 151 packageRoot: ifParsed('package-root'),
156 reporter: ifParsed('reporter'), 152 reporter: ifParsed('reporter'),
157 pubServePort: _wrapFormatException(options, 'pub-serve', int.parse), 153 pubServePort: _parseOption(options, 'pub-serve', int.parse),
158 concurrency: _wrapFormatException(options, 'concurrency', int.parse), 154 concurrency: _parseOption(options, 'concurrency', int.parse),
159 timeout: _wrapFormatException(options, 'timeout', 155 timeout: _parseOption(options, 'timeout',
160 (value) => new Timeout.parse(value)), 156 (value) => new Timeout.parse(value)),
161 pattern: pattern, 157 patterns: patterns,
162 platforms: ifParsed('platform')?.map(TestPlatform.find), 158 platforms: ifParsed('platform')?.map(TestPlatform.find),
163 chosenPresets: ifParsed('preset'), 159 chosenPresets: ifParsed('preset'),
164 paths: options.rest.isEmpty ? null : options.rest, 160 paths: options.rest.isEmpty ? null : options.rest,
165 includeTags: includeTags, 161 includeTags: includeTags,
166 excludeTags: excludeTags); 162 excludeTags: excludeTags);
167 } 163 }
168 164
169 /// Runs [parse] on the value of the option [name], and wraps any 165 /// Runs [parse] on the value of the option [name], and wraps any
170 /// [FormatException] it throws with additional information. 166 /// [FormatException] it throws with additional information.
171 _wrapFormatException(ArgResults options, String name, parse(value)) { 167 _parseOption(ArgResults options, String name, parse(value)) {
172 if (!options.wasParsed(name)) return null; 168 if (!options.wasParsed(name)) return null;
173 169
174 var value = options[name]; 170 var value = options[name];
175 if (value == null) return null; 171 if (value == null) return null;
176 172
173 return _wrapFormatException(name, () => parse(value));
174 }
175
176 /// Runs [parse], and wraps any [FormatException] it throws with additional
177 /// information.
178 _wrapFormatException(String name, parse()) {
177 try { 179 try {
178 return parse(value); 180 return parse();
179 } on FormatException catch (error) { 181 } on FormatException catch (error) {
180 throw new FormatException('Couldn\'t parse --$name "${options[name]}": ' 182 throw new FormatException('Couldn\'t parse --$name "${options[name]}": '
181 '${error.message}'); 183 '${error.message}');
182 } 184 }
183 } 185 }
OLDNEW
« no previous file with comments | « lib/src/runner/configuration.dart ('k') | lib/src/runner/configuration/load.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698