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

Unified Diff: packages/analyzer/test/src/task/dart_work_manager_test.dart

Issue 2990843002: Removed fixed dependencies (Closed)
Patch Set: Created 3 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
« no previous file with comments | « packages/analyzer/test/src/task/dart_test.dart ('k') | packages/analyzer/test/src/task/driver_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: packages/analyzer/test/src/task/dart_work_manager_test.dart
diff --git a/packages/analyzer/test/src/task/dart_work_manager_test.dart b/packages/analyzer/test/src/task/dart_work_manager_test.dart
index 8dd7dbc87f06318f3cc8a1958073486f98c4d17b..2927305eaf7309702e96c1a7df8e0567195e7a4c 100644
--- a/packages/analyzer/test/src/task/dart_work_manager_test.dart
+++ b/packages/analyzer/test/src/task/dart_work_manager_test.dart
@@ -2,20 +2,21 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-library test.src.task.dart_work_manager_test;
+library analyzer.test.src.task.dart_work_manager_test;
+import 'package:analyzer/dart/ast/ast.dart';
+import 'package:analyzer/error/error.dart' show AnalysisError;
+import 'package:analyzer/exception/exception.dart';
import 'package:analyzer/src/context/cache.dart';
-import 'package:analyzer/src/generated/ast.dart';
+import 'package:analyzer/src/dart/scanner/scanner.dart' show ScannerErrorCode;
import 'package:analyzer/src/generated/engine.dart'
show
- AnalysisErrorInfo,
AnalysisErrorInfoImpl,
+ AnalysisOptions,
+ AnalysisOptionsImpl,
CacheState,
ChangeNoticeImpl,
InternalAnalysisContext;
-import 'package:analyzer/src/generated/error.dart' show AnalysisError;
-import 'package:analyzer/src/generated/java_engine.dart' show CaughtException;
-import 'package:analyzer/src/generated/scanner.dart' show ScannerErrorCode;
import 'package:analyzer/src/generated/sdk.dart';
import 'package:analyzer/src/generated/source.dart';
import 'package:analyzer/src/generated/testing/ast_factory.dart';
@@ -24,16 +25,16 @@ import 'package:analyzer/src/task/dart_work_manager.dart';
import 'package:analyzer/task/dart.dart';
import 'package:analyzer/task/general.dart';
import 'package:analyzer/task/model.dart';
+import 'package:test_reflective_loader/test_reflective_loader.dart';
import 'package:typed_mock/typed_mock.dart';
import 'package:unittest/unittest.dart';
import '../../generated/test_support.dart';
-import '../../reflective_tests.dart';
import '../../utils.dart';
main() {
initializeTestEnvironment();
- runReflectiveTests(DartWorkManagerTest);
+ defineReflectiveTests(DartWorkManagerTest);
}
@reflectiveTest
@@ -64,10 +65,10 @@ class DartWorkManagerTest {
void setUp() {
cache = context.analysisCache;
manager = new DartWorkManager(context);
- entry1 = context.getCacheEntry(source1);
- entry2 = context.getCacheEntry(source2);
- entry3 = context.getCacheEntry(source3);
- entry4 = context.getCacheEntry(source4);
+ entry1 = _getOrCreateEntry(source1);
+ entry2 = _getOrCreateEntry(source2);
+ entry3 = _getOrCreateEntry(source3);
+ entry4 = _getOrCreateEntry(source4);
}
void test_applyChange_add() {
@@ -107,6 +108,21 @@ class DartWorkManagerTest {
expect_unknownSourceQueue([source4, source1]);
}
+ /**
+ * When we perform limited invalidation, we keep [SOURCE_KIND] valid. So, we
+ * don't need to put such sources into [DartWorkManager.unknownSourceQueue],
+ * and remove from [DartWorkManager.librarySourceQueue].
+ */
+ void test_applyChange_change_hasSourceKind() {
+ entry1.setValue(SOURCE_KIND, SourceKind.LIBRARY, []);
+ manager.librarySourceQueue.addAll([source1, source2]);
+ manager.unknownSourceQueue.addAll([source3]);
+ // change source1
+ manager.applyChange([], [source1, source2], []);
+ expect_librarySourceQueue([source1]);
+ expect_unknownSourceQueue([source2, source3]);
+ }
+
void test_applyChange_remove() {
manager.librarySourceQueue.addAll([source1, source3]);
manager.unknownSourceQueue.addAll([source4]);
@@ -210,8 +226,8 @@ class DartWorkManagerTest {
}
void test_applyPriorityTargets_isLibrary_computeErrors() {
- when(context.shouldErrorsBeAnalyzed(source2, null)).thenReturn(true);
- when(context.shouldErrorsBeAnalyzed(source3, null)).thenReturn(true);
+ when(context.shouldErrorsBeAnalyzed(source2)).thenReturn(true);
+ when(context.shouldErrorsBeAnalyzed(source3)).thenReturn(true);
entry1.setValue(SOURCE_KIND, SourceKind.LIBRARY, []);
entry2.setValue(SOURCE_KIND, SourceKind.LIBRARY, []);
entry3.setValue(SOURCE_KIND, SourceKind.LIBRARY, []);
@@ -234,8 +250,8 @@ class DartWorkManagerTest {
}
void test_applyPriorityTargets_isLibrary_computeUnit() {
- when(context.shouldErrorsBeAnalyzed(source2, null)).thenReturn(false);
- when(context.shouldErrorsBeAnalyzed(source3, null)).thenReturn(false);
+ when(context.shouldErrorsBeAnalyzed(source2)).thenReturn(false);
+ when(context.shouldErrorsBeAnalyzed(source3)).thenReturn(false);
entry1.setValue(SOURCE_KIND, SourceKind.LIBRARY, []);
entry2.setValue(SOURCE_KIND, SourceKind.LIBRARY, []);
entry3.setValue(SOURCE_KIND, SourceKind.LIBRARY, []);
@@ -315,6 +331,7 @@ class DartWorkManagerTest {
}
void test_getLibrariesContainingPart() {
+ when(context.aboutToComputeResult(anyObject, anyObject)).thenReturn(false);
Source part1 = new TestSource('part1.dart');
Source part2 = new TestSource('part2.dart');
Source part3 = new TestSource('part3.dart');
@@ -332,6 +349,35 @@ class DartWorkManagerTest {
expect(manager.getLibrariesContainingPart(part3), isEmpty);
}
+ void test_getLibrariesContainingPart_askResultProvider() {
+ Source part1 = new TestSource('part1.dart');
+ Source part2 = new TestSource('part2.dart');
+ Source part3 = new TestSource('part3.dart');
+ Source library1 = new TestSource('library1.dart');
+ Source library2 = new TestSource('library2.dart');
+ // configure AnalysisContext mock
+ when(context.aboutToComputeResult(anyObject, CONTAINING_LIBRARIES))
+ .thenInvoke((CacheEntry entry, ResultDescriptor result) {
+ if (entry.target == part1) {
+ entry.setValue(result as ResultDescriptor<List<Source>>,
+ <Source>[library1, library2], []);
+ return true;
+ }
+ if (entry.target == part2) {
+ entry.setValue(
+ result as ResultDescriptor<List<Source>>, <Source>[library2], []);
+ return true;
+ }
+ return false;
+ });
+ // getLibrariesContainingPart
+ expect(manager.getLibrariesContainingPart(part1),
+ unorderedEquals([library1, library2]));
+ expect(
+ manager.getLibrariesContainingPart(part2), unorderedEquals([library2]));
+ expect(manager.getLibrariesContainingPart(part3), isEmpty);
+ }
+
void test_getLibrariesContainingPart_inSDK() {
Source part = new _SourceMock('part.dart');
when(part.isInSystemLibrary).thenReturn(true);
@@ -509,6 +555,8 @@ class DartWorkManagerTest {
}
void test_onResultInvalidated_scheduleInvalidatedLibraries() {
+ // make source3 implicit
+ entry3.explicitlyAdded = false;
// set SOURCE_KIND
entry1.setValue(SOURCE_KIND, SourceKind.LIBRARY, []);
entry2.setValue(SOURCE_KIND, SourceKind.PART, []);
@@ -519,9 +567,9 @@ class DartWorkManagerTest {
// invalidate LIBRARY_ERRORS_READY for source1, schedule it
entry1.setState(LIBRARY_ERRORS_READY, CacheState.INVALID);
expect_librarySourceQueue([source1]);
- // invalidate LIBRARY_ERRORS_READY for source3, schedule it
+ // invalidate LIBRARY_ERRORS_READY for source3, implicit, not scheduled
entry3.setState(LIBRARY_ERRORS_READY, CacheState.INVALID);
- expect_librarySourceQueue([source1, source3]);
+ expect_librarySourceQueue([source1]);
}
void test_onSourceFactoryChanged() {
@@ -532,6 +580,8 @@ class DartWorkManagerTest {
entry1.setValue(EXPLICITLY_IMPORTED_LIBRARIES, <Source>[], []);
entry1.setValue(EXPORTED_LIBRARIES, <Source>[], []);
entry1.setValue(INCLUDED_PARTS, <Source>[], []);
+ entry1.setValue(LIBRARY_SPECIFIC_UNITS, <LibrarySpecificUnit>[], []);
+ entry1.setValue(UNITS, <Source>[], []);
// configure LibrarySpecificUnit
LibrarySpecificUnit unitTarget = new LibrarySpecificUnit(source2, source3);
CacheEntry unitEntry = new CacheEntry(unitTarget);
@@ -548,6 +598,8 @@ class DartWorkManagerTest {
expect(entry1.getState(EXPLICITLY_IMPORTED_LIBRARIES), CacheState.INVALID);
expect(entry1.getState(EXPORTED_LIBRARIES), CacheState.INVALID);
expect(entry1.getState(INCLUDED_PARTS), CacheState.INVALID);
+ expect(entry1.getState(LIBRARY_SPECIFIC_UNITS), CacheState.INVALID);
+ expect(entry1.getState(UNITS), CacheState.INVALID);
}
void test_resultsComputed_errors_forLibrarySpecificUnit() {
@@ -587,8 +639,8 @@ class DartWorkManagerTest {
entry1.setValue(SCAN_ERRORS, <AnalysisError>[error1], []);
entry1.setValue(PARSE_ERRORS, <AnalysisError>[error2], []);
// PARSED_UNIT is ready, set errors
- manager.resultsComputed(
- source1, {PARSED_UNIT: AstFactory.compilationUnit()});
+ manager
+ .resultsComputed(source1, {PARSED_UNIT: AstFactory.compilationUnit()});
// all of the errors are included
ChangeNoticeImpl notice = context.getNotice(source1);
expect(notice.errors, unorderedEquals([error1, error2]));
@@ -605,10 +657,9 @@ class DartWorkManagerTest {
expect(cache.getState(part1, CONTAINING_LIBRARIES), CacheState.VALID);
// configure AnalysisContext mock
when(context.prioritySources).thenReturn(<Source>[]);
- when(context.shouldErrorsBeAnalyzed(anyObject, anyObject))
- .thenReturn(false);
+ when(context.shouldErrorsBeAnalyzed(anyObject)).thenReturn(false);
// library1 parts
- manager.resultsComputed(library1, {
+ manager.resultsComputed(library1, <ResultDescriptor, dynamic>{
INCLUDED_PARTS: [part1, part2],
SOURCE_KIND: SourceKind.LIBRARY
});
@@ -618,7 +669,7 @@ class DartWorkManagerTest {
expect(manager.libraryPartsMap[library1], [part1, part2]);
expect(manager.libraryPartsMap[library2], isNull);
// library2 parts
- manager.resultsComputed(library2, {
+ manager.resultsComputed(library2, <ResultDescriptor, dynamic>{
INCLUDED_PARTS: [part2, part3],
SOURCE_KIND: SourceKind.LIBRARY
});
@@ -699,7 +750,7 @@ class DartWorkManagerTest {
void test_resultsComputed_sourceKind_isLibrary() {
manager.unknownSourceQueue.addAll([source1, source2, source3]);
when(context.prioritySources).thenReturn(<Source>[]);
- when(context.shouldErrorsBeAnalyzed(source2, null)).thenReturn(true);
+ when(context.shouldErrorsBeAnalyzed(source2)).thenReturn(true);
manager.resultsComputed(source2, {SOURCE_KIND: SourceKind.LIBRARY});
expect_librarySourceQueue([source2]);
expect_unknownSourceQueue([source1, source3]);
@@ -708,7 +759,7 @@ class DartWorkManagerTest {
void test_resultsComputed_sourceKind_isLibrary_isPriority_computeErrors() {
manager.unknownSourceQueue.addAll([source1, source2, source3]);
when(context.prioritySources).thenReturn(<Source>[source2]);
- when(context.shouldErrorsBeAnalyzed(source2, null)).thenReturn(true);
+ when(context.shouldErrorsBeAnalyzed(source2)).thenReturn(true);
manager.resultsComputed(source2, {SOURCE_KIND: SourceKind.LIBRARY});
expect_unknownSourceQueue([source1, source3]);
expect(manager.priorityResultQueue,
@@ -718,7 +769,7 @@ class DartWorkManagerTest {
void test_resultsComputed_sourceKind_isLibrary_isPriority_computeUnit() {
manager.unknownSourceQueue.addAll([source1, source2, source3]);
when(context.prioritySources).thenReturn(<Source>[source2]);
- when(context.shouldErrorsBeAnalyzed(source2, null)).thenReturn(false);
+ when(context.shouldErrorsBeAnalyzed(source2)).thenReturn(false);
manager.resultsComputed(source2, {SOURCE_KIND: SourceKind.LIBRARY});
expect_unknownSourceQueue([source1, source3]);
expect(
@@ -740,28 +791,32 @@ class DartWorkManagerTest {
Source part = new TestSource('part.dart');
expect(manager.libraryPartsMap, isEmpty);
// part.dart parsed, no changes is the map of libraries
- manager.resultsComputed(
- part, {SOURCE_KIND: SourceKind.PART, INCLUDED_PARTS: <Source>[]});
+ manager.resultsComputed(part, <ResultDescriptor, dynamic>{
+ SOURCE_KIND: SourceKind.PART,
+ INCLUDED_PARTS: <Source>[]
+ });
expect(manager.libraryPartsMap, isEmpty);
}
- CacheEntry _getOrCreateEntry(Source source) {
+ void test_unitIncrementallyResolved() {
+ manager.unitIncrementallyResolved(source1, source2);
+ expect_librarySourceQueue([source1]);
+ }
+
+ CacheEntry _getOrCreateEntry(Source source, [bool explicit = true]) {
CacheEntry entry = cache.get(source);
if (entry == null) {
entry = new CacheEntry(source);
+ entry.explicitlyAdded = explicit;
cache.put(entry);
}
return entry;
}
}
-class _DartSdkMock extends TypedMock implements DartSdk {
- noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
-}
+class _DartSdkMock extends TypedMock implements DartSdk {}
-class _DartWorkManagerMock extends TypedMock implements DartWorkManager {
- noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
-}
+class _DartWorkManagerMock extends TypedMock implements DartWorkManager {}
class _InternalAnalysisContextMock extends TypedMock
implements InternalAnalysisContext {
@@ -773,9 +828,19 @@ class _InternalAnalysisContextMock extends TypedMock
Map<Source, ChangeNoticeImpl> _pendingNotices = <Source, ChangeNoticeImpl>{};
+ @override
+ final AnalysisOptions analysisOptions = new AnalysisOptionsImpl();
+
+ @override
+ final ReentrantSynchronousStream<InvalidatedResult> onResultInvalidated =
+ new ReentrantSynchronousStream<InvalidatedResult>();
+
_InternalAnalysisContextMock() {
privateAnalysisCachePartition = new UniversalCachePartition(this);
analysisCache = new AnalysisCache([privateAnalysisCachePartition]);
+ analysisCache.onResultInvalidated.listen((InvalidatedResult event) {
+ onResultInvalidated.add(event);
+ });
}
@override
@@ -793,20 +858,15 @@ class _InternalAnalysisContextMock extends TypedMock
return _pendingNotices.putIfAbsent(
source, () => new ChangeNoticeImpl(source));
}
-
- noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
}
-class _SourceFactoryMock extends TypedMock implements SourceFactory {
- noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
-}
+class _SourceFactoryMock extends TypedMock implements SourceFactory {}
class _SourceMock extends TypedMock implements Source {
final String shortName;
_SourceMock(this.shortName);
@override
String get fullName => '/' + shortName;
- noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
@override
String toString() => fullName;
}
« no previous file with comments | « packages/analyzer/test/src/task/dart_test.dart ('k') | packages/analyzer/test/src/task/driver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698