Chromium Code Reviews| Index: tests/compiler/dart2js/kernel/closed_world_tester.dart |
| diff --git a/tests/compiler/dart2js/kernel/closed_world_tester.dart b/tests/compiler/dart2js/kernel/closed_world_tester.dart |
| index aac7e5bc45bc959318b99f91252e1223665c32c4..37c946ef973e0959534096bb24c32c35ceee04b6 100644 |
| --- a/tests/compiler/dart2js/kernel/closed_world_tester.dart |
| +++ b/tests/compiler/dart2js/kernel/closed_world_tester.dart |
| @@ -8,33 +8,121 @@ |
| import 'dart:async'; |
| import 'dart:io'; |
| +import 'package:args/args.dart'; |
| import 'package:compiler/src/filenames.dart'; |
| import 'closed_world2_test.dart'; |
| +const String ERROR_MARKER = '---'; |
| + |
| main(List<String> args) async { |
| - for (String arg in args) { |
| + ArgParser parser = new ArgParser(); |
| + parser.addOption('log'); |
| + |
| + ArgResults argsResults = parser.parse(args); |
| + String logName = argsResults['log']; |
| + IOSink log; |
| + Map<String, Result> results; |
| + if (logName != null) { |
| + if (FileSystemEntity.isFileSync(logName)) { |
|
Siggi Cherem (dart-lang)
2017/04/28 22:30:38
consider moving this if to a helper function to na
Johnni Winther
2017/05/01 07:47:23
Done.
|
| + results = <String, Result>{}; |
| + String text = new File(logName).readAsStringSync(); |
| + new File('$logName~').writeAsStringSync(text); |
| + List<String> lines = text.split('\n'); |
| + int index = 0; |
| + while (index < lines.length) { |
| + String line = lines[index]; |
| + int colonPos = line.lastIndexOf(':'); |
| + if (colonPos == -1) { |
| + if (!line.isEmpty) { |
| + print('Invalid log line @ $index: $line'); |
| + } |
| + } else { |
| + String fileName = line.substring(0, colonPos); |
| + String kindName = line.substring(colonPos + 1).trim(); |
| + ResultKind kind = |
| + ResultKind.values.firstWhere((kind) => '$kind' == kindName); |
| + String error; |
| + if (kind == ResultKind.failure) { |
| + assert(lines[index + 1] == ERROR_MARKER); |
| + index += 2; |
| + StringBuffer sb = new StringBuffer(); |
| + while (lines[index] != ERROR_MARKER) { |
| + sb.writeln(lines[index]); |
| + index++; |
| + } |
| + error = sb.toString(); |
| + } |
| + results[fileName] = new Result(kind, error); |
| + } |
| + index++; |
| + } |
| + } |
| + log = new File(logName).openWrite(); |
| + } |
| + |
| + if (results != null) { |
| + for (String fileName in results.keys) { |
| + Result result = results[fileName]; |
| + if (result.kind == ResultKind.failure) { |
| + if (FileSystemEntity.isFileSync(fileName)) { |
| + await testFile(new File(fileName), log); |
| + } else { |
| + print("$fileName doesn't exist"); |
| + } |
| + } else { |
| + log?.writeln('${fileName}: ${result.kind}'); |
| + } |
| + } |
| + } |
| + |
| + for (String arg in argsResults.rest) { |
| String path = nativeToUriPath(arg); |
| if (FileSystemEntity.isDirectorySync(path)) { |
| Directory dir = new Directory(path); |
| for (FileSystemEntity file in dir.listSync(recursive: true)) { |
| if (file is File && file.path.endsWith('.dart')) { |
| - await testFile(file); |
| + if (results == null || !results.containsKey(file.path)) { |
| + await testFile(file, log); |
| + } |
| } |
| } |
| } else if (FileSystemEntity.isFileSync(path)) { |
| - await testFile(new File(path)); |
| + if (results == null || !results.containsKey(path)) { |
| + await testFile(new File(path), log); |
| + } |
| } else { |
| print("$arg doesn't exist"); |
| } |
| } |
| + |
| + await log?.close(); |
| } |
| -Future testFile(File file) async { |
| +Future testFile(File file, IOSink log) async { |
| print('===================================================================='); |
| print('testing ${file.path}'); |
| + ResultKind kind; |
| + String error; |
| try { |
| - await mainInternal([file.path], skipWarnings: true, skipErrors: true); |
| + kind = |
| + await mainInternal([file.path], skipWarnings: true, skipErrors: true); |
| } catch (e, s) { |
| - print('$e:\n$s'); |
| + kind = ResultKind.failure; |
| + error = '$e:\n$s'; |
| + print(error); |
| } |
| + log?.writeln('${file.path}: ${kind}'); |
| + if (error != null) { |
| + log?.writeln(ERROR_MARKER); |
| + log?.writeln(error); |
| + log?.writeln(ERROR_MARKER); |
| + } |
| + await log.flush(); |
| +} |
| + |
| +class Result { |
| + final ResultKind kind; |
| + final String error; |
| + |
| + Result(this.kind, [this.error]); |
| } |