Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 /// Helper application to run `closed_world2_test` on multiple files or | 5 /// Helper application to run `closed_world2_test` on multiple files or |
| 6 /// directories. | 6 /// directories. |
| 7 | 7 |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 import 'dart:io'; | 9 import 'dart:io'; |
| 10 | 10 |
| 11 import 'package:args/args.dart'; | |
| 11 import 'package:compiler/src/filenames.dart'; | 12 import 'package:compiler/src/filenames.dart'; |
| 12 import 'closed_world2_test.dart'; | 13 import 'closed_world2_test.dart'; |
| 13 | 14 |
| 15 const String ERROR_MARKER = '---'; | |
| 16 | |
| 14 main(List<String> args) async { | 17 main(List<String> args) async { |
| 15 for (String arg in args) { | 18 ArgParser parser = new ArgParser(); |
| 19 parser.addOption('log'); | |
| 20 | |
| 21 ArgResults argsResults = parser.parse(args); | |
| 22 String logName = argsResults['log']; | |
| 23 IOSink log; | |
| 24 Map<String, Result> results; | |
| 25 if (logName != null) { | |
| 26 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.
| |
| 27 results = <String, Result>{}; | |
| 28 String text = new File(logName).readAsStringSync(); | |
| 29 new File('$logName~').writeAsStringSync(text); | |
| 30 List<String> lines = text.split('\n'); | |
| 31 int index = 0; | |
| 32 while (index < lines.length) { | |
| 33 String line = lines[index]; | |
| 34 int colonPos = line.lastIndexOf(':'); | |
| 35 if (colonPos == -1) { | |
| 36 if (!line.isEmpty) { | |
| 37 print('Invalid log line @ $index: $line'); | |
| 38 } | |
| 39 } else { | |
| 40 String fileName = line.substring(0, colonPos); | |
| 41 String kindName = line.substring(colonPos + 1).trim(); | |
| 42 ResultKind kind = | |
| 43 ResultKind.values.firstWhere((kind) => '$kind' == kindName); | |
| 44 String error; | |
| 45 if (kind == ResultKind.failure) { | |
| 46 assert(lines[index + 1] == ERROR_MARKER); | |
| 47 index += 2; | |
| 48 StringBuffer sb = new StringBuffer(); | |
| 49 while (lines[index] != ERROR_MARKER) { | |
| 50 sb.writeln(lines[index]); | |
| 51 index++; | |
| 52 } | |
| 53 error = sb.toString(); | |
| 54 } | |
| 55 results[fileName] = new Result(kind, error); | |
| 56 } | |
| 57 index++; | |
| 58 } | |
| 59 } | |
| 60 log = new File(logName).openWrite(); | |
| 61 } | |
| 62 | |
| 63 if (results != null) { | |
| 64 for (String fileName in results.keys) { | |
| 65 Result result = results[fileName]; | |
| 66 if (result.kind == ResultKind.failure) { | |
| 67 if (FileSystemEntity.isFileSync(fileName)) { | |
| 68 await testFile(new File(fileName), log); | |
| 69 } else { | |
| 70 print("$fileName doesn't exist"); | |
| 71 } | |
| 72 } else { | |
| 73 log?.writeln('${fileName}: ${result.kind}'); | |
| 74 } | |
| 75 } | |
| 76 } | |
| 77 | |
| 78 for (String arg in argsResults.rest) { | |
| 16 String path = nativeToUriPath(arg); | 79 String path = nativeToUriPath(arg); |
| 17 if (FileSystemEntity.isDirectorySync(path)) { | 80 if (FileSystemEntity.isDirectorySync(path)) { |
| 18 Directory dir = new Directory(path); | 81 Directory dir = new Directory(path); |
| 19 for (FileSystemEntity file in dir.listSync(recursive: true)) { | 82 for (FileSystemEntity file in dir.listSync(recursive: true)) { |
| 20 if (file is File && file.path.endsWith('.dart')) { | 83 if (file is File && file.path.endsWith('.dart')) { |
| 21 await testFile(file); | 84 if (results == null || !results.containsKey(file.path)) { |
| 85 await testFile(file, log); | |
| 86 } | |
| 22 } | 87 } |
| 23 } | 88 } |
| 24 } else if (FileSystemEntity.isFileSync(path)) { | 89 } else if (FileSystemEntity.isFileSync(path)) { |
| 25 await testFile(new File(path)); | 90 if (results == null || !results.containsKey(path)) { |
| 91 await testFile(new File(path), log); | |
| 92 } | |
| 26 } else { | 93 } else { |
| 27 print("$arg doesn't exist"); | 94 print("$arg doesn't exist"); |
| 28 } | 95 } |
| 29 } | 96 } |
| 97 | |
| 98 await log?.close(); | |
| 30 } | 99 } |
| 31 | 100 |
| 32 Future testFile(File file) async { | 101 Future testFile(File file, IOSink log) async { |
| 33 print('===================================================================='); | 102 print('===================================================================='); |
| 34 print('testing ${file.path}'); | 103 print('testing ${file.path}'); |
| 104 ResultKind kind; | |
| 105 String error; | |
| 35 try { | 106 try { |
| 36 await mainInternal([file.path], skipWarnings: true, skipErrors: true); | 107 kind = |
| 108 await mainInternal([file.path], skipWarnings: true, skipErrors: true); | |
| 37 } catch (e, s) { | 109 } catch (e, s) { |
| 38 print('$e:\n$s'); | 110 kind = ResultKind.failure; |
| 111 error = '$e:\n$s'; | |
| 112 print(error); | |
| 39 } | 113 } |
| 114 log?.writeln('${file.path}: ${kind}'); | |
| 115 if (error != null) { | |
| 116 log?.writeln(ERROR_MARKER); | |
| 117 log?.writeln(error); | |
| 118 log?.writeln(ERROR_MARKER); | |
| 119 } | |
| 120 await log.flush(); | |
| 40 } | 121 } |
| 122 | |
| 123 class Result { | |
| 124 final ResultKind kind; | |
| 125 final String error; | |
| 126 | |
| 127 Result(this.kind, [this.error]); | |
| 128 } | |
| OLD | NEW |