OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 /// Collects the configurations for all status files in the 'tests' folder that | |
6 /// mention one of the test names given as argument. | |
7 | |
8 import 'dart:async'; | |
9 import 'dart:math' hide log; | |
10 import 'dart:io'; | |
11 | |
12 import 'src/util.dart'; | |
13 | |
14 main(List<String> args) async { | |
15 if (args.length == 0) { | |
16 print('Usage: status_summary <test-name1> [<test-name2> ...]'); | |
17 exit(1); | |
18 } | |
19 int maxStatusWidth = 0; | |
20 int maxConfigWidth = 0; | |
21 | |
22 List<Uri> statusFiles = await findStatusFiles('tests'); | |
23 Map<String, List<StatusFile>> statusMap = <String, List<StatusFile>>{}; | |
24 for (Uri uri in statusFiles) { | |
25 Map<String, StatusFile> currentMap = <String, StatusFile>{}; | |
26 log('Scanning $uri'); | |
27 String currentConfig = ''; | |
28 for (String line in new File.fromUri(uri).readAsLinesSync()) { | |
29 if (line.startsWith('[')) { | |
30 currentConfig = line; | |
31 } else { | |
32 int colonIndex = line.indexOf(':'); | |
33 if (colonIndex != -1) { | |
34 String testName = line.substring(0, colonIndex).trim(); | |
35 int hashIndex = line.indexOf('#', colonIndex + 1); | |
36 String status; | |
37 String comment; | |
38 if (hashIndex != -1) { | |
39 status = line.substring(colonIndex + 1, hashIndex).trim(); | |
40 comment = line.substring(hashIndex + 1).trim(); | |
41 } else { | |
42 status = line.substring(colonIndex + 1).trim(); | |
43 comment = ''; | |
44 } | |
45 | |
46 for (String arg in args) { | |
47 if (testName.contains(arg) || arg.contains(testName)) { | |
karlklose
2017/03/15 14:06:25
Use startsWith like above?
Johnni Winther
2017/03/15 14:32:17
That wouldn't support test names that include the
| |
48 StatusFile statusFile = | |
49 currentMap.putIfAbsent(testName, () => new StatusFile(uri)); | |
50 statusFile.entries | |
51 .add(new StatusEntry(currentConfig, status, comment)); | |
52 | |
53 maxStatusWidth = max(maxStatusWidth, status.length); | |
54 maxConfigWidth = max(maxConfigWidth, currentConfig.length); | |
55 } | |
56 } | |
57 } | |
58 } | |
59 } | |
60 currentMap.forEach((String testName, StatusFile configFile) { | |
61 statusMap.putIfAbsent(testName, () => <StatusFile>[]).add(configFile); | |
62 }); | |
63 } | |
64 statusMap.forEach((String arg, List<StatusFile> statusFiles) { | |
65 print('$arg'); | |
66 for (StatusFile statusFile in statusFiles) { | |
67 print(' ${statusFile.uri}'); | |
68 statusFile.entries.forEach((StatusEntry entry) { | |
69 print(' ${padRight(entry.status, maxStatusWidth)}' | |
70 ' ${padRight(entry.config, maxConfigWidth)} ${entry.comment}'); | |
71 }); | |
72 } | |
73 }); | |
74 } | |
75 | |
76 /// Returns the [Uri]s for all `.status` files in [path] and subdirectories. | |
77 Future<List<Uri>> findStatusFiles(String path) async { | |
78 List<Uri> statusFiles = <Uri>[]; | |
79 await for (FileSystemEntity entity | |
80 in new Directory(path).list(recursive: true)) { | |
81 if (entity.path.endsWith('.status')) { | |
82 statusFiles.add(entity.uri); | |
83 } | |
84 } | |
85 return statusFiles; | |
86 } | |
87 | |
88 /// The entries collected for a single status file. | |
89 class StatusFile { | |
90 final Uri uri; | |
91 final List<StatusEntry> entries = <StatusEntry>[]; | |
92 | |
93 StatusFile(this.uri); | |
94 } | |
95 | |
96 /// A single entry in a status file. | |
97 class StatusEntry { | |
98 /// The preceding config line, i.e. `[...]` line that contained this entry. | |
karlklose
2017/03/15 14:06:25
Add that it can be null (if it did not encounter a
Johnni Winther
2017/03/15 14:32:17
It's will empty in that case. Added.
| |
99 final String config; | |
100 | |
101 /// The status of the entry, e.g. `Pass, Slow`. | |
102 final String status; | |
103 | |
104 /// The comment after the status, if any. | |
105 final String comment; | |
106 | |
107 StatusEntry(this.config, this.status, this.comment); | |
108 | |
109 String toString() => '$status $config $comment'; | |
110 } | |
OLD | NEW |