OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 library dart2js.serialization_model_test; | 5 library dart2js.serialization_model_test; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'package:async_helper/async_helper.dart'; | 8 import 'package:async_helper/async_helper.dart'; |
9 import 'package:expect/expect.dart'; | 9 import 'package:expect/expect.dart'; |
10 import 'package:compiler/src/closure.dart'; | 10 import 'package:compiler/src/closure.dart'; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 compilerDeserialized.enqueuer.resolution.processedEntities, | 118 compilerDeserialized.enqueuer.resolution.processedEntities, |
119 "Processed element mismatch", | 119 "Processed element mismatch", |
120 areElementsEquivalent, onSameElement: (a, b) { | 120 areElementsEquivalent, onSameElement: (a, b) { |
121 checkElements(compilerNormal, compilerDeserialized, a, b, verbose: verbose); | 121 checkElements(compilerNormal, compilerDeserialized, a, b, verbose: verbose); |
122 }, verbose: verbose); | 122 }, verbose: verbose); |
123 Expect.equals( | 123 Expect.equals( |
124 compilerNormal.deferredLoadTask.isProgramSplit, | 124 compilerNormal.deferredLoadTask.isProgramSplit, |
125 compilerDeserialized.deferredLoadTask.isProgramSplit, | 125 compilerDeserialized.deferredLoadTask.isProgramSplit, |
126 "isProgramSplit mismatch"); | 126 "isProgramSplit mismatch"); |
127 | 127 |
128 Map<ConstantValue, OutputUnit> constants1 = | 128 Iterable<ConstantValue> constants1 = |
129 compilerNormal.deferredLoadTask.outputUnitForConstantsForTesting; | 129 compilerNormal.deferredLoadTask.constantsForTesting; |
130 Map<ConstantValue, OutputUnit> constants2 = | 130 Iterable<ConstantValue> constants2 = |
131 compilerDeserialized.deferredLoadTask.outputUnitForConstantsForTesting; | 131 compilerDeserialized.deferredLoadTask.constantsForTesting; |
132 checkSets( | 132 checkSets( |
133 constants1.keys, | 133 constants1, |
134 constants2.keys, | 134 constants2, |
135 'deferredLoadTask._outputUnitForConstants.keys', | 135 'deferredLoadTask._outputUnitForConstants.keys', |
136 areConstantValuesEquivalent, | 136 areConstantValuesEquivalent, |
137 failOnUnfound: false, | 137 failOnUnfound: false, |
138 failOnExtra: false, | 138 failOnExtra: false, |
139 onSameElement: (ConstantValue value1, ConstantValue value2) { | 139 onSameElement: (ConstantValue value1, ConstantValue value2) { |
140 OutputUnit outputUnit1 = constants1[value1]; | |
141 OutputUnit outputUnit2 = constants2[value2]; | |
142 checkOutputUnits( | 140 checkOutputUnits( |
143 outputUnit1, | 141 compilerNormal, |
144 outputUnit2, | 142 compilerDeserialized, |
| 143 compilerNormal.deferredLoadTask.outputUnitForConstant(value1), |
| 144 compilerDeserialized.deferredLoadTask.outputUnitForConstant(value2), |
145 'for ${value1.toStructuredText()} ' | 145 'for ${value1.toStructuredText()} ' |
146 'vs ${value2.toStructuredText()}'); | 146 'vs ${value2.toStructuredText()}'); |
147 }, onUnfoundElement: (ConstantValue value1) { | 147 }, onUnfoundElement: (ConstantValue value1) { |
148 OutputUnit outputUnit1 = constants1[value1]; | 148 OutputUnit outputUnit1 = |
| 149 compilerNormal.deferredLoadTask.outputUnitForConstant(value1); |
149 Expect.isTrue(outputUnit1.isMainOutput, | 150 Expect.isTrue(outputUnit1.isMainOutput, |
150 "Missing deferred constant: ${value1.toStructuredText()}"); | 151 "Missing deferred constant: ${value1.toStructuredText()}"); |
151 }, onExtraElement: (ConstantValue value2) { | 152 }, onExtraElement: (ConstantValue value2) { |
152 OutputUnit outputUnit2 = constants2[value2]; | 153 OutputUnit outputUnit2 = |
| 154 compilerDeserialized.deferredLoadTask.outputUnitForConstant(value2); |
153 Expect.isTrue(outputUnit2.isMainOutput, | 155 Expect.isTrue(outputUnit2.isMainOutput, |
154 "Extra deferred constant: ${value2.toStructuredText()}"); | 156 "Extra deferred constant: ${value2.toStructuredText()}"); |
155 }, elementToString: (a) { | 157 }, elementToString: (a) { |
156 return '${a.toStructuredText()} -> ${constants1[a]}/${constants2[a]}'; | 158 OutputUnit o1 = compilerNormal.deferredLoadTask.outputUnitForConstant(a); |
| 159 OutputUnit o2 = |
| 160 compilerDeserialized.deferredLoadTask.outputUnitForConstant(a); |
| 161 return '${a.toStructuredText()} -> ${o1}/${o2}'; |
157 }); | 162 }); |
158 } | 163 } |
159 | 164 |
160 void checkElements( | 165 void checkElements( |
161 Compiler compiler1, Compiler compiler2, Element element1, Element element2, | 166 Compiler compiler1, Compiler compiler2, Element element1, Element element2, |
162 {bool verbose: false}) { | 167 {bool verbose: false}) { |
163 if (element1.isAbstract) return; | 168 if (element1.isAbstract) return; |
164 if (element1.isFunction || | 169 if (element1.isFunction || |
165 element1.isConstructor || | 170 element1.isConstructor || |
166 (element1.isField && element1.isInstanceMember)) { | 171 (element1.isField && element1.isInstanceMember)) { |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 } | 282 } |
278 return '(${node.runtimeType}) $text'; | 283 return '(${node.runtimeType}) $text'; |
279 } | 284 } |
280 | 285 |
281 void checkElementOutputUnits(Compiler compiler1, Compiler compiler2, | 286 void checkElementOutputUnits(Compiler compiler1, Compiler compiler2, |
282 Element element1, Element element2) { | 287 Element element1, Element element2) { |
283 OutputUnit outputUnit1 = | 288 OutputUnit outputUnit1 = |
284 compiler1.deferredLoadTask.getOutputUnitForElementForTesting(element1); | 289 compiler1.deferredLoadTask.getOutputUnitForElementForTesting(element1); |
285 OutputUnit outputUnit2 = | 290 OutputUnit outputUnit2 = |
286 compiler2.deferredLoadTask.getOutputUnitForElementForTesting(element2); | 291 compiler2.deferredLoadTask.getOutputUnitForElementForTesting(element2); |
287 checkOutputUnits(outputUnit1, outputUnit2, 'for $element1 vs $element2'); | 292 checkOutputUnits(compiler1, compiler2, outputUnit1, outputUnit2, |
| 293 'for $element1 vs $element2'); |
288 } | 294 } |
289 | 295 |
290 void checkOutputUnits( | 296 void checkOutputUnits(Compiler compiler1, Compiler compiler2, |
291 OutputUnit outputUnit1, OutputUnit outputUnit2, String message) { | 297 OutputUnit outputUnit1, OutputUnit outputUnit2, String message) { |
292 if (outputUnit1 == null && outputUnit2 == null) return; | 298 if (outputUnit1 == null && outputUnit2 == null) return; |
293 check(outputUnit1, outputUnit2, 'OutputUnit.isMainOutput $message', | 299 check(outputUnit1, outputUnit2, 'OutputUnit.isMainOutput $message', |
294 outputUnit1.isMainOutput, outputUnit2.isMainOutput); | 300 outputUnit1.isMainOutput, outputUnit2.isMainOutput); |
295 checkSetEquivalence( | 301 checkSetEquivalence( |
296 outputUnit1, | 302 outputUnit1, |
297 outputUnit2, | 303 outputUnit2, |
298 'OutputUnit.imports $message', | 304 'OutputUnit.imports $message', |
299 outputUnit1.imports, | 305 compiler1.deferredLoadTask.getImportNames(outputUnit1), |
300 outputUnit2.imports, | 306 compiler2.deferredLoadTask.getImportNames(outputUnit2), |
301 (a, b) => areElementsEquivalent(a.declaration, b.declaration)); | 307 (a, b) => areElementsEquivalent(a.declaration, b.declaration)); |
302 } | 308 } |
OLD | NEW |