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