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

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

Issue 1577973003: Test and fix serializing a library with a missing part. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 analyzer.test.src.summary.summary_test; 5 library analyzer.test.src.summary.summary_test;
6 6
7 import 'package:analyzer/dart/element/element.dart'; 7 import 'package:analyzer/dart/element/element.dart';
8 import 'package:analyzer/src/generated/ast.dart'; 8 import 'package:analyzer/src/generated/ast.dart';
9 import 'package:analyzer/src/generated/engine.dart'; 9 import 'package:analyzer/src/generated/engine.dart';
10 import 'package:analyzer/src/generated/error.dart'; 10 import 'package:analyzer/src/generated/error.dart';
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 * Override of [SummaryTest] which creates summaries from the element model. 185 * Override of [SummaryTest] which creates summaries from the element model.
186 */ 186 */
187 @reflectiveTest 187 @reflectiveTest
188 class SummarizeElementsTest extends ResolverTestCase with SummaryTest { 188 class SummarizeElementsTest extends ResolverTestCase with SummaryTest {
189 /** 189 /**
190 * The list of absolute unit URIs corresponding to the compilation units in 190 * The list of absolute unit URIs corresponding to the compilation units in
191 * [unlinkedUnits]. 191 * [unlinkedUnits].
192 */ 192 */
193 List<String> unitUris; 193 List<String> unitUris;
194 194
195 /**
196 * Map containing all source files in this test, and their corresponding file
197 * contents.
198 */
199 final Map<Source, String> _fileContents = <Source, String>{};
200
195 @override 201 @override
196 bool get checkAstDerivedData => false; 202 bool get checkAstDerivedData => false;
197 203
198 @override 204 @override
199 bool get expectAbsoluteUrisInDependencies => true; 205 bool get expectAbsoluteUrisInDependencies => true;
200 206
207 @override
208 Source addNamedSource(String filePath, String contents) {
209 Source source = super.addNamedSource(filePath, contents);
210 _fileContents[source] = contents;
211 return source;
212 }
213
201 /** 214 /**
202 * Serialize the library containing the given class [element], then 215 * Serialize the library containing the given class [element], then
203 * deserialize it and return the summary of the class. 216 * deserialize it and return the summary of the class.
204 */ 217 */
205 UnlinkedClass serializeClassElement(ClassElement element) { 218 UnlinkedClass serializeClassElement(ClassElement element) {
206 serializeLibraryElement(element.library); 219 serializeLibraryElement(element.library);
207 return findClass(element.name, failIfAbsent: true); 220 return findClass(element.name, failIfAbsent: true);
208 } 221 }
209 222
210 /** 223 /**
(...skipping 10 matching lines...) Expand all
221 unlinkedUnits = serializedLib.unlinkedUnits.map((UnlinkedUnitBuilder b) { 234 unlinkedUnits = serializedLib.unlinkedUnits.map((UnlinkedUnitBuilder b) {
222 List<int> buffer = b.toBuffer(); 235 List<int> buffer = b.toBuffer();
223 return new UnlinkedUnit.fromBuffer(buffer); 236 return new UnlinkedUnit.fromBuffer(buffer);
224 }).toList(); 237 }).toList();
225 unitUris = serializedLib.unitUris; 238 unitUris = serializedLib.unitUris;
226 } 239 }
227 240
228 @override 241 @override
229 void serializeLibraryText(String text, {bool allowErrors: false}) { 242 void serializeLibraryText(String text, {bool allowErrors: false}) {
230 Source source = addSource(text); 243 Source source = addSource(text);
244 _fileContents[source] = text;
231 LibraryElement library = resolve2(source); 245 LibraryElement library = resolve2(source);
232 if (!allowErrors) { 246 if (!allowErrors) {
233 assertNoErrors(source); 247 assertNoErrors(source);
234 } 248 }
235 serializeLibraryElement(library); 249 serializeLibraryElement(library);
236 expect( 250 expect(
237 unlinkedUnits[0].imports.length, prelinked.importDependencies.length); 251 unlinkedUnits[0].imports.length, prelinked.importDependencies.length);
238 expect(prelinked.units.length, unlinkedUnits.length); 252 expect(prelinked.units.length, unlinkedUnits.length);
239 for (int i = 0; i < prelinked.units.length; i++) { 253 for (int i = 0; i < prelinked.units.length; i++) {
240 expect(unlinkedUnits[i].references.length, 254 expect(unlinkedUnits[i].references.length,
(...skipping 16 matching lines...) Expand all
257 expect(cls.hasNoSupertype, isTrue); 271 expect(cls.hasNoSupertype, isTrue);
258 } 272 }
259 273
260 /** 274 /**
261 * Verify that [public_namespace.computePublicNamespace] produces data that's 275 * Verify that [public_namespace.computePublicNamespace] produces data that's
262 * equivalent to that produced by [summarize_elements.serializeLibrary]. 276 * equivalent to that produced by [summarize_elements.serializeLibrary].
263 */ 277 */
264 void verifyPublicNamespace() { 278 void verifyPublicNamespace() {
265 for (int i = 0; i < unlinkedUnits.length; i++) { 279 for (int i = 0; i < unlinkedUnits.length; i++) {
266 Source source = analysisContext.sourceFactory.forUri(unitUris[i]); 280 Source source = analysisContext.sourceFactory.forUri(unitUris[i]);
267 String text = analysisContext.getContents(source).data; 281 String text = _fileContents[source];
268 UnlinkedPublicNamespace namespace = 282 if (text == null) {
269 computePublicNamespaceFromText(text, source); 283 if (!allowMissingFiles) {
270 expect(canonicalize(namespace), 284 fail('Could not find file while verifying public namespace: '
271 canonicalize(unlinkedUnits[i].publicNamespace), 285 '${unitUris[i]}');
272 reason: 'publicNamespace(${unitUris[i]})'); 286 }
287 } else {
288 UnlinkedPublicNamespace namespace =
289 computePublicNamespaceFromText(text, source);
290 expect(canonicalize(namespace),
291 canonicalize(unlinkedUnits[i].publicNamespace),
292 reason: 'publicNamespace(${unitUris[i]})');
293 }
273 } 294 }
274 } 295 }
275 } 296 }
276 297
277 /** 298 /**
278 * Base class containing most summary tests. This allows summary tests to be 299 * Base class containing most summary tests. This allows summary tests to be
279 * re-used to exercise all the different ways in which summaries can be 300 * re-used to exercise all the different ways in which summaries can be
280 * generated (e.g. direct from the AST, from the element model, from a 301 * generated (e.g. direct from the AST, from the element model, from a
281 * "relinking" process, etc.) 302 * "relinking" process, etc.)
282 */ 303 */
(...skipping 2125 matching lines...) Expand 10 before | Expand all | Expand 10 after
2408 expect(unlinkedUnits[0].libraryNameLength, 'foo.bar'.length); 2429 expect(unlinkedUnits[0].libraryNameLength, 'foo.bar'.length);
2409 } 2430 }
2410 2431
2411 test_library_unnamed() { 2432 test_library_unnamed() {
2412 serializeLibraryText(''); 2433 serializeLibraryText('');
2413 expect(unlinkedUnits[0].libraryName, isEmpty); 2434 expect(unlinkedUnits[0].libraryName, isEmpty);
2414 expect(unlinkedUnits[0].libraryNameOffset, 0); 2435 expect(unlinkedUnits[0].libraryNameOffset, 0);
2415 expect(unlinkedUnits[0].libraryNameLength, 0); 2436 expect(unlinkedUnits[0].libraryNameLength, 0);
2416 } 2437 }
2417 2438
2439 test_library_with_missing_part() {
2440 // References to other parts should still be resolved.
2441 allowMissingFiles = true;
2442 addNamedSource('/bar.dart', 'part of my.lib; class C {}');
2443 serializeLibraryText(
2444 'library my.lib; part "foo.dart"; part "bar.dart"; C c;',
2445 allowErrors: true);
2446 checkTypeRef(findVariable('c').type, null, null, 'C',
2447 expectedTargetUnit: 2);
2448 }
2449
2418 test_local_names_take_precedence_over_imported_names() { 2450 test_local_names_take_precedence_over_imported_names() {
2419 addNamedSource('/a.dart', 'class C {} class D {}'); 2451 addNamedSource('/a.dart', 'class C {} class D {}');
2420 serializeLibraryText(''' 2452 serializeLibraryText('''
2421 import 'a.dart'; 2453 import 'a.dart';
2422 class C {} 2454 class C {}
2423 C c; 2455 C c;
2424 D d;'''); 2456 D d;''');
2425 checkTypeRef(findVariable('c').type, null, null, 'C'); 2457 checkTypeRef(findVariable('c').type, null, null, 'C');
2426 checkTypeRef(findVariable('d').type, absUri('/a.dart'), 'a.dart', 'D'); 2458 checkTypeRef(findVariable('d').type, absUri('/a.dart'), 'a.dart', 'D');
2427 } 2459 }
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
2867 UnlinkedVariable variable = 2899 UnlinkedVariable variable =
2868 serializeVariableText('int i;', variableName: 'i'); 2900 serializeVariableText('int i;', variableName: 'i');
2869 checkTypeRef(variable.type, 'dart:core', 'dart:core', 'int'); 2901 checkTypeRef(variable.type, 'dart:core', 'dart:core', 'int');
2870 } 2902 }
2871 2903
2872 test_varible_private() { 2904 test_varible_private() {
2873 serializeVariableText('int _i;', variableName: '_i'); 2905 serializeVariableText('int _i;', variableName: '_i');
2874 expect(unlinkedUnits[0].publicNamespace.names, isEmpty); 2906 expect(unlinkedUnits[0].publicNamespace.names, isEmpty);
2875 } 2907 }
2876 } 2908 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698