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

Unified 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: 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 side-by-side diff with in-line comments
Download patch
Index: pkg/analyzer/test/generated/engine_test.dart
diff --git a/pkg/analyzer/test/generated/engine_test.dart b/pkg/analyzer/test/generated/engine_test.dart
index feb01db1463b16b70463307227104e35c205d42a..cdb97acdb5dad98356b68e84094e212e7905b1dd 100644
--- a/pkg/analyzer/test/generated/engine_test.dart
+++ b/pkg/analyzer/test/generated/engine_test.dart
@@ -245,6 +245,21 @@ class AnalysisContextImplTest extends EngineTestCase {
super.tearDown();
}
+ Future test_analyzedSources_added() async {
+ AnalyzedSourcesListener listener = new AnalyzedSourcesListener();
+ _context.implicitAnalysisEvents.listen(listener.onData);
+ //
+ // Create a file that references an file that is not explicitly being
+ // analyzed and fully analyze it. Ensure that the listener is told about
+ // the implicitly analyzed file.
+ //
+ Source sourceA = _addSource('/a.dart', "library a; import 'b.dart';");
+ Source sourceB = _createSource('/b.dart', "library b;");
+ _context.computeErrors(sourceA);
+ await pumpEventQueue();
+ listener.expectAnalyzed(sourceB);
+ }
+
Future test_applyChanges_add() {
SourcesChangedListener listener = new SourcesChangedListener();
_context.onSourcesChanged.listen(listener.onData);
@@ -2151,6 +2166,12 @@ library test2;''');
_context.applyChanges(changeSet);
}
+ Source _createSource(String fileName, String contents) {
+ Source source = new FileBasedSource(FileUtilities2.createFile(fileName));
+ _context.setContents(source, contents);
+ return source;
+ }
+
/**
* Search the given compilation unit for a class with the given name. Return the class with the
* given name, or `null` if the class cannot be found.
@@ -2343,6 +2364,48 @@ class AnalysisTaskTest extends EngineTestCase {
}
}
+/**
+ * A listener used to gather the [ImplicitAnalysisEvent]s that are produced
+ * during analysis.
+ */
+class AnalyzedSourcesListener {
+ /**
+ * The events that have been gathered.
+ */
+ List<ImplicitAnalysisEvent> actualEvents = <ImplicitAnalysisEvent>[];
+
+ /**
+ * The sources that are being implicitly analyzed.
+ */
+ List<Source> analyzedSources = <Source>[];
+
+ /**
+ * Assert that the given source is currently being implicitly analyzed.
+ */
+ void expectAnalyzed(Source source) {
+ expect(analyzedSources, contains(source));
+ }
+
+ /**
+ * Assert that the given source is not currently being implicitly analyzed.
+ */
+ void expectNotAnalyzed(Source source) {
+ expect(analyzedSources, isNot(contains(source)));
+ }
+
+ /**
+ * Record that the given event was produced.
+ */
+ void onData(ImplicitAnalysisEvent event) {
+ actualEvents.add(event);
+ if (event.isAnalyzed) {
+ analyzedSources.add(event.source);
+ } else {
+ analyzedSources.remove(event.source);
+ }
+ }
+}
+
class CompilationUnitMock extends TypedMock implements CompilationUnit {
noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
}
@@ -5468,6 +5531,11 @@ class TestAnalysisContext implements InternalAnalysisContext {
return null;
}
@override
+ Stream<ImplicitAnalysisEvent> get implicitAnalysisEvents {
+ fail("Unexpected invocation of analyzedSources");
+ return null;
+ }
+ @override
bool get isDisposed {
fail("Unexpected invocation of isDisposed");
return false;
@@ -5511,6 +5579,7 @@ class TestAnalysisContext implements InternalAnalysisContext {
fail("Unexpected invocation of getPrioritySources");
return null;
}
+
@override
List<AnalysisTarget> get priorityTargets {
fail("Unexpected invocation of visitCacheItems");
@@ -5528,7 +5597,6 @@ class TestAnalysisContext implements InternalAnalysisContext {
fail("Unexpected invocation of getResolverVisitorFactory");
return null;
}
-
@override
SourceFactory get sourceFactory {
fail("Unexpected invocation of getSourceFactory");
@@ -5790,6 +5858,7 @@ class TestAnalysisContext implements InternalAnalysisContext {
fail("Unexpected invocation of parseHtmlUnit");
return null;
}
+
@override
AnalysisResult performAnalysisTask() {
fail("Unexpected invocation of performAnalysisTask");
@@ -5832,11 +5901,11 @@ class TestAnalysisContext implements InternalAnalysisContext {
int oldLength, int newLength) {
fail("Unexpected invocation of setChangedContents");
}
-
@override
void setContents(Source source, String contents) {
fail("Unexpected invocation of setContents");
}
+
@override
bool shouldErrorsBeAnalyzed(Source source, Object entry) {
fail("Unexpected invocation of shouldErrorsBeAnalyzed");

Powered by Google App Engine
This is Rietveld 408576698