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