@@ -22,10 +22,15 @@ import 'update_static_error_tests.dart' show runAnalyzer, runCfe;
22
22
23
23
Future <List <StaticError >> getErrors (
24
24
List <String > options, String filePath) async {
25
- return [
26
- ...await runAnalyzer (filePath, options),
27
- ...await runCfe (filePath, options)
28
- ];
25
+ var analyzerErrors = await runAnalyzer (filePath, options);
26
+ if (analyzerErrors == null ) {
27
+ exit (1 );
28
+ }
29
+ var cfeErrors = await runCfe (filePath, options);
30
+ if (cfeErrors == null ) {
31
+ exit (1 );
32
+ }
33
+ return [...analyzerErrors, ...cfeErrors];
29
34
}
30
35
31
36
bool areSameErrors (List <StaticError > first, List <StaticError > second) {
@@ -142,18 +147,8 @@ ${cleanedMultiTest.text}""";
142
147
}
143
148
}
144
149
145
- Future <void > main (List <String > arguments) async {
146
- var parser = ArgParser ();
147
- parser.addFlag ("verbose" , abbr: "v" , help: "print additional information" );
148
- parser.addFlag ("write" , abbr: "w" , help: "write output to input file" );
149
- var results = parser.parse (arguments);
150
- if (results.rest.length != 1 ) {
151
- print ("Usage: convert_multi_test.dart [-v] [-w] <input file>" );
152
- exitCode = 1 ;
153
- return ;
154
- }
155
- var verbose = results["verbose" ] as bool ;
156
- var testFilePath = Uri .base .resolve (results.rest.single).toFilePath ();
150
+ Future <void > convertFile (String testFilePath, bool writeToFile, bool verbose,
151
+ List <String > experiments) async {
157
152
var testFile = File (testFilePath);
158
153
if (! await testFile.exists ()) {
159
154
print ("File '${testFile .uri .toFilePath ()}' not found" );
@@ -190,6 +185,9 @@ Future<void> main(List<String> arguments) async {
190
185
// Get the reported errors for the multi-test and all generated sub-tests
191
186
// from the analyser and the common front-end.
192
187
var options = test.sharedOptions;
188
+ if (experiments.isNotEmpty) {
189
+ options.add ("--enable-experiment=${experiments .join (',' )}" );
190
+ }
193
191
var errors = < List <StaticError >> [];
194
192
for (var test in tests) {
195
193
if (verbose) {
@@ -198,7 +196,7 @@ Future<void> main(List<String> arguments) async {
198
196
errors.add (await getErrors (options, test.path.toNativePath ()));
199
197
}
200
198
if (errors[1 ].isNotEmpty) {
201
- throw "internal error: errors in '/none' test" ;
199
+ throw UnableToConvertException ( "internal error: errors in '/none' test" ) ;
202
200
}
203
201
// Check that the multi-test generates the same errors as all sub-tests
204
202
// together - otherwise converting the test would be unsound.
@@ -217,7 +215,6 @@ Future<void> main(List<String> arguments) async {
217
215
// and output the result.
218
216
var annotatedContent =
219
217
updateErrorExpectations (contentWithoutMarkers, errors[0 ]);
220
- var writeToFile = results["write" ] as bool ;
221
218
if (writeToFile) {
222
219
await testFile.writeAsString (annotatedContent);
223
220
print ("Converted test '${test .path .toNativePath ()}'." );
@@ -245,3 +242,27 @@ Future<void> main(List<String> arguments) async {
245
242
outputDirectory.delete (recursive: true );
246
243
}
247
244
}
245
+
246
+ Future <void > main (List <String > arguments) async {
247
+ var parser = ArgParser ();
248
+ parser.addFlag ("verbose" , abbr: "v" , help: "print additional information" );
249
+ parser.addFlag ("write" , abbr: "w" , help: "write output to input file" );
250
+ parser.addOption ("enable-experiment" ,
251
+ help: "Enable one or more experimental features" , allowMultiple: true );
252
+
253
+ var results = parser.parse (arguments);
254
+ if (results.rest.isEmpty) {
255
+ print ("Usage: convert_multi_test.dart [-v] [-w] <input files>" );
256
+ print (parser.getUsage ());
257
+ exitCode = 1 ;
258
+ return ;
259
+ }
260
+ var verbose = results["verbose" ] as bool ;
261
+ var filePaths =
262
+ results.rest.map ((path) => Uri .base .resolve (path).toFilePath ());
263
+ var writeToFile = results["write" ] as bool ;
264
+ for (var testFilePath in filePaths) {
265
+ await convertFile (testFilePath, writeToFile, verbose,
266
+ (results["enable-experiment" ] as List ).cast <String >());
267
+ }
268
+ }
0 commit comments