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 library dart2js.serialization_resolved_ast_test; |
| 6 |
| 7 import 'dart:async'; |
| 8 import 'package:async_helper/async_helper.dart'; |
| 9 import 'package:expect/expect.dart'; |
| 10 import 'package:compiler/src/commandline_options.dart'; |
| 11 import 'package:compiler/src/common/backend_api.dart'; |
| 12 import 'package:compiler/src/common/names.dart'; |
| 13 import 'package:compiler/src/compiler.dart'; |
| 14 import 'package:compiler/src/elements/elements.dart'; |
| 15 import 'package:compiler/src/filenames.dart'; |
| 16 import 'package:compiler/src/serialization/equivalence.dart'; |
| 17 import 'memory_compiler.dart'; |
| 18 import 'serialization_helper.dart'; |
| 19 import 'serialization_test_data.dart'; |
| 20 import 'serialization_test_helper.dart'; |
| 21 |
| 22 |
| 23 main(List<String> arguments) { |
| 24 asyncTest(() async { |
| 25 String serializedData = await serializeDartCore(serializeResolvedAst: true); |
| 26 if (arguments.isNotEmpty) { |
| 27 Uri entryPoint = Uri.base.resolve(nativeToUriPath(arguments.last)); |
| 28 await check(serializedData, entryPoint); |
| 29 } else { |
| 30 Uri entryPoint = Uri.parse('memory:main.dart'); |
| 31 // TODO(johnniwinther): Change to test all serialized resolved ast instead |
| 32 // only those used in the test. |
| 33 Test test = TESTS.last; |
| 34 await check(serializedData, entryPoint, test.sourceFiles); |
| 35 } |
| 36 }); |
| 37 } |
| 38 |
| 39 Future check( |
| 40 String serializedData, |
| 41 Uri entryPoint, |
| 42 [Map<String, String> sourceFiles = const <String, String>{}]) async { |
| 43 |
| 44 Compiler compilerNormal = compilerFor( |
| 45 memorySourceFiles: sourceFiles, |
| 46 options: [Flags.analyzeOnly]); |
| 47 compilerNormal.resolution.retainCachesForTesting = true; |
| 48 await compilerNormal.run(entryPoint); |
| 49 |
| 50 Compiler compilerDeserialized = compilerFor( |
| 51 memorySourceFiles: sourceFiles, |
| 52 options: [Flags.analyzeOnly]); |
| 53 compilerDeserialized.resolution.retainCachesForTesting = true; |
| 54 deserialize( |
| 55 compilerDeserialized, serializedData, deserializeResolvedAst: true); |
| 56 await compilerDeserialized.run(entryPoint); |
| 57 |
| 58 checkAllResolvedAsts(compilerNormal, compilerDeserialized, verbose: true); |
| 59 } |
| 60 |
| 61 void checkAllResolvedAsts( |
| 62 Compiler compiler1, |
| 63 Compiler compiler2, |
| 64 {bool verbose: false}) { |
| 65 checkLoadedLibraryMembers( |
| 66 compiler1, |
| 67 compiler2, |
| 68 (Element member1) { |
| 69 return compiler1.resolution.hasResolvedAst(member1); |
| 70 }, |
| 71 checkResolvedAsts, |
| 72 verbose: true); |
| 73 } |
| 74 |
| 75 |
| 76 /// Check equivalence of [impact1] and [impact2]. |
| 77 void checkResolvedAsts(Compiler compiler1, Element member1, |
| 78 Compiler compiler2, Element member2, |
| 79 {bool verbose: false}) { |
| 80 ResolvedAst resolvedAst1 = compiler1.resolution.getResolvedAst(member1); |
| 81 ResolvedAst resolvedAst2 = |
| 82 compiler2.serialization.deserializer.getResolvedAst(member2); |
| 83 |
| 84 if (resolvedAst1 == null || resolvedAst2 == null) return; |
| 85 |
| 86 if (verbose) { |
| 87 print('Checking resolved asts for $member1 vs $member2'); |
| 88 } |
| 89 |
| 90 testResolvedAstEquivalence( |
| 91 resolvedAst1, resolvedAst2, const CheckStrategy()); |
| 92 } |
OLD | NEW |