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

Side by Side Diff: pkg/analyzer/test/src/context/context_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: Address comments 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 library test.src.context.context_test; 5 library test.src.context.context_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analyzer/file_system/memory_file_system.dart'; 9 import 'package:analyzer/file_system/memory_file_system.dart';
10 import 'package:analyzer/src/cancelable_future.dart'; 10 import 'package:analyzer/src/cancelable_future.dart';
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 import 'abstract_context.dart'; 48 import 'abstract_context.dart';
49 49
50 main() { 50 main() {
51 groupSep = ' | '; 51 groupSep = ' | ';
52 runReflectiveTests(AnalysisContextImplTest); 52 runReflectiveTests(AnalysisContextImplTest);
53 runReflectiveTests(LimitedInvalidateTest); 53 runReflectiveTests(LimitedInvalidateTest);
54 } 54 }
55 55
56 @reflectiveTest 56 @reflectiveTest
57 class AnalysisContextImplTest extends AbstractContextTest { 57 class AnalysisContextImplTest extends AbstractContextTest {
58 Future fail_analyzedSources_removed() async {
59 AnalyzedSourcesListener listener = new AnalyzedSourcesListener();
60 context.implicitAnalysisEvents.listen(listener.onData);
61 //
62 // Create a file that references an file that is not explicitly being
63 // analyzed and fully analyze it. Ensure that the listener is told about
64 // the implicitly analyzed file.
65 //
66 Source sourceA = newSource('/a.dart', "library a; import 'b.dart';");
67 Source sourceB = newSource('/b.dart', "library b;");
68 ChangeSet changeSet = new ChangeSet();
69 changeSet.addedSource(sourceA);
70 context.applyChanges(changeSet);
71 context.computeErrors(sourceA);
72 await pumpEventQueue();
73 listener.expectAnalyzed(sourceB);
74 //
75 // Remove the reference and ensure that the listener is told that we're no
76 // longer implicitly analyzing the file.
77 //
78 context.setContents(sourceA, "library a;");
79 context.computeErrors(sourceA);
80 await pumpEventQueue();
81 listener.expectNotAnalyzed(sourceB);
82 }
83
58 void fail_performAnalysisTask_importedLibraryDelete_html() { 84 void fail_performAnalysisTask_importedLibraryDelete_html() {
59 // NOTE: This was failing before converting to the new task model. 85 // NOTE: This was failing before converting to the new task model.
60 Source htmlSource = addSource("/page.html", r''' 86 Source htmlSource = addSource("/page.html", r'''
61 <html><body><script type="application/dart"> 87 <html><body><script type="application/dart">
62 import 'libB.dart'; 88 import 'libB.dart';
63 main() {print('hello dart');} 89 main() {print('hello dart');}
64 </script></body></html>'''); 90 </script></body></html>''');
65 Source libBSource = addSource("/libB.dart", "library libB;"); 91 Source libBSource = addSource("/libB.dart", "library libB;");
66 _analyzeAll_assertFinished(); 92 _analyzeAll_assertFinished();
67 context.computeErrors(htmlSource); 93 context.computeErrors(htmlSource);
(...skipping 15 matching lines...) Expand all
83 fail("Implement this"); 109 fail("Implement this");
84 } 110 }
85 111
86 @override 112 @override
87 void tearDown() { 113 void tearDown() {
88 context = null; 114 context = null;
89 sourceFactory = null; 115 sourceFactory = null;
90 super.tearDown(); 116 super.tearDown();
91 } 117 }
92 118
119 Future test_analyzedSources_added() async {
120 AnalyzedSourcesListener listener = new AnalyzedSourcesListener();
121 context.implicitAnalysisEvents.listen(listener.onData);
122 //
123 // Create a file that references an file that is not explicitly being
124 // analyzed and fully analyze it. Ensure that the listener is told about
125 // the implicitly analyzed file.
126 //
127 Source sourceA = newSource('/a.dart', "library a; import 'b.dart';");
128 Source sourceB = newSource('/b.dart', "library b;");
129 ChangeSet changeSet = new ChangeSet();
130 changeSet.addedSource(sourceA);
131 context.applyChanges(changeSet);
132 context.computeErrors(sourceA);
133 await pumpEventQueue();
134 listener.expectAnalyzed(sourceB);
135 }
136
93 Future test_applyChanges_add() { 137 Future test_applyChanges_add() {
94 SourcesChangedListener listener = new SourcesChangedListener(); 138 SourcesChangedListener listener = new SourcesChangedListener();
95 context.onSourcesChanged.listen(listener.onData); 139 context.onSourcesChanged.listen(listener.onData);
96 expect(context.sourcesNeedingProcessing, isEmpty); 140 expect(context.sourcesNeedingProcessing, isEmpty);
97 Source source = newSource('/test.dart'); 141 Source source = newSource('/test.dart');
98 ChangeSet changeSet = new ChangeSet(); 142 ChangeSet changeSet = new ChangeSet();
99 changeSet.addedSource(source); 143 changeSet.addedSource(source);
100 context.applyChanges(changeSet); 144 context.applyChanges(changeSet);
101 expect(context.sourcesNeedingProcessing, contains(source)); 145 expect(context.sourcesNeedingProcessing, contains(source));
102 return pumpEventQueue().then((_) { 146 return pumpEventQueue().then((_) {
(...skipping 2203 matching lines...) Expand 10 before | Expand all | Expand 10 after
2306 } 2350 }
2307 } 2351 }
2308 2352
2309 class _AnalysisContextImplTest_test_applyChanges_removeContainer 2353 class _AnalysisContextImplTest_test_applyChanges_removeContainer
2310 implements SourceContainer { 2354 implements SourceContainer {
2311 Source libB; 2355 Source libB;
2312 _AnalysisContextImplTest_test_applyChanges_removeContainer(this.libB); 2356 _AnalysisContextImplTest_test_applyChanges_removeContainer(this.libB);
2313 @override 2357 @override
2314 bool contains(Source source) => source == libB; 2358 bool contains(Source source) => source == libB;
2315 } 2359 }
OLDNEW
« pkg/analyzer/lib/src/context/context.dart ('K') | « pkg/analyzer/test/src/context/cache_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698