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

Side by Side Diff: pkg/analyzer/test/generated/engine_test.dart

Issue 1239863002: Add hook for listening to implicitly analyzed files (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 5 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 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library engine.engine_test; 8 library engine.engine_test;
9 9
10 import 'dart:async'; 10 import 'dart:async';
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 _context.analysisOptions = options; 238 _context.analysisOptions = options;
239 } 239 }
240 240
241 @override 241 @override
242 void tearDown() { 242 void tearDown() {
243 _context = null; 243 _context = null;
244 _sourceFactory = null; 244 _sourceFactory = null;
245 super.tearDown(); 245 super.tearDown();
246 } 246 }
247 247
248 Future test_analyzedSources_added() async {
249 AnalyzedSourcesListener listener = new AnalyzedSourcesListener();
250 _context.analyzedSources.listen(listener.onData);
251 //
252 // Create a file that references an file that is not explicitly being
253 // analyzed and fully analyze it. Ensure that the listener is told about
254 // the implicitly analyzed file.
255 //
256 Source sourceA = _addSource('/a.dart', "library a; import 'b.dart';");
257 Source sourceB = _createSource('/b.dart', "library b;");
258 _context.computeErrors(sourceA);
259 await pumpEventQueue();
260 listener.expectAnalyzed(sourceB);
261 }
262
248 Future test_applyChanges_add() { 263 Future test_applyChanges_add() {
249 SourcesChangedListener listener = new SourcesChangedListener(); 264 SourcesChangedListener listener = new SourcesChangedListener();
250 _context.onSourcesChanged.listen(listener.onData); 265 _context.onSourcesChanged.listen(listener.onData);
251 expect(_context.sourcesNeedingProcessing.isEmpty, isTrue); 266 expect(_context.sourcesNeedingProcessing.isEmpty, isTrue);
252 Source source = 267 Source source =
253 new FileBasedSource(FileUtilities2.createFile("/test.dart")); 268 new FileBasedSource(FileUtilities2.createFile("/test.dart"));
254 ChangeSet changeSet = new ChangeSet(); 269 ChangeSet changeSet = new ChangeSet();
255 changeSet.addedSource(source); 270 changeSet.addedSource(source);
256 _context.applyChanges(changeSet); 271 _context.applyChanges(changeSet);
257 expect(_context.sourcesNeedingProcessing.contains(source), isTrue); 272 expect(_context.sourcesNeedingProcessing.contains(source), isTrue);
(...skipping 1886 matching lines...) Expand 10 before | Expand all | Expand 10 after
2144 fail("performAnalysisTask failed to terminate after analyzing all sources"); 2159 fail("performAnalysisTask failed to terminate after analyzing all sources");
2145 } 2160 }
2146 2161
2147 void _changeSource(TestSource source, String contents) { 2162 void _changeSource(TestSource source, String contents) {
2148 source.setContents(contents); 2163 source.setContents(contents);
2149 ChangeSet changeSet = new ChangeSet(); 2164 ChangeSet changeSet = new ChangeSet();
2150 changeSet.changedSource(source); 2165 changeSet.changedSource(source);
2151 _context.applyChanges(changeSet); 2166 _context.applyChanges(changeSet);
2152 } 2167 }
2153 2168
2169 Source _createSource(String fileName, String contents) {
2170 Source source = new FileBasedSource(FileUtilities2.createFile(fileName));
2171 _context.setContents(source, contents);
2172 return source;
2173 }
2174
2154 /** 2175 /**
2155 * Search the given compilation unit for a class with the given name. Return t he class with the 2176 * Search the given compilation unit for a class with the given name. Return t he class with the
2156 * given name, or `null` if the class cannot be found. 2177 * given name, or `null` if the class cannot be found.
2157 * 2178 *
2158 * @param unit the compilation unit being searched 2179 * @param unit the compilation unit being searched
2159 * @param className the name of the class being searched for 2180 * @param className the name of the class being searched for
2160 * @return the class with the given name 2181 * @return the class with the given name
2161 */ 2182 */
2162 ClassElement _findClass(CompilationUnitElement unit, String className) { 2183 ClassElement _findClass(CompilationUnitElement unit, String className) {
2163 for (ClassElement classElement in unit.types) { 2184 for (ClassElement classElement in unit.types) {
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
2336 2357
2337 @reflectiveTest 2358 @reflectiveTest
2338 class AnalysisTaskTest extends EngineTestCase { 2359 class AnalysisTaskTest extends EngineTestCase {
2339 void test_perform_exception() { 2360 void test_perform_exception() {
2340 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); 2361 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore();
2341 AnalysisTask task = new AnalysisTask_test_perform_exception(context); 2362 AnalysisTask task = new AnalysisTask_test_perform_exception(context);
2342 task.perform(new TestTaskVisitor<Object>()); 2363 task.perform(new TestTaskVisitor<Object>());
2343 } 2364 }
2344 } 2365 }
2345 2366
2367 /**
2368 * A listener used to gather the [AnalyzedSourcesEvent]s that are produced
2369 * during analysis.
2370 */
2371 class AnalyzedSourcesListener {
2372 /**
2373 * The events that have been gathered.
2374 */
2375 List<AnalyzedSourcesEvent> actualEvents = <AnalyzedSourcesEvent>[];
2376
2377 /**
2378 * The sources that are being implicitly analyzed.
2379 */
2380 List<Source> analyzedSources = <Source>[];
2381
2382 /**
2383 * Assert that the given source is currently being implicitly analyzed.
2384 */
2385 void expectAnalyzed(Source source) {
2386 expect(analyzedSources, contains(source));
2387 }
2388
2389 /**
2390 * Assert that the given source is not currently being implicitly analyzed.
2391 */
2392 void expectNotAnalyzed(Source source) {
2393 expect(analyzedSources, isNot(contains(source)));
2394 }
2395
2396 /**
2397 * Record that the given event was produced.
2398 */
2399 void onData(AnalyzedSourcesEvent event) {
2400 actualEvents.add(event);
2401 if (event.isAnalyzed) {
2402 analyzedSources.add(event.source);
2403 } else {
2404 analyzedSources.remove(event.source);
2405 }
2406 }
2407 }
2408
2346 class CompilationUnitMock extends TypedMock implements CompilationUnit { 2409 class CompilationUnitMock extends TypedMock implements CompilationUnit {
2347 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 2410 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
2348 } 2411 }
2349 2412
2350 @reflectiveTest 2413 @reflectiveTest
2351 class DartEntryTest extends EngineTestCase { 2414 class DartEntryTest extends EngineTestCase {
2352 void test_allErrors() { 2415 void test_allErrors() {
2353 Source source = new TestSource(); 2416 Source source = new TestSource();
2354 DartEntry entry = new DartEntry(); 2417 DartEntry entry = new DartEntry();
2355 expect(entry.allErrors, hasLength(0)); 2418 expect(entry.allErrors, hasLength(0));
(...skipping 3086 matching lines...) Expand 10 before | Expand all | Expand 10 after
5442 } 5505 }
5443 @override 5506 @override
5444 void set analysisOptions(AnalysisOptions options) { 5507 void set analysisOptions(AnalysisOptions options) {
5445 fail("Unexpected invocation of setAnalysisOptions"); 5508 fail("Unexpected invocation of setAnalysisOptions");
5446 } 5509 }
5447 @override 5510 @override
5448 void set analysisPriorityOrder(List<Source> sources) { 5511 void set analysisPriorityOrder(List<Source> sources) {
5449 fail("Unexpected invocation of setAnalysisPriorityOrder"); 5512 fail("Unexpected invocation of setAnalysisPriorityOrder");
5450 } 5513 }
5451 @override 5514 @override
5515 Stream<AnalyzedSourcesEvent> get analyzedSources {
5516 fail("Unexpected invocation of analyzedSources");
5517 return null;
5518 }
5519 @override
5452 set contentCache(ContentCache value) { 5520 set contentCache(ContentCache value) {
5453 fail("Unexpected invocation of setContentCache"); 5521 fail("Unexpected invocation of setContentCache");
5454 } 5522 }
5455 @override 5523 @override
5456 DeclaredVariables get declaredVariables { 5524 DeclaredVariables get declaredVariables {
5457 fail("Unexpected invocation of getDeclaredVariables"); 5525 fail("Unexpected invocation of getDeclaredVariables");
5458 return null; 5526 return null;
5459 } 5527 }
5460 @override 5528 @override
5461 List<AnalysisTarget> get explicitTargets { 5529 List<AnalysisTarget> get explicitTargets {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
5504 @override 5572 @override
5505 Stream<SourcesChangedEvent> get onSourcesChanged { 5573 Stream<SourcesChangedEvent> get onSourcesChanged {
5506 fail("Unexpected invocation of onSourcesChanged"); 5574 fail("Unexpected invocation of onSourcesChanged");
5507 return null; 5575 return null;
5508 } 5576 }
5509 @override 5577 @override
5510 List<Source> get prioritySources { 5578 List<Source> get prioritySources {
5511 fail("Unexpected invocation of getPrioritySources"); 5579 fail("Unexpected invocation of getPrioritySources");
5512 return null; 5580 return null;
5513 } 5581 }
5582
5514 @override 5583 @override
5515 List<AnalysisTarget> get priorityTargets { 5584 List<AnalysisTarget> get priorityTargets {
5516 fail("Unexpected invocation of visitCacheItems"); 5585 fail("Unexpected invocation of visitCacheItems");
5517 return null; 5586 return null;
5518 } 5587 }
5519 5588
5520 @override 5589 @override
5521 CachePartition get privateAnalysisCachePartition { 5590 CachePartition get privateAnalysisCachePartition {
5522 fail("Unexpected invocation of privateAnalysisCachePartition"); 5591 fail("Unexpected invocation of privateAnalysisCachePartition");
5523 return null; 5592 return null;
5524 } 5593 }
5525 5594
5526 @override 5595 @override
5527 ResolverVisitorFactory get resolverVisitorFactory { 5596 ResolverVisitorFactory get resolverVisitorFactory {
5528 fail("Unexpected invocation of getResolverVisitorFactory"); 5597 fail("Unexpected invocation of getResolverVisitorFactory");
5529 return null; 5598 return null;
5530 } 5599 }
5531
5532 @override 5600 @override
5533 SourceFactory get sourceFactory { 5601 SourceFactory get sourceFactory {
5534 fail("Unexpected invocation of getSourceFactory"); 5602 fail("Unexpected invocation of getSourceFactory");
5535 return null; 5603 return null;
5536 } 5604 }
5537 @override 5605 @override
5538 void set sourceFactory(SourceFactory factory) { 5606 void set sourceFactory(SourceFactory factory) {
5539 fail("Unexpected invocation of setSourceFactory"); 5607 fail("Unexpected invocation of setSourceFactory");
5540 } 5608 }
5541 @override 5609 @override
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
5783 @override 5851 @override
5784 Document parseHtmlDocument(Source source) { 5852 Document parseHtmlDocument(Source source) {
5785 fail("Unexpected invocation of parseHtmlDocument"); 5853 fail("Unexpected invocation of parseHtmlDocument");
5786 return null; 5854 return null;
5787 } 5855 }
5788 @override 5856 @override
5789 ht.HtmlUnit parseHtmlUnit(Source source) { 5857 ht.HtmlUnit parseHtmlUnit(Source source) {
5790 fail("Unexpected invocation of parseHtmlUnit"); 5858 fail("Unexpected invocation of parseHtmlUnit");
5791 return null; 5859 return null;
5792 } 5860 }
5861
5793 @override 5862 @override
5794 AnalysisResult performAnalysisTask() { 5863 AnalysisResult performAnalysisTask() {
5795 fail("Unexpected invocation of performAnalysisTask"); 5864 fail("Unexpected invocation of performAnalysisTask");
5796 return null; 5865 return null;
5797 } 5866 }
5798 5867
5799 @override 5868 @override
5800 void recordLibraryElements(Map<Source, LibraryElement> elementMap) { 5869 void recordLibraryElements(Map<Source, LibraryElement> elementMap) {
5801 fail("Unexpected invocation of recordLibraryElements"); 5870 fail("Unexpected invocation of recordLibraryElements");
5802 } 5871 }
(...skipping 22 matching lines...) Expand all
5825 ht.HtmlUnit resolveHtmlUnit(Source htmlSource) { 5894 ht.HtmlUnit resolveHtmlUnit(Source htmlSource) {
5826 fail("Unexpected invocation of resolveHtmlUnit"); 5895 fail("Unexpected invocation of resolveHtmlUnit");
5827 return null; 5896 return null;
5828 } 5897 }
5829 5898
5830 @override 5899 @override
5831 void setChangedContents(Source source, String contents, int offset, 5900 void setChangedContents(Source source, String contents, int offset,
5832 int oldLength, int newLength) { 5901 int oldLength, int newLength) {
5833 fail("Unexpected invocation of setChangedContents"); 5902 fail("Unexpected invocation of setChangedContents");
5834 } 5903 }
5835
5836 @override 5904 @override
5837 void setContents(Source source, String contents) { 5905 void setContents(Source source, String contents) {
5838 fail("Unexpected invocation of setContents"); 5906 fail("Unexpected invocation of setContents");
5839 } 5907 }
5908
5840 @override 5909 @override
5841 bool shouldErrorsBeAnalyzed(Source source, Object entry) { 5910 bool shouldErrorsBeAnalyzed(Source source, Object entry) {
5842 fail("Unexpected invocation of shouldErrorsBeAnalyzed"); 5911 fail("Unexpected invocation of shouldErrorsBeAnalyzed");
5843 return false; 5912 return false;
5844 } 5913 }
5845 5914
5846 @override 5915 @override
5847 void test_flushAstStructures(Source source) { 5916 void test_flushAstStructures(Source source) {
5848 fail("Unexpected invocation of test_flushAstStructures"); 5917 fail("Unexpected invocation of test_flushAstStructures");
5849 } 5918 }
(...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after
6663 @override 6732 @override
6664 bool exists() => true; 6733 bool exists() => true;
6665 } 6734 }
6666 6735
6667 class _UniversalCachePartitionTest_test_setMaxCacheSize 6736 class _UniversalCachePartitionTest_test_setMaxCacheSize
6668 implements CacheRetentionPolicy { 6737 implements CacheRetentionPolicy {
6669 @override 6738 @override
6670 RetentionPriority getAstPriority(Source source, SourceEntry sourceEntry) => 6739 RetentionPriority getAstPriority(Source source, SourceEntry sourceEntry) =>
6671 RetentionPriority.LOW; 6740 RetentionPriority.LOW;
6672 } 6741 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698