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

Side by Side Diff: pkg/analyzer/test/src/summary/resynthesize_test.dart

Issue 1838453002: Use shared MockSdk instances in resynthesize tests. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 8 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
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 test.src.serialization.elements_test; 5 library test.src.serialization.elements_test;
6 6
7 import 'dart:convert'; 7 import 'dart:convert';
8 8
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/constant/value.dart'; 10 import 'package:analyzer/dart/constant/value.dart';
11 import 'package:analyzer/dart/element/element.dart'; 11 import 'package:analyzer/dart/element/element.dart';
12 import 'package:analyzer/dart/element/type.dart'; 12 import 'package:analyzer/dart/element/type.dart';
13 import 'package:analyzer/src/dart/ast/ast.dart'; 13 import 'package:analyzer/src/dart/ast/ast.dart';
14 import 'package:analyzer/src/dart/element/element.dart'; 14 import 'package:analyzer/src/dart/element/element.dart';
15 import 'package:analyzer/src/dart/element/handle.dart'; 15 import 'package:analyzer/src/dart/element/handle.dart';
16 import 'package:analyzer/src/dart/element/member.dart'; 16 import 'package:analyzer/src/dart/element/member.dart';
17 import 'package:analyzer/src/dart/element/type.dart'; 17 import 'package:analyzer/src/dart/element/type.dart';
18 import 'package:analyzer/src/generated/engine.dart'; 18 import 'package:analyzer/src/generated/engine.dart';
19 import 'package:analyzer/src/generated/error.dart'; 19 import 'package:analyzer/src/generated/error.dart';
20 import 'package:analyzer/src/generated/resolver.dart' 20 import 'package:analyzer/src/generated/resolver.dart'
21 show Namespace, TypeProvider; 21 show Namespace, TypeProvider;
22 import 'package:analyzer/src/generated/sdk.dart';
22 import 'package:analyzer/src/generated/source.dart'; 23 import 'package:analyzer/src/generated/source.dart';
23 import 'package:analyzer/src/generated/testing/ast_factory.dart'; 24 import 'package:analyzer/src/generated/testing/ast_factory.dart';
24 import 'package:analyzer/src/summary/idl.dart'; 25 import 'package:analyzer/src/summary/idl.dart';
25 import 'package:analyzer/src/summary/resynthesize.dart'; 26 import 'package:analyzer/src/summary/resynthesize.dart';
26 import 'package:analyzer/src/summary/summarize_elements.dart'; 27 import 'package:analyzer/src/summary/summarize_elements.dart';
27 import 'package:unittest/unittest.dart'; 28 import 'package:unittest/unittest.dart';
28 29
29 import '../../generated/test_support.dart'; 30 import '../../generated/test_support.dart';
30 import '../../reflective_tests.dart'; 31 import '../../reflective_tests.dart';
31 import '../abstract_single_unit.dart'; 32 import '../abstract_single_unit.dart';
33 import '../context/abstract_context.dart';
32 import 'summary_common.dart' show canonicalize; 34 import 'summary_common.dart' show canonicalize;
33 35
34 main() { 36 main() {
35 groupSep = ' | '; 37 groupSep = ' | ';
36 runReflectiveTests(ResynthesizeElementTest); 38 runReflectiveTests(ResynthesizeElementTest);
37 } 39 }
38 40
39 @reflectiveTest 41 @reflectiveTest
40 class ResynthesizeElementTest extends ResynthesizeTest { 42 class ResynthesizeElementTest extends ResynthesizeTest {
41 @override 43 @override
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 linkedSummaries[uri] = getLinkedSummaryFor(original); 106 linkedSummaries[uri] = getLinkedSummaryFor(original);
105 } 107 }
106 if (dumpSummaries) { 108 if (dumpSummaries) {
107 unlinkedSummaries.forEach((String path, UnlinkedUnit unit) { 109 unlinkedSummaries.forEach((String path, UnlinkedUnit unit) {
108 print('Unlinked $path: ${JSON.encode(canonicalize(unit))}'); 110 print('Unlinked $path: ${JSON.encode(canonicalize(unit))}');
109 }); 111 });
110 linkedSummaries.forEach((String path, LinkedLibrary lib) { 112 linkedSummaries.forEach((String path, LinkedLibrary lib) {
111 print('Linked $path: ${JSON.encode(canonicalize(lib))}'); 113 print('Linked $path: ${JSON.encode(canonicalize(lib))}');
112 }); 114 });
113 } 115 }
114 return new TestSummaryResynthesizer(null, context, unlinkedSummaries, 116 return new TestSummaryResynthesizer(
115 linkedSummaries); 117 null, context, unlinkedSummaries, linkedSummaries);
116 } 118 }
117 119
118 /** 120 /**
119 * Resynthesize the library element associated with [uri] using 121 * Resynthesize the library element associated with [uri] using
120 * [resynthesizer], and verify that it only had to consult one summary in 122 * [resynthesizer], and verify that it only had to consult one summary in
121 * order to do so. [original] is consulted merely to verify that no 123 * order to do so. [original] is consulted merely to verify that no
122 * unnecessary resynthesis work was performed. 124 * unnecessary resynthesis work was performed.
123 */ 125 */
124 LibraryElementImpl resynthesizeLibraryElement( 126 LibraryElementImpl resynthesizeLibraryElement(
125 TestSummaryResynthesizer resynthesizer, 127 TestSummaryResynthesizer resynthesizer,
(...skipping 1015 matching lines...) Expand 10 before | Expand all | Expand 10 after
1141 } else { 1143 } else {
1142 compareConstAsts(initializer, originalActual.constantInitializer, 1144 compareConstAsts(initializer, originalActual.constantInitializer,
1143 '$desc initializer'); 1145 '$desc initializer');
1144 } 1146 }
1145 } 1147 }
1146 } 1148 }
1147 checkPossibleMember(resynthesized, original, desc); 1149 checkPossibleMember(resynthesized, original, desc);
1148 checkPossibleLocalElements(resynthesized, original); 1150 checkPossibleLocalElements(resynthesized, original);
1149 } 1151 }
1150 1152
1153 DartSdk createDartSdk() => AbstractContextTest.SHARED_MOCK_SDK;
1154
1151 /** 1155 /**
1152 * Determine the analysis options that should be used for this test. 1156 * Determine the analysis options that should be used for this test.
1153 */ 1157 */
1154 AnalysisOptionsImpl createOptions() => 1158 AnalysisOptionsImpl createOptions() =>
1155 new AnalysisOptionsImpl()..enableGenericMethods = true; 1159 new AnalysisOptionsImpl()..enableGenericMethods = true;
1156 1160
1157 /** 1161 /**
1158 * Return a [SummaryResynthesizer] to resynthesize the library with the 1162 * Return a [SummaryResynthesizer] to resynthesize the library with the
1159 * given [librarySource]. 1163 * given [librarySource].
1160 */ 1164 */
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1206 linkedSummaries[uri] = getLinkedSummaryFor(original); 1210 linkedSummaries[uri] = getLinkedSummaryFor(original);
1207 } 1211 }
1208 if (dumpSummaries) { 1212 if (dumpSummaries) {
1209 unlinkedSummaries.forEach((String path, UnlinkedUnit unit) { 1213 unlinkedSummaries.forEach((String path, UnlinkedUnit unit) {
1210 print('Unlinked $path: ${JSON.encode(canonicalize(unit))}'); 1214 print('Unlinked $path: ${JSON.encode(canonicalize(unit))}');
1211 }); 1215 });
1212 linkedSummaries.forEach((String path, LinkedLibrary lib) { 1216 linkedSummaries.forEach((String path, LinkedLibrary lib) {
1213 print('Linked $path: ${JSON.encode(canonicalize(lib))}'); 1217 print('Linked $path: ${JSON.encode(canonicalize(lib))}');
1214 }); 1218 });
1215 } 1219 }
1216 return new TestSummaryResynthesizer(null, context, unlinkedSummaries, 1220 return new TestSummaryResynthesizer(
1217 linkedSummaries); 1221 null, context, unlinkedSummaries, linkedSummaries);
1218 } 1222 }
1219 1223
1220 fail_library_hasExtUri() { 1224 fail_library_hasExtUri() {
1221 checkLibrary('import "dart-ext:doesNotExist.dart";'); 1225 checkLibrary('import "dart-ext:doesNotExist.dart";');
1222 } 1226 }
1223 1227
1224 ElementImpl getActualElement(Element element, String desc) { 1228 ElementImpl getActualElement(Element element, String desc) {
1225 if (element == null) { 1229 if (element == null) {
1226 return null; 1230 return null;
1227 } else if (element is ElementImpl) { 1231 } else if (element is ElementImpl) {
(...skipping 2979 matching lines...) Expand 10 before | Expand all | Expand 10 after
4207 fail('Unexpectedly tried to get unlinked summary for $uri'); 4211 fail('Unexpectedly tried to get unlinked summary for $uri');
4208 } 4212 }
4209 return serializedUnit; 4213 return serializedUnit;
4210 } 4214 }
4211 4215
4212 @override 4216 @override
4213 bool hasLibrarySummary(String uri) { 4217 bool hasLibrarySummary(String uri) {
4214 return true; 4218 return true;
4215 } 4219 }
4216 } 4220 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698