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

Side by Side Diff: pkg/analyzer/test/src/context/context_test.dart

Issue 2226613004: Suppress follow-on errors when a file is imported with either a prefix or a show clause (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Cache URI existence in a modifier' Created 4 years, 4 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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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.context.context_test; 5 library analyzer.test.src.context.context_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'package:analyzer/dart/ast/ast.dart'; 10 import 'package:analyzer/dart/ast/ast.dart';
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 CacheEntry entry = context.getCacheEntry(source); 148 CacheEntry entry = context.getCacheEntry(source);
149 expect(entry.explicitlyAdded, isFalse); 149 expect(entry.explicitlyAdded, isFalse);
150 // add the source 150 // add the source
151 ChangeSet changeSet = new ChangeSet(); 151 ChangeSet changeSet = new ChangeSet();
152 changeSet.addedSource(source); 152 changeSet.addedSource(source);
153 context.applyChanges(changeSet); 153 context.applyChanges(changeSet);
154 // now the entry is explicit 154 // now the entry is explicit
155 expect(entry.explicitlyAdded, isTrue); 155 expect(entry.explicitlyAdded, isTrue);
156 } 156 }
157 157
158 void test_applyChanges_addNewImport_invalidateLibraryCycle() {
159 context.analysisOptions =
160 new AnalysisOptionsImpl.from(context.analysisOptions)
161 ..strongMode = true;
162 Source embedder = addSource(
163 '/a.dart',
164 r'''
165 library a;
166 import 'b.dart';
167 //import 'c.dart';
168 ''');
169 addSource(
170 '/b.dart',
171 r'''
172 library b;
173 import 'a.dart';
174 ''');
175 addSource(
176 '/c.dart',
177 r'''
178 library c;
179 import 'b.dart';
180 ''');
181 _performPendingAnalysisTasks();
182 // Add a new import into a.dart, this should invalidate its library cycle.
183 // If it doesn't, we will get a task cycle exception.
184 context.setContents(
185 embedder,
186 r'''
187 library a;
188 import 'b.dart';
189 import 'c.dart';
190 ''');
191 _performPendingAnalysisTasks();
192 expect(context.getCacheEntry(embedder).exception, isNull);
193 }
194
158 Future test_applyChanges_change() { 195 Future test_applyChanges_change() {
159 SourcesChangedListener listener = new SourcesChangedListener(); 196 SourcesChangedListener listener = new SourcesChangedListener();
160 context.onSourcesChanged.listen(listener.onData); 197 context.onSourcesChanged.listen(listener.onData);
161 expect(context.sourcesNeedingProcessing, isEmpty); 198 expect(context.sourcesNeedingProcessing, isEmpty);
162 Source source = newSource('/test.dart'); 199 Source source = newSource('/test.dart');
163 ChangeSet changeSet1 = new ChangeSet(); 200 ChangeSet changeSet1 = new ChangeSet();
164 changeSet1.addedSource(source); 201 changeSet1.addedSource(source);
165 context.applyChanges(changeSet1); 202 context.applyChanges(changeSet1);
166 expect(context.sourcesNeedingProcessing, contains(source)); 203 expect(context.sourcesNeedingProcessing, contains(source));
167 Source source2 = newSource('/test2.dart'); 204 Source source2 = newSource('/test2.dart');
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 expect(importedLibraries, hasLength(2)); 408 expect(importedLibraries, hasLength(2));
372 context.computeErrors(libA); 409 context.computeErrors(libA);
373 context.computeErrors(libB); 410 context.computeErrors(libB);
374 context.setContents(libB, null); 411 context.setContents(libB, null);
375 _removeSource(libB); 412 _removeSource(libB);
376 List<Source> sources = context.sourcesNeedingProcessing; 413 List<Source> sources = context.sourcesNeedingProcessing;
377 expect(sources, hasLength(1)); 414 expect(sources, hasLength(1));
378 expect(sources[0], same(libA)); 415 expect(sources[0], same(libA));
379 libAElement = context.computeLibraryElement(libA); 416 libAElement = context.computeLibraryElement(libA);
380 importedLibraries = libAElement.importedLibraries; 417 importedLibraries = libAElement.importedLibraries;
381 expect(importedLibraries, hasLength(1)); 418 expect(importedLibraries, hasLength(2));
382 return pumpEventQueue().then((_) { 419 return pumpEventQueue().then((_) {
383 listener.assertEvent(wereSourcesAdded: true); 420 listener.assertEvent(wereSourcesAdded: true);
384 listener.assertEvent(wereSourcesAdded: true); 421 listener.assertEvent(wereSourcesAdded: true);
385 listener.assertEvent(wereSourcesRemovedOrDeleted: true); 422 listener.assertEvent(wereSourcesRemovedOrDeleted: true);
386 listener.assertNoMoreEvents(); 423 listener.assertNoMoreEvents();
387 }); 424 });
388 } 425 }
389 426
390 /** 427 /**
391 * IDEA uses the following scenario: 428 * IDEA uses the following scenario:
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 // The reason is that a.dart adds dependencies on (not existing) b.dart 517 // The reason is that a.dart adds dependencies on (not existing) b.dart
481 // results in cache. 518 // results in cache.
482 // Now a.dart does not have errors. 519 // Now a.dart does not have errors.
483 addSource('/b.dart', codeB); 520 addSource('/b.dart', codeB);
484 expect(getErrorsState(a), CacheState.INVALID); 521 expect(getErrorsState(a), CacheState.INVALID);
485 _performPendingAnalysisTasks(); 522 _performPendingAnalysisTasks();
486 expect(getErrorsState(a), CacheState.VALID); 523 expect(getErrorsState(a), CacheState.VALID);
487 expect(context.getErrors(a).errors, hasLength(0)); 524 expect(context.getErrors(a).errors, hasLength(0));
488 } 525 }
489 526
490 void test_applyChanges_addNewImport_invalidateLibraryCycle() {
491 context.analysisOptions =
492 new AnalysisOptionsImpl.from(context.analysisOptions)
493 ..strongMode = true;
494 Source embedder = addSource(
495 '/a.dart',
496 r'''
497 library a;
498 import 'b.dart';
499 //import 'c.dart';
500 ''');
501 addSource(
502 '/b.dart',
503 r'''
504 library b;
505 import 'a.dart';
506 ''');
507 addSource(
508 '/c.dart',
509 r'''
510 library c;
511 import 'b.dart';
512 ''');
513 _performPendingAnalysisTasks();
514 // Add a new import into a.dart, this should invalidate its library cycle.
515 // If it doesn't, we will get a task cycle exception.
516 context.setContents(
517 embedder,
518 r'''
519 library a;
520 import 'b.dart';
521 import 'c.dart';
522 ''');
523 _performPendingAnalysisTasks();
524 expect(context.getCacheEntry(embedder).exception, isNull);
525 }
526
527 void test_cacheConsistencyValidator_computed_deleted() { 527 void test_cacheConsistencyValidator_computed_deleted() {
528 CacheConsistencyValidator validator = context.cacheConsistencyValidator; 528 CacheConsistencyValidator validator = context.cacheConsistencyValidator;
529 var stat = PerformanceStatistics.cacheConsistencyValidationStatistics; 529 var stat = PerformanceStatistics.cacheConsistencyValidationStatistics;
530 stat.reset(); 530 stat.reset();
531 // Add sources. 531 // Add sources.
532 MemoryResourceProvider resourceProvider = new MemoryResourceProvider(); 532 MemoryResourceProvider resourceProvider = new MemoryResourceProvider();
533 String path1 = '/test1.dart'; 533 String path1 = '/test1.dart';
534 String path2 = '/test2.dart'; 534 String path2 = '/test2.dart';
535 Source source1 = resourceProvider.newFile(path1, '// 1-1').createSource(); 535 Source source1 = resourceProvider.newFile(path1, '// 1-1').createSource();
536 Source source2 = resourceProvider.newFile(path2, '// 2-1').createSource(); 536 Source source2 = resourceProvider.newFile(path2, '// 2-1').createSource();
(...skipping 3206 matching lines...) Expand 10 before | Expand all | Expand 10 after
3743 '''); 3743 ''');
3744 _performPendingAnalysisTasks(); 3744 _performPendingAnalysisTasks();
3745 Expression find42() { 3745 Expression find42() {
3746 CompilationUnit unit = 3746 CompilationUnit unit =
3747 context.getResult(new LibrarySpecificUnit(a, a), RESOLVED_UNIT); 3747 context.getResult(new LibrarySpecificUnit(a, a), RESOLVED_UNIT);
3748 ExpressionStatement statement = 3748 ExpressionStatement statement =
3749 AstFinder.getStatementsInTopLevelFunction(unit, 'main').single; 3749 AstFinder.getStatementsInTopLevelFunction(unit, 'main').single;
3750 MethodInvocation invocation = statement.expression; 3750 MethodInvocation invocation = statement.expression;
3751 return invocation.argumentList.arguments[0]; 3751 return invocation.argumentList.arguments[0];
3752 } 3752 }
3753
3753 { 3754 {
3754 Expression argument = find42(); 3755 Expression argument = find42();
3755 expect(argument.staticParameterElement, isNull); 3756 expect(argument.staticParameterElement, isNull);
3756 expect(argument.propagatedParameterElement, isNotNull); 3757 expect(argument.propagatedParameterElement, isNotNull);
3757 } 3758 }
3758 // Update a.dart: add type annotation for 'a'. 3759 // Update a.dart: add type annotation for 'a'.
3759 // '42' has 'staticParameterElement', but not 'propagatedParameterElement'. 3760 // '42' has 'staticParameterElement', but not 'propagatedParameterElement'.
3760 context.setContents( 3761 context.setContents(
3761 a, 3762 a,
3762 r''' 3763 r'''
(...skipping 1418 matching lines...) Expand 10 before | Expand all | Expand 10 after
5181 * Initialize the visitor. 5182 * Initialize the visitor.
5182 */ 5183 */
5183 _ElementGatherer(); 5184 _ElementGatherer();
5184 5185
5185 @override 5186 @override
5186 void visitElement(Element element) { 5187 void visitElement(Element element) {
5187 elements[element] = element; 5188 elements[element] = element;
5188 super.visitElement(element); 5189 super.visitElement(element);
5189 } 5190 }
5190 } 5191 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698