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 to test compilation equivalence between source and .dill based | 5 // Helper to test compilation equivalence between source and .dill based |
6 // compilation. | 6 // compilation. |
7 library dart2js.kernel.compile_from_dill_test_helper; | 7 library dart2js.kernel.compile_from_dill_test_helper; |
8 | 8 |
9 import 'dart:async'; | 9 import 'dart:async'; |
10 import 'dart:io'; | 10 import 'dart:io'; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 } | 87 } |
88 x = toplevel; | 88 x = toplevel; |
89 print(x); | 89 print(x); |
90 return x; | 90 return x; |
91 } | 91 } |
92 ''' | 92 ''' |
93 }; | 93 }; |
94 | 94 |
95 enum ResultKind { crashes, errors, warnings, success, failure } | 95 enum ResultKind { crashes, errors, warnings, success, failure } |
96 | 96 |
| 97 const List<String> commonOptions = const <String>[ |
| 98 Flags.disableTypeInference, |
| 99 Flags.disableInlining, |
| 100 Flags.enableAssertMessage |
| 101 ]; |
| 102 |
97 Future<ResultKind> runTest( | 103 Future<ResultKind> runTest( |
98 Uri entryPoint, Map<String, String> memorySourceFiles, | 104 Uri entryPoint, Map<String, String> memorySourceFiles, |
99 {bool skipWarnings: false, | 105 {bool skipWarnings: false, |
100 bool skipErrors: false, | 106 bool skipErrors: false, |
101 bool verbose: false, | 107 bool verbose: false, |
102 List<String> options: const <String>[]}) async { | 108 List<String> options: const <String>[]}) async { |
103 enableDebugMode(); | 109 enableDebugMode(); |
104 EnumCreator.matchKernelRepresentationForTesting = true; | 110 EnumCreator.matchKernelRepresentationForTesting = true; |
105 Elements.usePatchedDart2jsSdkSorting = true; | 111 Elements.usePatchedDart2jsSdkSorting = true; |
106 | 112 |
107 Directory dir = await Directory.systemTemp.createTemp('dart2js-with-dill'); | 113 Directory dir = await Directory.systemTemp.createTemp('dart2js-with-dill'); |
108 print('--- create temp directory $dir -------------------------------'); | 114 print('--- create temp directory $dir -------------------------------'); |
109 memorySourceFiles.forEach((String name, String source) { | 115 memorySourceFiles.forEach((String name, String source) { |
110 new File.fromUri(dir.uri.resolve(name)).writeAsStringSync(source); | 116 new File.fromUri(dir.uri.resolve(name)).writeAsStringSync(source); |
111 }); | 117 }); |
112 entryPoint = dir.uri.resolve(entryPoint.path); | 118 entryPoint = dir.uri.resolve(entryPoint.path); |
113 | 119 |
114 print('---- compile from ast ----------------------------------------------'); | 120 print('---- compile from ast ----------------------------------------------'); |
115 DiagnosticCollector collector = new DiagnosticCollector(); | 121 DiagnosticCollector collector = new DiagnosticCollector(); |
116 OutputCollector collector1 = new OutputCollector(); | 122 OutputCollector collector1 = new OutputCollector(); |
117 Compiler compiler1 = compilerFor( | 123 Compiler compiler1 = compilerFor( |
118 entryPoint: entryPoint, | 124 entryPoint: entryPoint, |
119 diagnosticHandler: collector, | 125 diagnosticHandler: collector, |
120 outputProvider: collector1, | 126 outputProvider: collector1, |
121 options: [ | 127 options: <String>[]..addAll(commonOptions)..addAll(options)); |
122 Flags.disableTypeInference, | |
123 Flags.disableInlining, | |
124 Flags.enableAssertMessage | |
125 ]..addAll(options)); | |
126 ElementResolutionWorldBuilder.useInstantiationMap = true; | 128 ElementResolutionWorldBuilder.useInstantiationMap = true; |
127 compiler1.resolution.retainCachesForTesting = true; | 129 compiler1.resolution.retainCachesForTesting = true; |
128 await compiler1.run(entryPoint); | 130 await compiler1.run(entryPoint); |
129 if (collector.crashes.isNotEmpty) { | 131 if (collector.crashes.isNotEmpty) { |
130 print('Skipping due to crashes.'); | 132 print('Skipping due to crashes.'); |
131 return ResultKind.crashes; | 133 return ResultKind.crashes; |
132 } | 134 } |
133 if (collector.errors.isNotEmpty && skipErrors) { | 135 if (collector.errors.isNotEmpty && skipErrors) { |
134 print('Skipping due to errors.'); | 136 print('Skipping due to errors.'); |
135 return ResultKind.errors; | 137 return ResultKind.errors; |
136 } | 138 } |
137 if (collector.warnings.isNotEmpty && skipWarnings) { | 139 if (collector.warnings.isNotEmpty && skipWarnings) { |
138 print('Skipping due to warnings.'); | 140 print('Skipping due to warnings.'); |
139 return ResultKind.warnings; | 141 return ResultKind.warnings; |
140 } | 142 } |
141 Expect.isFalse(compiler1.compilationFailed); | 143 Expect.isFalse(compiler1.compilationFailed); |
142 ClosedWorld closedWorld1 = | 144 ClosedWorld closedWorld1 = |
143 compiler1.resolutionWorldBuilder.closedWorldForTesting; | 145 compiler1.resolutionWorldBuilder.closedWorldForTesting; |
144 | 146 |
145 OutputCollector collector2 = new OutputCollector(); | 147 OutputCollector collector2 = new OutputCollector(); |
146 Compiler compiler2 = await compileWithDill( | 148 Compiler compiler2 = await compileWithDill( |
147 entryPoint, | 149 entryPoint, const {}, <String>[]..addAll(commonOptions)..addAll(options), |
148 const {}, | 150 printSteps: true, compilerOutput: collector2); |
149 [ | |
150 Flags.disableTypeInference, | |
151 Flags.disableInlining, | |
152 Flags.enableAssertMessage | |
153 ]..addAll(options), | |
154 printSteps: true, | |
155 compilerOutput: collector2); | |
156 | 151 |
157 KernelFrontEndStrategy frontendStrategy = compiler2.frontendStrategy; | 152 KernelFrontEndStrategy frontendStrategy = compiler2.frontendStrategy; |
158 KernelToElementMap elementMap = frontendStrategy.elementMap; | 153 KernelToElementMap elementMap = frontendStrategy.elementMap; |
159 | 154 |
160 Expect.isFalse(compiler2.compilationFailed); | 155 Expect.isFalse(compiler2.compilationFailed); |
161 | 156 |
162 KernelEquivalence equivalence = new KernelEquivalence(elementMap); | 157 KernelEquivalence equivalence = new KernelEquivalence(elementMap); |
163 | 158 |
164 ClosedWorld closedWorld2 = | 159 ClosedWorld closedWorld2 = |
165 compiler2.resolutionWorldBuilder.closedWorldForTesting; | 160 compiler2.resolutionWorldBuilder.closedWorldForTesting; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 } | 209 } |
215 Map<String, BufferedOutputSink> map2 = collector2.outputMap[outputType]; | 210 Map<String, BufferedOutputSink> map2 = collector2.outputMap[outputType]; |
216 checkSets(map1.keys, map2.keys, 'output', equality); | 211 checkSets(map1.keys, map2.keys, 'output', equality); |
217 map1.forEach((String name, BufferedOutputSink output1) { | 212 map1.forEach((String name, BufferedOutputSink output1) { |
218 BufferedOutputSink output2 = map2[name]; | 213 BufferedOutputSink output2 = map2[name]; |
219 Expect.stringEquals(output1.text, output2.text); | 214 Expect.stringEquals(output1.text, output2.text); |
220 }); | 215 }); |
221 }); | 216 }); |
222 return ResultKind.success; | 217 return ResultKind.success; |
223 } | 218 } |
OLD | NEW |