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:compiler/src/commandline_options.dart'; | 9 import 'package:compiler/src/commandline_options.dart'; |
10 import 'package:compiler/src/compiler.dart'; | 10 import 'package:compiler/src/compiler.dart'; |
11 import 'package:compiler/src/elements/elements.dart'; | 11 import 'package:compiler/src/elements/elements.dart'; |
12 import 'package:compiler/src/filenames.dart'; | 12 import 'package:compiler/src/filenames.dart'; |
13 import 'package:compiler/src/serialization/equivalence.dart'; | 13 import 'package:compiler/src/serialization/equivalence.dart'; |
14 import '../memory_compiler.dart'; | 14 import '../memory_compiler.dart'; |
15 import 'helper.dart'; | 15 import 'helper.dart'; |
16 import 'test_data.dart'; | 16 import 'test_data.dart'; |
17 import 'test_helper.dart'; | 17 import 'test_helper.dart'; |
18 | 18 |
19 | 19 |
20 main(List<String> args) { | 20 main(List<String> args) { |
21 Arguments arguments = new Arguments.from(args); | 21 Arguments arguments = new Arguments.from(args); |
22 asyncTest(() async { | 22 asyncTest(() async { |
23 String serializedData = await serializeDartCore(arguments: arguments); | 23 SerializedData serializedData = |
| 24 await serializeDartCore(arguments: arguments); |
24 if (arguments.filename != null) { | 25 if (arguments.filename != null) { |
25 Uri entryPoint = Uri.base.resolve(nativeToUriPath(arguments.filename)); | 26 Uri entryPoint = Uri.base.resolve(nativeToUriPath(arguments.filename)); |
26 await check(serializedData, entryPoint); | 27 await check(serializedData, entryPoint); |
27 } else { | 28 } else { |
28 Uri entryPoint = Uri.parse('memory:main.dart'); | 29 Uri entryPoint = Uri.parse('memory:main.dart'); |
29 // TODO(johnniwinther): Change to test all serialized resolved ast instead | 30 // TODO(johnniwinther): Change to test all serialized resolved ast instead |
30 // only those used in the test. | 31 // only those used in the test. |
31 Test test = TESTS.last; | 32 Test test = TESTS.last; |
32 await check(serializedData, entryPoint, test.sourceFiles); | 33 await check(serializedData, entryPoint, test.sourceFiles); |
33 } | 34 } |
34 }); | 35 }); |
35 } | 36 } |
36 | 37 |
37 Future check( | 38 Future check( |
38 String serializedData, | 39 SerializedData serializedData, |
39 Uri entryPoint, | 40 Uri entryPoint, |
40 [Map<String, String> sourceFiles = const <String, String>{}]) async { | 41 [Map<String, String> sourceFiles = const <String, String>{}]) async { |
41 | 42 |
42 Compiler compilerNormal = compilerFor( | 43 Compiler compilerNormal = compilerFor( |
43 memorySourceFiles: sourceFiles, | 44 memorySourceFiles: sourceFiles, |
44 options: [Flags.analyzeAll]); | 45 options: [Flags.analyzeAll]); |
45 compilerNormal.resolution.retainCachesForTesting = true; | 46 compilerNormal.resolution.retainCachesForTesting = true; |
46 await compilerNormal.run(entryPoint); | 47 await compilerNormal.run(entryPoint); |
47 | 48 |
48 Compiler compilerDeserialized = compilerFor( | 49 Compiler compilerDeserialized = compilerFor( |
49 memorySourceFiles: sourceFiles, | 50 memorySourceFiles: serializedData.toMemorySourceFiles(sourceFiles), |
| 51 resolutionInputs: serializedData.toUris(), |
50 options: [Flags.analyzeAll]); | 52 options: [Flags.analyzeAll]); |
51 compilerDeserialized.resolution.retainCachesForTesting = true; | 53 compilerDeserialized.resolution.retainCachesForTesting = true; |
52 compilerDeserialized.serialization.deserializeFromText(serializedData); | |
53 await compilerDeserialized.run(entryPoint); | 54 await compilerDeserialized.run(entryPoint); |
54 | 55 |
55 checkAllResolvedAsts(compilerNormal, compilerDeserialized, verbose: true); | 56 checkAllResolvedAsts(compilerNormal, compilerDeserialized, verbose: true); |
56 } | 57 } |
57 | 58 |
58 void checkAllResolvedAsts( | 59 void checkAllResolvedAsts( |
59 Compiler compiler1, | 60 Compiler compiler1, |
60 Compiler compiler2, | 61 Compiler compiler2, |
61 {bool verbose: false}) { | 62 {bool verbose: false}) { |
62 checkLoadedLibraryMembers( | 63 checkLoadedLibraryMembers( |
(...skipping 20 matching lines...) Expand all Loading... |
83 | 84 |
84 if (resolvedAst1 == null || resolvedAst2 == null) return; | 85 if (resolvedAst1 == null || resolvedAst2 == null) return; |
85 | 86 |
86 if (verbose) { | 87 if (verbose) { |
87 print('Checking resolved asts for $member1 vs $member2'); | 88 print('Checking resolved asts for $member1 vs $member2'); |
88 } | 89 } |
89 | 90 |
90 testResolvedAstEquivalence( | 91 testResolvedAstEquivalence( |
91 resolvedAst1, resolvedAst2, const CheckStrategy()); | 92 resolvedAst1, resolvedAst2, const CheckStrategy()); |
92 } | 93 } |
OLD | NEW |