mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 00:13:50 +00:00
Make the static error updater gracefully skip multitests.
Multitests aren't valid Dart files that can be processed by a Dart implementation so the updater generally does a poor job if it tries to update one. It's probably not worth supporting because, in practice, a test should either be a multitest or a static error test, but not both. Change the tool to skip over any multitests it encounters. If this results in it doing nothing at all, it reports that as an error. Otherwise, it just lists the multitests it didn't process. Close #37721. Change-Id: Icfb1ff9fe63f2c249b3ccfba65166b97654a9918 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/296760 Commit-Queue: Leaf Petersen <leafp@google.com> Reviewed-by: Leaf Petersen <leafp@google.com> Auto-Submit: Bob Nystrom <rnystrom@google.com>
This commit is contained in:
parent
2a66f966f3
commit
b985fc961a
|
@ -76,7 +76,6 @@ bool _invalidVariableName(String keyword, {bool strictMode = true}) {
|
|||
switch (keyword) {
|
||||
// http://www.ecma-international.org/ecma-262/6.0/#sec-future-reserved-words
|
||||
case "await":
|
||||
|
||||
case "break":
|
||||
case "case":
|
||||
case "catch":
|
||||
|
|
|
@ -109,6 +109,9 @@ Future<void> main(List<String> args) async {
|
|||
parser, "Must provide at least one flag for an operation to perform.");
|
||||
}
|
||||
|
||||
var processedFiles = 0;
|
||||
var skippedMultitests = <String>[];
|
||||
|
||||
for (var result in results.rest) {
|
||||
// Allow tests to be specified without the extension for compatibility with
|
||||
// the regular test runner syntax.
|
||||
|
@ -124,13 +127,34 @@ Future<void> main(List<String> args) async {
|
|||
.listSync(root: root)
|
||||
.whereType<File>()
|
||||
.where((file) => file.path.endsWith('.dart'))) {
|
||||
await _processFile(
|
||||
var processed = await _processFile(
|
||||
entry,
|
||||
dryRun: dryRun,
|
||||
includeContext: includeContext,
|
||||
remove: removeSources,
|
||||
insert: insertSources,
|
||||
);
|
||||
|
||||
if (processed) {
|
||||
processedFiles++;
|
||||
} else {
|
||||
skippedMultitests.add(entry.path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (skippedMultitests.isNotEmpty) {
|
||||
// If no files were successfully processed, then the user is only pointing
|
||||
// it at multitests and made a mistake.
|
||||
if (processedFiles == 0) {
|
||||
stderr.writeln("Error: This tool doesn't support updating static errors "
|
||||
"in multitests. Couldn't update:");
|
||||
} else {
|
||||
stderr.writeln("Did not update the following multitests:");
|
||||
}
|
||||
|
||||
for (var multitest in skippedMultitests) {
|
||||
stderr.writeln(p.normalize(multitest));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -143,15 +167,25 @@ void _usageError(ArgParser parser, String message) {
|
|||
exit(64);
|
||||
}
|
||||
|
||||
Future<void> _processFile(File file,
|
||||
Future<bool> _processFile(File file,
|
||||
{required bool dryRun,
|
||||
required bool includeContext,
|
||||
required Set<ErrorSource> remove,
|
||||
required Set<ErrorSource> insert}) async {
|
||||
stdout.write("${file.path}...");
|
||||
var source = file.readAsStringSync();
|
||||
var testFile = TestFile.parse(Path("."), file.absolute.path, source);
|
||||
|
||||
// Don't process multitests. The multitest file isn't necessarily a valid or
|
||||
// meaningful Dart file that can be processed by front ends. To process them,
|
||||
// we'd have to split the multitest, run each separate file on the front ends,
|
||||
// and then try to merge the results back together.
|
||||
//
|
||||
// In practice, a test should either be a multitest or a static error test,
|
||||
// but not both.
|
||||
if (testFile.isMultitest) return false;
|
||||
|
||||
stdout.write("${file.path}...");
|
||||
|
||||
var experiments = [
|
||||
if (testFile.experiments.isNotEmpty) ...testFile.experiments
|
||||
];
|
||||
|
@ -202,6 +236,8 @@ Future<void> _processFile(File file,
|
|||
} else {
|
||||
await file.writeAsString(result);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Invoke analyzer on [file] and gather all static errors it reports.
|
||||
|
|
Loading…
Reference in a new issue