OLD | NEW |
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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 valueHelp: 'port'); | 78 valueHelp: 'port'); |
79 parser.addOption("timeout", | 79 parser.addOption("timeout", |
80 help: 'The default test timeout. For example: 15s, 2x, none', | 80 help: 'The default test timeout. For example: 15s, 2x, none', |
81 defaultsTo: '30s'); | 81 defaultsTo: '30s'); |
82 parser.addFlag("pause-after-load", | 82 parser.addFlag("pause-after-load", |
83 help: 'Pauses for debugging before any tests execute.\n' | 83 help: 'Pauses for debugging before any tests execute.\n' |
84 'Implies --concurrency=1 and --timeout=none.\n' | 84 'Implies --concurrency=1 and --timeout=none.\n' |
85 'Currently only supported for browser tests.', | 85 'Currently only supported for browser tests.', |
86 negatable: false); | 86 negatable: false); |
87 | 87 |
| 88 // These are used by the internal Google test runner, so they're hidden from |
| 89 // the --help output but still supported as stable API surface. See |
| 90 // [Configuration.shardIndex] for details on their semantics. |
| 91 parser.addOption("shard-index", hide: true); |
| 92 parser.addOption("total-shards", hide: true); |
| 93 |
88 parser.addSeparator("======== Output"); | 94 parser.addSeparator("======== Output"); |
89 parser.addOption("reporter", | 95 parser.addOption("reporter", |
90 abbr: 'r', | 96 abbr: 'r', |
91 help: 'The runner used to print test results.', | 97 help: 'The runner used to print test results.', |
92 defaultsTo: defaultReporter, | 98 defaultsTo: defaultReporter, |
93 allowed: allReporters, | 99 allowed: allReporters, |
94 allowedHelp: { | 100 allowedHelp: { |
95 'compact': 'A single line, updated continuously.', | 101 'compact': 'A single line, updated continuously.', |
96 'expanded': 'A separate line for each update.', | 102 'expanded': 'A separate line for each update.', |
97 'json': 'A machine-readable format (see https://goo.gl/0HRhdZ).' | 103 'json': 'A machine-readable format (see https://goo.gl/0HRhdZ).' |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 }); | 145 }); |
140 | 146 |
141 var excludeTagSet = new Set.from(_options['exclude-tags'] ?? []) | 147 var excludeTagSet = new Set.from(_options['exclude-tags'] ?? []) |
142 ..addAll(_options['exclude-tag'] ?? []); | 148 ..addAll(_options['exclude-tag'] ?? []); |
143 | 149 |
144 var excludeTags = excludeTagSet.fold(BooleanSelector.none, (selector, tag) { | 150 var excludeTags = excludeTagSet.fold(BooleanSelector.none, (selector, tag) { |
145 var tagSelector = new BooleanSelector.parse(tag); | 151 var tagSelector = new BooleanSelector.parse(tag); |
146 return selector.union(tagSelector); | 152 return selector.union(tagSelector); |
147 }); | 153 }); |
148 | 154 |
| 155 var shardIndex = _parseOption('shard-index', int.parse); |
| 156 var totalShards = _parseOption('total-shards', int.parse); |
| 157 if ((shardIndex == null) != (totalShards == null)) { |
| 158 throw new FormatException( |
| 159 "--shard-index and --total-shards may only be passed together."); |
| 160 } else if (shardIndex != null) { |
| 161 if (shardIndex < 0) { |
| 162 throw new FormatException("--shard-index may not be negative."); |
| 163 } else if (shardIndex >= totalShards) { |
| 164 throw new FormatException( |
| 165 "--shard-index must be less than --total-shards."); |
| 166 } |
| 167 } |
| 168 |
149 return new Configuration( | 169 return new Configuration( |
150 help: _ifParsed('help'), | 170 help: _ifParsed('help'), |
151 version: _ifParsed('version'), | 171 version: _ifParsed('version'), |
152 verboseTrace: _ifParsed('verbose-trace'), | 172 verboseTrace: _ifParsed('verbose-trace'), |
153 jsTrace: _ifParsed('js-trace'), | 173 jsTrace: _ifParsed('js-trace'), |
154 pauseAfterLoad: _ifParsed('pause-after-load'), | 174 pauseAfterLoad: _ifParsed('pause-after-load'), |
155 color: _ifParsed('color'), | 175 color: _ifParsed('color'), |
156 packageRoot: _ifParsed('package-root'), | 176 packageRoot: _ifParsed('package-root'), |
157 reporter: _ifParsed('reporter'), | 177 reporter: _ifParsed('reporter'), |
158 pubServePort: _parseOption('pub-serve', int.parse), | 178 pubServePort: _parseOption('pub-serve', int.parse), |
159 concurrency: _parseOption('concurrency', int.parse), | 179 concurrency: _parseOption('concurrency', int.parse), |
| 180 shardIndex: shardIndex, |
| 181 totalShards: totalShards, |
160 timeout: _parseOption('timeout', (value) => new Timeout.parse(value)), | 182 timeout: _parseOption('timeout', (value) => new Timeout.parse(value)), |
161 patterns: patterns, | 183 patterns: patterns, |
162 platforms: _ifParsed('platform')?.map(TestPlatform.find), | 184 platforms: _ifParsed('platform')?.map(TestPlatform.find), |
163 chosenPresets: _ifParsed('preset'), | 185 chosenPresets: _ifParsed('preset'), |
164 paths: _options.rest.isEmpty ? null : _options.rest, | 186 paths: _options.rest.isEmpty ? null : _options.rest, |
165 includeTags: includeTags, | 187 includeTags: includeTags, |
166 excludeTags: excludeTags); | 188 excludeTags: excludeTags); |
167 } | 189 } |
168 | 190 |
169 /// Returns the parsed option for [name], or `null` if none was parsed. | 191 /// Returns the parsed option for [name], or `null` if none was parsed. |
(...skipping 18 matching lines...) Expand all Loading... |
188 /// information. | 210 /// information. |
189 _wrapFormatException(String name, parse()) { | 211 _wrapFormatException(String name, parse()) { |
190 try { | 212 try { |
191 return parse(); | 213 return parse(); |
192 } on FormatException catch (error) { | 214 } on FormatException catch (error) { |
193 throw new FormatException('Couldn\'t parse --$name "${_options[name]}": ' | 215 throw new FormatException('Couldn\'t parse --$name "${_options[name]}": ' |
194 '${error.message}'); | 216 '${error.message}'); |
195 } | 217 } |
196 } | 218 } |
197 } | 219 } |
OLD | NEW |