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

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

Issue 2389003004: Clean up unnecessary absolute URIs in summary tests. (Closed)
Patch Set: Created 4 years, 2 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 | « pkg/analyzer/test/src/summary/summarize_ast_test.dart ('k') | 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_common; 5 library analyzer.test.src.summary.summary_common;
6 6
7 import 'package:analyzer/analyzer.dart'; 7 import 'package:analyzer/analyzer.dart';
8 import 'package:analyzer/dart/ast/ast.dart'; 8 import 'package:analyzer/dart/ast/ast.dart';
9 import 'package:analyzer/error/listener.dart'; 9 import 'package:analyzer/error/listener.dart';
10 import 'package:analyzer/src/dart/scanner/reader.dart'; 10 import 'package:analyzer/src/dart/scanner/reader.dart';
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 * `part` declarations that deliberately refer to non-existent files. 134 * `part` declarations that deliberately refer to non-existent files.
135 */ 135 */
136 bool allowMissingFiles = false; 136 bool allowMissingFiles = false;
137 137
138 /** 138 /**
139 * Get access to the linked defining compilation unit. 139 * Get access to the linked defining compilation unit.
140 */ 140 */
141 LinkedUnit get definingUnit => linked.units[0]; 141 LinkedUnit get definingUnit => linked.units[0];
142 142
143 /** 143 /**
144 * `true` if the linked portion of the summary is expected to contain
145 * absolute URIs. This happens because the element model doesn't (yet) store
146 * enough information to recover relative URIs, TODO(paulberry): fix this.
147 */
148 bool get expectAbsoluteUrisInDependencies;
149
150 /**
151 * Get access to the linked summary that results from serializing and 144 * Get access to the linked summary that results from serializing and
152 * then deserializing the library under test. 145 * then deserializing the library under test.
153 */ 146 */
154 LinkedLibrary get linked; 147 LinkedLibrary get linked;
155 148
156 /** 149 /**
157 * `true` if the linked portion of the summary only contains prelinked data. 150 * `true` if the linked portion of the summary only contains prelinked data.
158 * This happens because we don't yet have a full linker; only a prelinker. 151 * This happens because we don't yet have a full linker; only a prelinker.
159 */ 152 */
160 bool get skipFullyLinkedData; 153 bool get skipFullyLinkedData;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 : isNot(contains(constCycleSlot))); 203 : isNot(contains(constCycleSlot)));
211 } 204 }
212 } 205 }
213 206
214 /** 207 /**
215 * Verify that the [dependency]th element of the dependency table represents 208 * Verify that the [dependency]th element of the dependency table represents
216 * a file reachable via the given [absoluteUri] and [relativeUri]. 209 * a file reachable via the given [absoluteUri] and [relativeUri].
217 */ 210 */
218 void checkDependency(int dependency, String absoluteUri, String relativeUri) { 211 void checkDependency(int dependency, String absoluteUri, String relativeUri) {
219 expect(dependency, new isInstanceOf<int>()); 212 expect(dependency, new isInstanceOf<int>());
220 if (expectAbsoluteUrisInDependencies) { 213 if (dependency >= linked.numPrelinkedDependencies) {
221 // The element model doesn't (yet) store enough information to recover
222 // relative URIs, so we have to use the absolute URI.
223 // TODO(paulberry): fix this.
224 expect(linked.dependencies[dependency].uri, absoluteUri);
225 } else if (dependency >= linked.numPrelinkedDependencies) {
226 // Fully-linked dependencies are always absolute URIs. 214 // Fully-linked dependencies are always absolute URIs.
227 expect(linked.dependencies[dependency].uri, absoluteUri); 215 expect(linked.dependencies[dependency].uri, absoluteUri);
228 } else { 216 } else {
229 expect(linked.dependencies[dependency].uri, relativeUri); 217 expect(linked.dependencies[dependency].uri, relativeUri);
230 } 218 }
231 } 219 }
232 220
233 /** 221 /**
234 * Verify that the given [dependency] lists the given [absoluteUris] or 222 * Verify that the given [dependency] lists the given
235 * [relativeUris] as its parts. 223 * [relativeUris] as its parts.
236 */ 224 */
237 void checkDependencyParts(LinkedDependency dependency, 225 void checkDependencyParts(
238 List<String> absoluteUris, List<String> relativeUris) { 226 LinkedDependency dependency, List<String> relativeUris) {
239 if (expectAbsoluteUrisInDependencies) {
240 // The element model doesn't (yet) store enough information to recover
241 // relative URIs, so we have to use the absolute URI.
242 // TODO(paulberry): fix this.
243 relativeUris = absoluteUris;
244 }
245 expect(dependency.parts, relativeUris); 227 expect(dependency.parts, relativeUris);
246 } 228 }
247 229
248 /** 230 /**
249 * Check that the given [documentationComment] matches the first 231 * Check that the given [documentationComment] matches the first
250 * Javadoc-style comment found in [text]. 232 * Javadoc-style comment found in [text].
251 * 233 *
252 * Note that the algorithm for finding the Javadoc-style comment in [text] is 234 * Note that the algorithm for finding the Javadoc-style comment in [text] is
253 * a simple-minded text search; it is easily confused by corner cases such as 235 * a simple-minded text search; it is easily confused by corner cases such as
254 * strings containing comments, nested comments, etc. 236 * strings containing comments, nested comments, etc.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 // Exported names must come from other libraries. 270 // Exported names must come from other libraries.
289 expect(exportName.dependency, isNot(0)); 271 expect(exportName.dependency, isNot(0));
290 checkDependency(exportName.dependency, absoluteUri, relativeUri); 272 checkDependency(exportName.dependency, absoluteUri, relativeUri);
291 expect(exportName.name, expectedName); 273 expect(exportName.name, expectedName);
292 expect(exportName.kind, expectedKind); 274 expect(exportName.kind, expectedKind);
293 expect(exportName.unit, expectedTargetUnit); 275 expect(exportName.unit, expectedTargetUnit);
294 } 276 }
295 277
296 /** 278 /**
297 * Verify that the dependency table contains an entry for a file reachable 279 * Verify that the dependency table contains an entry for a file reachable
298 * via the given [absoluteUri] and [relativeUri]. If [fullyLinked] is 280 * via the given [relativeUri]. If [fullyLinked] is
299 * `true`, then the dependency should be a fully-linked dependency; otherwise 281 * `true`, then the dependency should be a fully-linked dependency; otherwise
300 * it should be a prelinked dependency. 282 * it should be a prelinked dependency.
301 * 283 *
302 * The index of the [LinkedDependency] is returned. 284 * The index of the [LinkedDependency] is returned.
303 */ 285 */
304 int checkHasDependency(String absoluteUri, String relativeUri, 286 int checkHasDependency(String relativeUri, {bool fullyLinked: false}) {
305 {bool fullyLinked: false}) {
306 if (expectAbsoluteUrisInDependencies) {
307 // The element model doesn't (yet) store enough information to recover
308 // relative URIs, so we have to use the absolute URI.
309 // TODO(paulberry): fix this.
310 relativeUri = absoluteUri;
311 }
312 List<String> found = <String>[]; 287 List<String> found = <String>[];
313 for (int i = 0; i < linked.dependencies.length; i++) { 288 for (int i = 0; i < linked.dependencies.length; i++) {
314 LinkedDependency dep = linked.dependencies[i]; 289 LinkedDependency dep = linked.dependencies[i];
315 if (dep.uri == relativeUri) { 290 if (dep.uri == relativeUri) {
316 if (fullyLinked) { 291 if (fullyLinked) {
317 expect(i, greaterThanOrEqualTo(linked.numPrelinkedDependencies)); 292 expect(i, greaterThanOrEqualTo(linked.numPrelinkedDependencies));
318 } else { 293 } else {
319 expect(i, lessThan(linked.numPrelinkedDependencies)); 294 expect(i, lessThan(linked.numPrelinkedDependencies));
320 } 295 }
321 return i; 296 return i;
(...skipping 30 matching lines...) Expand all
352 // A slot id should have been assigned but it should not be associated 327 // A slot id should have been assigned but it should not be associated
353 // with any type. 328 // with any type.
354 expect(slotId, isNot(0)); 329 expect(slotId, isNot(0));
355 expect(getTypeRefForSlot(slotId, linkedSourceUnit: linkedSourceUnit), 330 expect(getTypeRefForSlot(slotId, linkedSourceUnit: linkedSourceUnit),
356 isNull); 331 isNull);
357 } 332 }
358 } 333 }
359 334
360 /** 335 /**
361 * Verify that the dependency table *does not* contain any entries for a file 336 * Verify that the dependency table *does not* contain any entries for a file
362 * reachable via the given [absoluteUri] and [relativeUri]. 337 * reachable via the given [relativeUri].
363 */ 338 */
364 void checkLacksDependency(String absoluteUri, String relativeUri) { 339 void checkLacksDependency(String relativeUri) {
365 if (expectAbsoluteUrisInDependencies) {
366 // The element model doesn't (yet) store enough information to recover
367 // relative URIs, so we have to use the absolute URI.
368 // TODO(paulberry): fix this.
369 relativeUri = absoluteUri;
370 }
371 for (LinkedDependency dep in linked.dependencies) { 340 for (LinkedDependency dep in linked.dependencies) {
372 if (dep.uri == relativeUri) { 341 if (dep.uri == relativeUri) {
373 fail('Unexpected dependency found: $relativeUri'); 342 fail('Unexpected dependency found: $relativeUri');
374 } 343 }
375 } 344 }
376 } 345 }
377 346
378 /** 347 /**
379 * Verify that the given [typeRef] represents the type `dynamic`. 348 * Verify that the given [typeRef] represents the type `dynamic`.
380 */ 349 */
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 unlinkedSourceUnit: unlinkedSourceUnit); 582 unlinkedSourceUnit: unlinkedSourceUnit);
614 } 583 }
615 584
616 /** 585 /**
617 * Verify that the given [typeRef] represents the type `void`. 586 * Verify that the given [typeRef] represents the type `void`.
618 */ 587 */
619 void checkVoidTypeRef(EntityRef typeRef) { 588 void checkVoidTypeRef(EntityRef typeRef) {
620 checkTypeRef(typeRef, null, null, 'void'); 589 checkTypeRef(typeRef, null, null, 'void');
621 } 590 }
622 591
592 fail_invalid_prefix_dynamic() {
593 // if (checkAstDerivedData) {
594 // // TODO(paulberry): get this to work properly.
595 // return;
596 // }
597 var t = serializeTypeText('dynamic.T', allowErrors: true);
598 checkUnresolvedTypeRef(t, 'dynamic', 'T');
599 }
600
601 fail_invalid_prefix_type_parameter() {
602 // if (checkAstDerivedData) {
603 // // TODO(paulberry): get this to work properly.
604 // return;
605 // }
606 checkUnresolvedTypeRef(
607 serializeClassText('class C<T> { T.U x; }', allowErrors: true)
608 .fields[0]
609 .type,
610 'T',
611 'U');
612 }
613
614 fail_invalid_prefix_void() {
615 // if (checkAstDerivedData) {
616 // // TODO(paulberry): get this to work properly.
617 // return;
618 // }
619 checkUnresolvedTypeRef(
620 serializeTypeText('void.T', allowErrors: true), 'void', 'T');
621 }
622
623 /** 623 /**
624 * Find the class with the given [className] in the summary, and return its 624 * Find the class with the given [className] in the summary, and return its
625 * [UnlinkedClass] data structure. If [unit] is not given, the class is 625 * [UnlinkedClass] data structure. If [unit] is not given, the class is
626 * looked for in the defining compilation unit. 626 * looked for in the defining compilation unit.
627 */ 627 */
628 UnlinkedClass findClass(String className, 628 UnlinkedClass findClass(String className,
629 {bool failIfAbsent: false, UnlinkedUnit unit}) { 629 {bool failIfAbsent: false, UnlinkedUnit unit}) {
630 unit ??= unlinkedUnits[0]; 630 unit ??= unlinkedUnits[0];
631 UnlinkedClass result; 631 UnlinkedClass result;
632 for (UnlinkedClass cls in unit.classes) { 632 for (UnlinkedClass cls in unit.classes) {
(...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after
1356 addNamedSource('/a.dart', 'class C { D d; } class D {}'); 1356 addNamedSource('/a.dart', 'class C { D d; } class D {}');
1357 // The closure has type `() => D`; `D` is defined in a library that is 1357 // The closure has type `() => D`; `D` is defined in a library that is
1358 // imported. 1358 // imported.
1359 UnlinkedExecutable executable = serializeExecutableText( 1359 UnlinkedExecutable executable = serializeExecutableText(
1360 'import "a.dart"; f() { print((() => new C().d)()); }'); 1360 'import "a.dart"; f() { print((() => new C().d)()); }');
1361 expect(executable.localFunctions, hasLength(1)); 1361 expect(executable.localFunctions, hasLength(1));
1362 expect(executable.localFunctions[0].returnType, isNull); 1362 expect(executable.localFunctions[0].returnType, isNull);
1363 checkInferredTypeSlot(executable.localFunctions[0].inferredReturnTypeSlot, 1363 checkInferredTypeSlot(executable.localFunctions[0].inferredReturnTypeSlot,
1364 absUri('/a.dart'), 'a.dart', 'D', 1364 absUri('/a.dart'), 'a.dart', 'D',
1365 onlyInStrongMode: false); 1365 onlyInStrongMode: false);
1366 checkHasDependency(absUri('/a.dart'), 'a.dart', fullyLinked: false); 1366 checkHasDependency('a.dart', fullyLinked: false);
1367 } 1367 }
1368 1368
1369 test_closure_executable_with_return_type_from_closure() { 1369 test_closure_executable_with_return_type_from_closure() {
1370 if (skipFullyLinkedData) { 1370 if (skipFullyLinkedData) {
1371 return; 1371 return;
1372 } 1372 }
1373 // The closure has type `() => () => int`, where the `() => int` part refers 1373 // The closure has type `() => () => int`, where the `() => int` part refers
1374 // to the nested closure. 1374 // to the nested closure.
1375 UnlinkedExecutable executable = serializeExecutableText(''' 1375 UnlinkedExecutable executable = serializeExecutableText('''
1376 f() { 1376 f() {
(...skipping 24 matching lines...) Expand all
1401 // The closure has type `() => D`; `D` is defined in a library that is not 1401 // The closure has type `() => D`; `D` is defined in a library that is not
1402 // imported. 1402 // imported.
1403 UnlinkedExecutable executable = serializeExecutableText( 1403 UnlinkedExecutable executable = serializeExecutableText(
1404 'import "a.dart"; f() { print((() => new C().d)()); }'); 1404 'import "a.dart"; f() { print((() => new C().d)()); }');
1405 expect(executable.localFunctions, hasLength(1)); 1405 expect(executable.localFunctions, hasLength(1));
1406 expect(executable.localFunctions[0].returnType, isNull); 1406 expect(executable.localFunctions[0].returnType, isNull);
1407 checkInferredTypeSlot(executable.localFunctions[0].inferredReturnTypeSlot, 1407 checkInferredTypeSlot(executable.localFunctions[0].inferredReturnTypeSlot,
1408 absUri('/b.dart'), 'b.dart', 'D', 1408 absUri('/b.dart'), 'b.dart', 'D',
1409 onlyInStrongMode: false); 1409 onlyInStrongMode: false);
1410 if (!skipFullyLinkedData) { 1410 if (!skipFullyLinkedData) {
1411 checkHasDependency(absUri('/b.dart'), 'b.dart', fullyLinked: true); 1411 checkHasDependency('b.dart', fullyLinked: true);
1412 } 1412 }
1413 } 1413 }
1414 1414
1415 test_constExpr_binary_add() { 1415 test_constExpr_binary_add() {
1416 UnlinkedVariable variable = serializeVariableText('const v = 1 + 2;'); 1416 UnlinkedVariable variable = serializeVariableText('const v = 1 + 2;');
1417 _assertUnlinkedConst(variable.initializer.bodyExpr, operators: [ 1417 _assertUnlinkedConst(variable.initializer.bodyExpr, operators: [
1418 UnlinkedConstOperation.pushInt, 1418 UnlinkedConstOperation.pushInt,
1419 UnlinkedConstOperation.pushInt, 1419 UnlinkedConstOperation.pushInt,
1420 UnlinkedConstOperation.add 1420 UnlinkedConstOperation.add
1421 ], ints: [ 1421 ], ints: [
(...skipping 3270 matching lines...) Expand 10 before | Expand all | Expand 10 after
4692 } 4692 }
4693 4693
4694 test_dependencies_export_to_export_unused() { 4694 test_dependencies_export_to_export_unused() {
4695 addNamedSource('/a.dart', 'export "b.dart";'); 4695 addNamedSource('/a.dart', 'export "b.dart";');
4696 addNamedSource('/b.dart', ''); 4696 addNamedSource('/b.dart', '');
4697 serializeLibraryText('export "a.dart";'); 4697 serializeLibraryText('export "a.dart";');
4698 // The main test library depends on b.dart, even though it doesn't 4698 // The main test library depends on b.dart, even though it doesn't
4699 // re-export any names defined in b.dart, because a change to b.dart might 4699 // re-export any names defined in b.dart, because a change to b.dart might
4700 // cause it to start exporting a name that the main test library *does* 4700 // cause it to start exporting a name that the main test library *does*
4701 // use. 4701 // use.
4702 checkHasDependency(absUri('/b.dart'), 'b.dart'); 4702 checkHasDependency('b.dart');
4703 } 4703 }
4704 4704
4705 test_dependencies_export_unused() { 4705 test_dependencies_export_unused() {
4706 addNamedSource('/a.dart', ''); 4706 addNamedSource('/a.dart', '');
4707 serializeLibraryText('export "a.dart";'); 4707 serializeLibraryText('export "a.dart";');
4708 // The main test library depends on a.dart, even though it doesn't 4708 // The main test library depends on a.dart, even though it doesn't
4709 // re-export any names defined in a.dart, because a change to a.dart might 4709 // re-export any names defined in a.dart, because a change to a.dart might
4710 // cause it to start exporting a name that the main test library *will* 4710 // cause it to start exporting a name that the main test library *will*
4711 // re-export. 4711 // re-export.
4712 checkHasDependency(absUri('/a.dart'), 'a.dart'); 4712 checkHasDependency('a.dart');
4713 } 4713 }
4714 4714
4715 test_dependencies_import_to_export() { 4715 test_dependencies_import_to_export() {
4716 addNamedSource('/a.dart', 'library a; export "b.dart"; class A {}'); 4716 addNamedSource('/a.dart', 'library a; export "b.dart"; class A {}');
4717 addNamedSource('/b.dart', 'library b;'); 4717 addNamedSource('/b.dart', 'library b;');
4718 serializeLibraryText('import "a.dart"; A a;'); 4718 serializeLibraryText('import "a.dart"; A a;');
4719 checkHasDependency(absUri('/a.dart'), 'a.dart'); 4719 checkHasDependency('a.dart');
4720 // The main test library depends on b.dart, because names defined in 4720 // The main test library depends on b.dart, because names defined in
4721 // b.dart are exported by a.dart. 4721 // b.dart are exported by a.dart.
4722 checkHasDependency(absUri('/b.dart'), 'b.dart'); 4722 checkHasDependency('b.dart');
4723 } 4723 }
4724 4724
4725 test_dependencies_import_to_export_in_subdirs_absolute_export() { 4725 test_dependencies_import_to_export_in_subdirs_absolute_export() {
4726 addNamedSource('/a/a.dart', 4726 addNamedSource('/a/a.dart',
4727 'library a; export "${absUri('/a/b/b.dart')}"; class A {}'); 4727 'library a; export "${absUri('/a/b/b.dart')}"; class A {}');
4728 addNamedSource('/a/b/b.dart', 'library b;'); 4728 addNamedSource('/a/b/b.dart', 'library b;');
4729 serializeLibraryText('import "a/a.dart"; A a;'); 4729 serializeLibraryText('import "a/a.dart"; A a;');
4730 checkHasDependency(absUri('/a/a.dart'), 'a/a.dart'); 4730 checkHasDependency('a/a.dart');
4731 // The main test library depends on b.dart, because names defined in 4731 // The main test library depends on b.dart, because names defined in
4732 // b.dart are exported by a.dart. 4732 // b.dart are exported by a.dart.
4733 checkHasDependency(absUri('/a/b/b.dart'), absUri('/a/b/b.dart')); 4733 checkHasDependency(absUri('/a/b/b.dart'));
4734 } 4734 }
4735 4735
4736 test_dependencies_import_to_export_in_subdirs_absolute_import() { 4736 test_dependencies_import_to_export_in_subdirs_absolute_import() {
4737 addNamedSource('/a/a.dart', 'library a; export "b/b.dart"; class A {}'); 4737 addNamedSource('/a/a.dart', 'library a; export "b/b.dart"; class A {}');
4738 addNamedSource('/a/b/b.dart', 'library b;'); 4738 addNamedSource('/a/b/b.dart', 'library b;');
4739 serializeLibraryText('import "${absUri('/a/a.dart')}"; A a;'); 4739 serializeLibraryText('import "${absUri('/a/a.dart')}"; A a;');
4740 checkHasDependency(absUri('/a/a.dart'), absUri('/a/a.dart')); 4740 checkHasDependency(absUri('/a/a.dart'));
4741 // The main test library depends on b.dart, because names defined in 4741 // The main test library depends on b.dart, because names defined in
4742 // b.dart are exported by a.dart. 4742 // b.dart are exported by a.dart.
4743 checkHasDependency(absUri('/a/b/b.dart'), absUri('/a/b/b.dart')); 4743 checkHasDependency(absUri('/a/b/b.dart'));
4744 } 4744 }
4745 4745
4746 test_dependencies_import_to_export_in_subdirs_relative() { 4746 test_dependencies_import_to_export_in_subdirs_relative() {
4747 addNamedSource('/a/a.dart', 'library a; export "b/b.dart"; class A {}'); 4747 addNamedSource('/a/a.dart', 'library a; export "b/b.dart"; class A {}');
4748 addNamedSource('/a/b/b.dart', 'library b;'); 4748 addNamedSource('/a/b/b.dart', 'library b;');
4749 serializeLibraryText('import "a/a.dart"; A a;'); 4749 serializeLibraryText('import "a/a.dart"; A a;');
4750 checkHasDependency(absUri('/a/a.dart'), 'a/a.dart'); 4750 checkHasDependency('a/a.dart');
4751 // The main test library depends on b.dart, because names defined in 4751 // The main test library depends on b.dart, because names defined in
4752 // b.dart are exported by a.dart. 4752 // b.dart are exported by a.dart.
4753 checkHasDependency(absUri('/a/b/b.dart'), 'a/b/b.dart'); 4753 checkHasDependency('a/b/b.dart');
4754 } 4754 }
4755 4755
4756 test_dependencies_import_to_export_loop() { 4756 test_dependencies_import_to_export_loop() {
4757 addNamedSource('/a.dart', 'library a; export "b.dart"; class A {}'); 4757 addNamedSource('/a.dart', 'library a; export "b.dart"; class A {}');
4758 addNamedSource('/b.dart', 'library b; export "a.dart";'); 4758 addNamedSource('/b.dart', 'library b; export "a.dart";');
4759 serializeLibraryText('import "a.dart"; A a;'); 4759 serializeLibraryText('import "a.dart"; A a;');
4760 checkHasDependency(absUri('/a.dart'), 'a.dart'); 4760 checkHasDependency('a.dart');
4761 // Serialization should have been able to walk the transitive export 4761 // Serialization should have been able to walk the transitive export
4762 // dependencies to b.dart without going into an infinite loop. 4762 // dependencies to b.dart without going into an infinite loop.
4763 checkHasDependency(absUri('/b.dart'), 'b.dart'); 4763 checkHasDependency('b.dart');
4764 } 4764 }
4765 4765
4766 test_dependencies_import_to_export_transitive_closure() { 4766 test_dependencies_import_to_export_transitive_closure() {
4767 addNamedSource('/a.dart', 'library a; export "b.dart"; class A {}'); 4767 addNamedSource('/a.dart', 'library a; export "b.dart"; class A {}');
4768 addNamedSource('/b.dart', 'library b; export "c.dart";'); 4768 addNamedSource('/b.dart', 'library b; export "c.dart";');
4769 addNamedSource('/c.dart', 'library c;'); 4769 addNamedSource('/c.dart', 'library c;');
4770 serializeLibraryText('import "a.dart"; A a;'); 4770 serializeLibraryText('import "a.dart"; A a;');
4771 checkHasDependency(absUri('/a.dart'), 'a.dart'); 4771 checkHasDependency('a.dart');
4772 // The main test library depends on c.dart, because names defined in 4772 // The main test library depends on c.dart, because names defined in
4773 // c.dart are exported by b.dart and then re-exported by a.dart. 4773 // c.dart are exported by b.dart and then re-exported by a.dart.
4774 checkHasDependency(absUri('/c.dart'), 'c.dart'); 4774 checkHasDependency('c.dart');
4775 } 4775 }
4776 4776
4777 test_dependencies_import_to_export_unused() { 4777 test_dependencies_import_to_export_unused() {
4778 addNamedSource('/a.dart', 'export "b.dart";'); 4778 addNamedSource('/a.dart', 'export "b.dart";');
4779 addNamedSource('/b.dart', ''); 4779 addNamedSource('/b.dart', '');
4780 serializeLibraryText('import "a.dart";', allowErrors: true); 4780 serializeLibraryText('import "a.dart";', allowErrors: true);
4781 // The main test library depends on b.dart, even though it doesn't use any 4781 // The main test library depends on b.dart, even though it doesn't use any
4782 // names defined in b.dart, because a change to b.dart might cause it to 4782 // names defined in b.dart, because a change to b.dart might cause it to
4783 // start exporting a name that the main test library *does* use. 4783 // start exporting a name that the main test library *does* use.
4784 checkHasDependency(absUri('/b.dart'), 'b.dart'); 4784 checkHasDependency('b.dart');
4785 } 4785 }
4786 4786
4787 test_dependencies_import_transitive_closure() { 4787 test_dependencies_import_transitive_closure() {
4788 addNamedSource( 4788 addNamedSource(
4789 '/a.dart', 'library a; import "b.dart"; class A extends B {}'); 4789 '/a.dart', 'library a; import "b.dart"; class A extends B {}');
4790 addNamedSource('/b.dart', 'library b; class B {}'); 4790 addNamedSource('/b.dart', 'library b; class B {}');
4791 serializeLibraryText('import "a.dart"; A a;'); 4791 serializeLibraryText('import "a.dart"; A a;');
4792 checkHasDependency(absUri('/a.dart'), 'a.dart'); 4792 checkHasDependency('a.dart');
4793 // The main test library doesn't depend on b.dart, because no change to 4793 // The main test library doesn't depend on b.dart, because no change to
4794 // b.dart can possibly affect the serialized element model for it. 4794 // b.dart can possibly affect the serialized element model for it.
4795 checkLacksDependency(absUri('/b.dart'), 'b.dart'); 4795 checkLacksDependency('b.dart');
4796 } 4796 }
4797 4797
4798 test_dependencies_import_unused() { 4798 test_dependencies_import_unused() {
4799 addNamedSource('/a.dart', ''); 4799 addNamedSource('/a.dart', '');
4800 serializeLibraryText('import "a.dart";', allowErrors: true); 4800 serializeLibraryText('import "a.dart";', allowErrors: true);
4801 // The main test library depends on a.dart, even though it doesn't use any 4801 // The main test library depends on a.dart, even though it doesn't use any
4802 // names defined in a.dart, because a change to a.dart might cause it to 4802 // names defined in a.dart, because a change to a.dart might cause it to
4803 // start exporting a name that the main test library *does* use. 4803 // start exporting a name that the main test library *does* use.
4804 checkHasDependency(absUri('/a.dart'), 'a.dart'); 4804 checkHasDependency('a.dart');
4805 } 4805 }
4806 4806
4807 test_dependencies_parts() { 4807 test_dependencies_parts() {
4808 addNamedSource( 4808 addNamedSource(
4809 '/a.dart', 'library a; part "b.dart"; part "c.dart"; class A {}'); 4809 '/a.dart', 'library a; part "b.dart"; part "c.dart"; class A {}');
4810 addNamedSource('/b.dart', 'part of a;'); 4810 addNamedSource('/b.dart', 'part of a;');
4811 addNamedSource('/c.dart', 'part of a;'); 4811 addNamedSource('/c.dart', 'part of a;');
4812 serializeLibraryText('import "a.dart"; A a;'); 4812 serializeLibraryText('import "a.dart"; A a;');
4813 int dep = checkHasDependency(absUri('/a.dart'), 'a.dart'); 4813 int dep = checkHasDependency('a.dart');
4814 checkDependencyParts(linked.dependencies[dep], 4814 checkDependencyParts(linked.dependencies[dep], ['b.dart', 'c.dart']);
4815 [absUri('/b.dart'), absUri('/c.dart')], ['b.dart', 'c.dart']);
4816 } 4815 }
4817 4816
4818 test_dependencies_parts_relative_to_importing_library() { 4817 test_dependencies_parts_relative_to_importing_library() {
4819 addNamedSource('/a/b.dart', 'export "c/d.dart";'); 4818 addNamedSource('/a/b.dart', 'export "c/d.dart";');
4820 addNamedSource('/a/c/d.dart', 4819 addNamedSource('/a/c/d.dart',
4821 'library d; part "e/f.dart"; part "g/h.dart"; class D {}'); 4820 'library d; part "e/f.dart"; part "g/h.dart"; class D {}');
4822 addNamedSource('/a/c/e/f.dart', 'part of d;'); 4821 addNamedSource('/a/c/e/f.dart', 'part of d;');
4823 addNamedSource('/a/c/g/h.dart', 'part of d;'); 4822 addNamedSource('/a/c/g/h.dart', 'part of d;');
4824 serializeLibraryText('import "a/b.dart"; D d;'); 4823 serializeLibraryText('import "a/b.dart"; D d;');
4825 int dep = checkHasDependency(absUri('/a/c/d.dart'), 'a/c/d.dart'); 4824 int dep = checkHasDependency('a/c/d.dart');
4826 checkDependencyParts( 4825 checkDependencyParts(
4827 linked.dependencies[dep], 4826 linked.dependencies[dep], ['a/c/e/f.dart', 'a/c/g/h.dart']);
4828 [absUri('/a/c/e/f.dart'), absUri('/a/c/g/h.dart')],
4829 ['a/c/e/f.dart', 'a/c/g/h.dart']);
4830 } 4827 }
4831 4828
4832 test_elements_in_part() { 4829 test_elements_in_part() {
4833 addNamedSource( 4830 addNamedSource(
4834 '/part1.dart', 4831 '/part1.dart',
4835 ''' 4832 '''
4836 part of my.lib; 4833 part of my.lib;
4837 4834
4838 class C {} 4835 class C {}
4839 enum E { v } 4836 enum E { v }
(...skipping 2945 matching lines...) Expand 10 before | Expand all | Expand 10 after
7785 test_implicit_dependencies_follow_other_dependencies() { 7782 test_implicit_dependencies_follow_other_dependencies() {
7786 if (skipFullyLinkedData) { 7783 if (skipFullyLinkedData) {
7787 return; 7784 return;
7788 } 7785 }
7789 addNamedSource('/a.dart', 'import "b.dart"; class C {} D f() => null;'); 7786 addNamedSource('/a.dart', 'import "b.dart"; class C {} D f() => null;');
7790 addNamedSource('/b.dart', 'class D {}'); 7787 addNamedSource('/b.dart', 'class D {}');
7791 serializeLibraryText('import "a.dart"; final x = f(); C y;'); 7788 serializeLibraryText('import "a.dart"; final x = f(); C y;');
7792 // The dependency on b.dart is implicit, so it should be placed at the end 7789 // The dependency on b.dart is implicit, so it should be placed at the end
7793 // of the dependency list, after a.dart, even though the code that refers 7790 // of the dependency list, after a.dart, even though the code that refers
7794 // to b.dart comes before the code that refers to a.dart. 7791 // to b.dart comes before the code that refers to a.dart.
7795 int aDep = 7792 int aDep = checkHasDependency('a.dart', fullyLinked: false);
7796 checkHasDependency(absUri('/a.dart'), 'a.dart', fullyLinked: false); 7793 int bDep = checkHasDependency('b.dart', fullyLinked: true);
7797 int bDep =
7798 checkHasDependency(absUri('/b.dart'), 'b.dart', fullyLinked: true);
7799 expect(aDep, lessThan(bDep)); 7794 expect(aDep, lessThan(bDep));
7800 } 7795 }
7801 7796
7802 test_import_configurations() { 7797 test_import_configurations() {
7803 addNamedSource('/foo.dart', 'bar() {}'); 7798 addNamedSource('/foo.dart', 'bar() {}');
7804 addNamedSource('/foo_io.dart', 'bar() {}'); 7799 addNamedSource('/foo_io.dart', 'bar() {}');
7805 addNamedSource('/foo_html.dart', 'bar() {}'); 7800 addNamedSource('/foo_html.dart', 'bar() {}');
7806 String libraryText = r''' 7801 String libraryText = r'''
7807 import 'foo.dart' 7802 import 'foo.dart'
7808 if (dart.library.io) 'foo_io.dart' 7803 if (dart.library.io) 'foo_io.dart'
(...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after
8372 // The synthetic executable for `v` has type `() => D`; `D` is defined in 8367 // The synthetic executable for `v` has type `() => D`; `D` is defined in
8373 // a library that is imported. Note: `v` is mis-typed as `int` to prevent 8368 // a library that is imported. Note: `v` is mis-typed as `int` to prevent
8374 // type propagation, which would complicate the test. 8369 // type propagation, which would complicate the test.
8375 UnlinkedVariable variable = serializeVariableText( 8370 UnlinkedVariable variable = serializeVariableText(
8376 'import "a.dart"; int v = new C().d;', 8371 'import "a.dart"; int v = new C().d;',
8377 allowErrors: true); 8372 allowErrors: true);
8378 expect(variable.initializer.returnType, isNull); 8373 expect(variable.initializer.returnType, isNull);
8379 checkInferredTypeSlot(variable.initializer.inferredReturnTypeSlot, 8374 checkInferredTypeSlot(variable.initializer.inferredReturnTypeSlot,
8380 absUri('/a.dart'), 'a.dart', 'D', 8375 absUri('/a.dart'), 'a.dart', 'D',
8381 onlyInStrongMode: false); 8376 onlyInStrongMode: false);
8382 checkHasDependency(absUri('/a.dart'), 'a.dart', fullyLinked: false); 8377 checkHasDependency('a.dart', fullyLinked: false);
8383 } 8378 }
8384 8379
8385 test_initializer_executable_with_return_type_from_closure() { 8380 test_initializer_executable_with_return_type_from_closure() {
8386 if (skipFullyLinkedData) { 8381 if (skipFullyLinkedData) {
8387 return; 8382 return;
8388 } 8383 }
8389 // The synthetic executable for `v` has type `() => () => int`, where the 8384 // The synthetic executable for `v` has type `() => () => int`, where the
8390 // `() => int` part refers to the closure declared inside the initializer 8385 // `() => int` part refers to the closure declared inside the initializer
8391 // for v. Note: `v` is mis-typed as `int` to prevent type propagation, 8386 // for v. Note: `v` is mis-typed as `int` to prevent type propagation,
8392 // which would complicate the test. 8387 // which would complicate the test.
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
8483 // a library that is not imported. Note: `v` is mis-typed as `int` to 8478 // a library that is not imported. Note: `v` is mis-typed as `int` to
8484 // prevent type propagation, which would complicate the test. 8479 // prevent type propagation, which would complicate the test.
8485 UnlinkedVariable variable = serializeVariableText( 8480 UnlinkedVariable variable = serializeVariableText(
8486 'import "a.dart"; int v = new C().d;', 8481 'import "a.dart"; int v = new C().d;',
8487 allowErrors: true); 8482 allowErrors: true);
8488 expect(variable.initializer.returnType, isNull); 8483 expect(variable.initializer.returnType, isNull);
8489 checkInferredTypeSlot(variable.initializer.inferredReturnTypeSlot, 8484 checkInferredTypeSlot(variable.initializer.inferredReturnTypeSlot,
8490 absUri('/b.dart'), 'b.dart', 'D', 8485 absUri('/b.dart'), 'b.dart', 'D',
8491 onlyInStrongMode: false); 8486 onlyInStrongMode: false);
8492 if (!skipFullyLinkedData) { 8487 if (!skipFullyLinkedData) {
8493 checkHasDependency(absUri('/b.dart'), 'b.dart', fullyLinked: true); 8488 checkHasDependency('b.dart', fullyLinked: true);
8494 } 8489 }
8495 } 8490 }
8496 8491
8497 fail_invalid_prefix_dynamic() {
8498 // if (checkAstDerivedData) {
8499 // // TODO(paulberry): get this to work properly.
8500 // return;
8501 // }
8502 var t = serializeTypeText('dynamic.T', allowErrors: true);
8503 checkUnresolvedTypeRef(t, 'dynamic', 'T');
8504 }
8505
8506 fail_invalid_prefix_type_parameter() {
8507 // if (checkAstDerivedData) {
8508 // // TODO(paulberry): get this to work properly.
8509 // return;
8510 // }
8511 checkUnresolvedTypeRef(
8512 serializeClassText('class C<T> { T.U x; }', allowErrors: true)
8513 .fields[0]
8514 .type,
8515 'T',
8516 'U');
8517 }
8518
8519 fail_invalid_prefix_void() {
8520 // if (checkAstDerivedData) {
8521 // // TODO(paulberry): get this to work properly.
8522 // return;
8523 // }
8524 checkUnresolvedTypeRef(
8525 serializeTypeText('void.T', allowErrors: true), 'void', 'T');
8526 }
8527
8528 test_library_documented() { 8492 test_library_documented() {
8529 String text = ''' 8493 String text = '''
8530 // Extra comment so doc comment offset != 0 8494 // Extra comment so doc comment offset != 0
8531 /** 8495 /**
8532 * Docs 8496 * Docs
8533 */ 8497 */
8534 library foo;'''; 8498 library foo;''';
8535 serializeLibraryText(text); 8499 serializeLibraryText(text);
8536 expect(unlinkedUnits[0].libraryDocumentationComment, isNotNull); 8500 expect(unlinkedUnits[0].libraryDocumentationComment, isNotNull);
8537 checkDocumentationComment( 8501 checkDocumentationComment(
(...skipping 1799 matching lines...) Expand 10 before | Expand all | Expand 10 after
10337 class _PrefixExpectation { 10301 class _PrefixExpectation {
10338 final ReferenceKind kind; 10302 final ReferenceKind kind;
10339 final String name; 10303 final String name;
10340 final String absoluteUri; 10304 final String absoluteUri;
10341 final String relativeUri; 10305 final String relativeUri;
10342 final int numTypeParameters; 10306 final int numTypeParameters;
10343 10307
10344 _PrefixExpectation(this.kind, this.name, 10308 _PrefixExpectation(this.kind, this.name,
10345 {this.absoluteUri, this.relativeUri, this.numTypeParameters: 0}); 10309 {this.absoluteUri, this.relativeUri, this.numTypeParameters: 0});
10346 } 10310 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/src/summary/summarize_ast_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698