OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2016, 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 /// Tests the tool `pkg/front_end/tool/fasta`. | |
Siggi Cherem (dart-lang)
2017/08/23 20:17:35
yay!
ahe
2017/08/24 11:52:02
Acknowledged.
| |
6 | |
7 import "dart:convert"; | |
8 | |
9 import "dart:io"; | |
10 | |
11 import "package:expect/expect.dart"; | |
12 | |
13 import "package:front_end/src/fasta/fasta_codes.dart" | |
14 show messageFastaUsageShort; | |
15 | |
16 const String toolPath = "pkg/front_end/tool/fasta"; | |
17 | |
18 const List<String> subtools = const <String>[ | |
19 "abcompile", | |
20 "analyzer-compile", | |
21 "compile", | |
22 "compile-platform", | |
23 "compile-platform-dartk", | |
24 "log", | |
25 "logd", | |
26 "outline", | |
27 "parser", | |
28 "run", | |
29 "scanner", | |
30 "dump-partial", | |
31 "dump-ir", | |
32 "kernel-service", | |
33 "testing", | |
34 "generate-messages", | |
35 ]; | |
36 | |
37 const List<String> unsafeTools = const <String>[ | |
Siggi Cherem (dart-lang)
2017/08/23 20:17:35
Please document what does it mean for a tool to be
ahe
2017/08/24 11:52:02
Done.
| |
38 "generate-messages", | |
39 "logd", | |
40 "testing", | |
41 ]; | |
42 | |
43 const JsonEncoder prettyJson = const JsonEncoder.withIndent(" "); | |
44 | |
45 main() { | |
46 if (!Platform.isMacOS && !Platform.isLinux) { | |
47 // The tool is a shell script and only works on Mac and Linux. | |
Siggi Cherem (dart-lang)
2017/08/23 20:17:35
should we replace it with a Dart script?
ahe
2017/08/24 11:52:02
Yes. I've added a TODO to the script.
| |
48 return; | |
49 } | |
50 Set<String> testedSubtools = new Set<String>.from(subtools) | |
51 .difference(new Set<String>.from(unsafeTools)); | |
52 Map<String, Map<String, dynamic>> resultMap = | |
53 <String, Map<String, dynamic>>{}; | |
54 for (String subtool in testedSubtools) { | |
55 print("Testing $subtool"); | |
56 ProcessResult result = | |
57 Process.runSync("/bin/bash", <String>[toolPath, subtool]); | |
Siggi Cherem (dart-lang)
2017/08/23 20:17:35
should we also run all tools with a good example s
ahe
2017/08/24 11:52:02
For now, I assume that happens as part of our regu
| |
58 resultMap[subtool] = { | |
59 "exitCode": result.exitCode, | |
60 "stdout": result.stdout, | |
61 "stderr": result.stderr, | |
62 }; | |
63 } | |
64 Map<String, dynamic> scanner = resultMap["scanner"]; | |
65 Expect.isTrue(scanner["stdout"].startsWith("Reading files took: ")); | |
66 scanner.remove("stdout"); | |
67 | |
68 Map<String, dynamic> kernelService = resultMap["kernel-service"]; | |
69 Expect.isTrue(kernelService["stderr"].startsWith("Usage: dart [")); | |
70 kernelService.remove("stderr"); | |
71 | |
72 String jsonResult = prettyJson.convert(resultMap); | |
73 String usage = messageFastaUsageShort.message; | |
74 | |
75 String jsonExpectation = prettyJson.convert({ | |
76 "abcompile": { | |
77 "exitCode": 1, | |
78 "stdout": """[] | |
79 Expected -DbRoot=/absolute/path/to/other/sdk/repo | |
80 """, | |
81 "stderr": "", | |
82 }, | |
83 "analyzer-compile": { | |
84 "exitCode": 2, | |
85 "stdout": "", | |
86 "stderr": "'analyzer-compile' isn't supported anymore," | |
87 " please use 'compile' instead.\n", | |
88 }, | |
89 "compile": { | |
90 "exitCode": 1, | |
91 "stdout": """Usage: compile [options] dartfile | |
92 | |
93 Compiles a Dart program to the Dill/Kernel IR format. | |
94 | |
95 $usage | |
96 Error: No Dart file specified. | |
97 """, | |
98 "stderr": "", | |
99 }, | |
100 "compile-platform": { | |
101 "exitCode": 1, | |
102 "stdout": """ | |
103 Usage: compile_platform [options] patched_sdk fullOutput outlineOutput | |
104 | |
105 Compiles Dart SDK platform to the Dill/Kernel IR format. | |
106 | |
107 $usage | |
108 Error: Expected three arguments. | |
109 """, | |
110 "stderr": "", | |
111 }, | |
112 "compile-platform-dartk": { | |
113 "exitCode": 2, | |
114 "stdout": "", | |
115 "stderr": "Usage: compile-platform-dartk file\n", | |
116 }, | |
117 "log": { | |
118 "exitCode": 0, | |
119 "stdout": "", | |
120 "stderr": "", | |
121 }, | |
122 "outline": { | |
123 "exitCode": 1, | |
124 "stdout": """Usage: outline [options] dartfile | |
125 | |
126 Creates an outline of a Dart program in the Dill/Kernel IR format. | |
127 | |
128 $usage | |
129 Error: No Dart file specified. | |
130 """, | |
131 "stderr": "", | |
132 }, | |
133 "parser": { | |
134 "exitCode": 0, | |
135 "stdout": "", | |
136 "stderr": "", | |
137 }, | |
138 "run": { | |
139 "exitCode": 2, | |
140 "stdout": "", | |
141 "stderr": "'run' isn't supported anymore," | |
142 " please use 'kernel-service' instead.\n", | |
143 }, | |
144 "scanner": { | |
145 "exitCode": 0, | |
146 "stderr": "", | |
147 }, | |
148 "dump-partial": { | |
149 "exitCode": 1, | |
150 "stdout": "usage: pkg/front_end/tool/fasta dump_partial" | |
151 " partial.dill [extra1.dill] ... [extraN.dill]\n", | |
152 "stderr": "", | |
153 }, | |
154 "dump-ir": { | |
155 "exitCode": 2, | |
156 "stdout": "", | |
157 "stderr": "Usage: dump-ir dillfile [output]\n", | |
158 }, | |
159 "kernel-service": { | |
160 "exitCode": 255, | |
161 "stdout": "", | |
162 }, | |
163 }); | |
164 Expect.stringEquals(jsonExpectation, jsonResult); | |
165 } | |
OLD | NEW |