Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Side by Side Diff: tests/compiler/dart2js/serialization_resolved_ast_test.dart

Issue 1934883002: Refactor unittests (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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> args) {
24 Arguments arguments = new Arguments.from(args);
25 asyncTest(() async {
26 String serializedData = await serializeDartCore(
27 arguments: arguments, serializeResolvedAst: true);
28 if (arguments.filename != null) {
29 Uri entryPoint = Uri.base.resolve(nativeToUriPath(arguments.filename));
30 await check(serializedData, entryPoint);
31 } else {
32 Uri entryPoint = Uri.parse('memory:main.dart');
33 // TODO(johnniwinther): Change to test all serialized resolved ast instead
34 // only those used in the test.
35 Test test = TESTS.last;
36 await check(serializedData, entryPoint, test.sourceFiles);
37 }
38 });
39 }
40
41 Future check(
42 String serializedData,
43 Uri entryPoint,
44 [Map<String, String> sourceFiles = const <String, String>{}]) async {
45
46 Compiler compilerNormal = compilerFor(
47 memorySourceFiles: sourceFiles,
48 options: [Flags.analyzeAll]);
49 compilerNormal.resolution.retainCachesForTesting = true;
50 await compilerNormal.run(entryPoint);
51
52 Compiler compilerDeserialized = compilerFor(
53 memorySourceFiles: sourceFiles,
54 options: [Flags.analyzeAll]);
55 compilerDeserialized.resolution.retainCachesForTesting = true;
56 deserialize(
57 compilerDeserialized, serializedData, deserializeResolvedAst: true);
58 await compilerDeserialized.run(entryPoint);
59
60 checkAllResolvedAsts(compilerNormal, compilerDeserialized, verbose: true);
61 }
62
63 void checkAllResolvedAsts(
64 Compiler compiler1,
65 Compiler compiler2,
66 {bool verbose: false}) {
67 checkLoadedLibraryMembers(
68 compiler1,
69 compiler2,
70 (Element member1) {
71 return compiler1.resolution.hasResolvedAst(member1);
72 },
73 checkResolvedAsts,
74 verbose: verbose);
75 }
76
77
78 /// Check equivalence of [impact1] and [impact2].
79 void checkResolvedAsts(Compiler compiler1, Element member1,
80 Compiler compiler2, Element member2,
81 {bool verbose: false}) {
82 ResolvedAst resolvedAst1 = compiler1.resolution.getResolvedAst(member1);
83 ResolvedAst resolvedAst2 =
84 compiler2.serialization.deserializer.getResolvedAst(member2);
85
86 if (resolvedAst1 == null || resolvedAst2 == null) return;
87
88 if (verbose) {
89 print('Checking resolved asts for $member1 vs $member2');
90 }
91
92 testResolvedAstEquivalence(
93 resolvedAst1, resolvedAst2, const CheckStrategy());
94 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/serialization_model_test.dart ('k') | tests/compiler/dart2js/serialization_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698