| 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 /// Collects the configurations for all status files in the 'tests' folder that | 5 /// Collects the configurations for all status files in the 'tests' folder that |
| 6 /// mention one of the test names given as argument. | 6 /// mention one of the test names given as argument. |
| 7 | 7 |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 import 'dart:math' hide log; | 9 import 'dart:math' hide log; |
| 10 import 'dart:io'; | 10 import 'dart:io'; |
| 11 | 11 |
| 12 import 'package:args/args.dart'; | 12 import 'package:args/args.dart'; |
| 13 import 'package:gardening/src/util.dart'; | 13 import 'package:gardening/src/util.dart'; |
| 14 | 14 |
| 15 void help(ArgParser argParser) { |
| 16 print('Prints all status-file entries for the given tests.'); |
| 17 print('The test-names must be a substring (or full match) of the lines in '); |
| 18 print('the status file. They can not be fully qualified'); |
| 19 print('Usage: status_summary [options] <test-name1> [<test-name2> ...]'); |
| 20 print('where options are:'); |
| 21 print(argParser.usage); |
| 22 } |
| 23 |
| 15 main(List<String> args) async { | 24 main(List<String> args) async { |
| 16 ArgParser argParser = createArgParser(); | 25 ArgParser argParser = createArgParser(); |
| 17 ArgResults argResults = argParser.parse(args); | 26 ArgResults argResults = argParser.parse(args); |
| 18 processArgResults(argResults); | 27 processArgResults(argResults); |
| 19 if (argResults.rest.length == 0) { | 28 if (argResults.rest.length == 0 || argResults['help']) { |
| 20 print('Usage: status_summary [options] <test-name1> [<test-name2> ...]'); | 29 help(argParser); |
| 21 print('where options are:'); | 30 if (argResults['help']) return; |
| 22 print(argParser.usage); | |
| 23 exit(1); | 31 exit(1); |
| 24 } | 32 } |
| 25 int maxStatusWidth = 0; | 33 int maxStatusWidth = 0; |
| 26 int maxConfigWidth = 0; | 34 int maxConfigWidth = 0; |
| 27 | 35 |
| 28 List<Uri> statusFiles = await findStatusFiles('tests'); | 36 Directory testDirectory = findTestDirectory('tests'); |
| 37 List<Uri> statusFiles = await findStatusFiles(testDirectory); |
| 38 Directory pkgDirectory = findTestDirectory('pkg'); |
| 39 statusFiles.addAll(await findStatusFiles(pkgDirectory)); |
| 29 Map<String, List<StatusFile>> statusMap = <String, List<StatusFile>>{}; | 40 Map<String, List<StatusFile>> statusMap = <String, List<StatusFile>>{}; |
| 30 for (Uri uri in statusFiles) { | 41 for (Uri uri in statusFiles) { |
| 31 Map<String, StatusFile> currentMap = <String, StatusFile>{}; | 42 Map<String, StatusFile> currentMap = <String, StatusFile>{}; |
| 32 log('Scanning $uri'); | 43 log('Scanning $uri'); |
| 33 String currentConfig = ''; | 44 String currentConfig = ''; |
| 34 for (String line in new File.fromUri(uri).readAsLinesSync()) { | 45 for (String line in new File.fromUri(uri).readAsLinesSync()) { |
| 35 if (line.startsWith('[')) { | 46 if (line.startsWith('[')) { |
| 36 currentConfig = line; | 47 currentConfig = line; |
| 37 } else { | 48 } else { |
| 38 int colonIndex = line.indexOf(':'); | 49 int colonIndex = line.indexOf(':'); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 for (StatusFile statusFile in statusFiles) { | 83 for (StatusFile statusFile in statusFiles) { |
| 73 print(' ${statusFile.uri}'); | 84 print(' ${statusFile.uri}'); |
| 74 statusFile.entries.forEach((StatusEntry entry) { | 85 statusFile.entries.forEach((StatusEntry entry) { |
| 75 print(' ${padRight(entry.status, maxStatusWidth)}' | 86 print(' ${padRight(entry.status, maxStatusWidth)}' |
| 76 ' ${padRight(entry.config, maxConfigWidth)} ${entry.comment}'); | 87 ' ${padRight(entry.config, maxConfigWidth)} ${entry.comment}'); |
| 77 }); | 88 }); |
| 78 } | 89 } |
| 79 }); | 90 }); |
| 80 } | 91 } |
| 81 | 92 |
| 93 /// Finds the test directory. |
| 94 /// |
| 95 /// First looks at a test-directory that is relative to the current |
| 96 Directory findTestDirectory(String directoryName) { |
| 97 var directory = new Directory(directoryName); |
| 98 if (directory.existsSync()) return directory; |
| 99 return new Directory.fromUri( |
| 100 Platform.script.resolve("../../../$directoryName")); |
| 101 } |
| 102 |
| 82 /// Returns the [Uri]s for all `.status` files in [path] and subdirectories. | 103 /// Returns the [Uri]s for all `.status` files in [path] and subdirectories. |
| 83 Future<List<Uri>> findStatusFiles(String path) async { | 104 Future<List<Uri>> findStatusFiles(Directory testDirectory) async { |
| 84 List<Uri> statusFiles = <Uri>[]; | 105 List<Uri> statusFiles = <Uri>[]; |
| 85 await for (FileSystemEntity entity | 106 await for (FileSystemEntity entity in testDirectory.list(recursive: true)) { |
| 86 in new Directory(path).list(recursive: true)) { | |
| 87 if (entity.path.endsWith('.status')) { | 107 if (entity.path.endsWith('.status')) { |
| 88 statusFiles.add(entity.uri); | 108 statusFiles.add(entity.uri); |
| 89 } | 109 } |
| 90 } | 110 } |
| 91 return statusFiles; | 111 return statusFiles; |
| 92 } | 112 } |
| 93 | 113 |
| 94 /// The entries collected for a single status file. | 114 /// The entries collected for a single status file. |
| 95 class StatusFile { | 115 class StatusFile { |
| 96 final Uri uri; | 116 final Uri uri; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 108 /// The status of the entry, e.g. `Pass, Slow`. | 128 /// The status of the entry, e.g. `Pass, Slow`. |
| 109 final String status; | 129 final String status; |
| 110 | 130 |
| 111 /// The comment after the status, if any. | 131 /// The comment after the status, if any. |
| 112 final String comment; | 132 final String comment; |
| 113 | 133 |
| 114 StatusEntry(this.config, this.status, this.comment); | 134 StatusEntry(this.config, this.status, this.comment); |
| 115 | 135 |
| 116 String toString() => '$status $config $comment'; | 136 String toString() => '$status $config $comment'; |
| 117 } | 137 } |
| OLD | NEW |