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

Unified Diff: pkg/analysis_server/test/context_manager_test.dart

Issue 1223413003: Hook for overriding the ContextManager and some code clean-up (with more to follow) (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 side-by-side diff with in-line comments
Download patch
Index: pkg/analysis_server/test/context_manager_test.dart
diff --git a/pkg/analysis_server/test/context_manager_test.dart b/pkg/analysis_server/test/context_manager_test.dart
index 092fc85875a0d9167faad3b7353a95d581904b65..1623924dd68c85e543388ae2ca7b8b7ccb57cba7 100644
--- a/pkg/analysis_server/test/context_manager_test.dart
+++ b/pkg/analysis_server/test/context_manager_test.dart
@@ -8,6 +8,7 @@ import 'dart:collection';
import 'package:analysis_server/src/context_manager.dart';
import 'package:analysis_server/src/source/optimizing_pub_package_map_provider.dart';
+import 'package:analysis_server/uri/resolver_provider.dart';
import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/file_system/memory_file_system.dart';
import 'package:analyzer/instrumentation/instrumentation.dart';
@@ -20,15 +21,14 @@ import 'package:test_reflective_loader/test_reflective_loader.dart';
import 'package:unittest/unittest.dart';
import 'mocks.dart';
-import 'package:analysis_server/uri/resolver_provider.dart';
main() {
groupSep = ' | ';
- defineReflectiveTests(ContextManagerTest);
+ defineReflectiveTests(AbstractContextManagerTest);
}
@reflectiveTest
-class ContextManagerTest {
+class AbstractContextManagerTest {
/**
* The name of the 'bin' directory.
*/
@@ -83,7 +83,8 @@ class ContextManagerTest {
void setUp() {
resourceProvider = new MemoryResourceProvider();
packageMapProvider = new MockPackageMapProvider();
- manager = new TestContextManager(resourceProvider, providePackageResolver, packageMapProvider);
+ manager = new TestContextManager(
+ resourceProvider, providePackageResolver, packageMapProvider);
resourceProvider.newFolder(projPath);
}
@@ -202,7 +203,8 @@ class ContextManagerTest {
var filePaths = manager.currentContextFilePaths[projPath];
expect(filePaths, hasLength(1));
expect(filePaths, contains(filePath));
- List<AnalysisContext> contextsInAnalysisRoot = manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath));
+ List<AnalysisContext> contextsInAnalysisRoot =
+ manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath));
expect(contextsInAnalysisRoot, hasLength(1));
AnalysisContext context = contextsInAnalysisRoot[0];
expect(context, isNotNull);
@@ -211,22 +213,6 @@ class ContextManagerTest {
expect(result.exists(), isFalse);
}
- void test_setRoots_packageResolver() {
- Uri uri = Uri.parse('package:foo/foo.dart');
- Source source = new TestSource();
- packageResolver = new TestUriResolver({uri : source});
- String filePath = posix.join(projPath, 'foo.dart');
- resourceProvider.newFile(filePath, 'contents');
- manager.setRoots(<String>[projPath], <String>[], <String, String>{});
-
- List<AnalysisContext> contextsInAnalysisRoot = manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath));
- expect(contextsInAnalysisRoot, hasLength(1));
- AnalysisContext context = contextsInAnalysisRoot[0];
- expect(context, isNotNull);
- Source result = context.sourceFactory.forUri2(uri);
- expect(result, same(source));
- }
-
void test_setRoots_addFolderWithDartFileInSubfolder() {
String filePath = posix.join(projPath, 'foo', 'bar.dart');
resourceProvider.newFile(filePath, 'contents');
@@ -250,9 +236,9 @@ class ContextManagerTest {
String examplePath = newFolder([projPath, EXAMPLE_NAME]);
String libPath = newFolder([projPath, LIB_NAME]);
- newFile([projPath, PUBSPEC_NAME]);
+ newFile([projPath, AbstractContextManager.PUBSPEC_NAME]);
newFile([libPath, 'main.dart']);
- newFile([examplePath, PUBSPEC_NAME]);
+ newFile([examplePath, AbstractContextManager.PUBSPEC_NAME]);
newFile([examplePath, 'example.dart']);
packageMapProvider.packageMap['proj'] =
@@ -299,7 +285,7 @@ class ContextManagerTest {
String srcPath = newFolder([libPath, SRC_NAME]);
String testPath = newFolder([projPath, TEST_NAME]);
- newFile([projPath, PUBSPEC_NAME]);
+ newFile([projPath, AbstractContextManager.PUBSPEC_NAME]);
String appPath = newFile([binPath, 'app.dart']);
newFile([libPath, 'main.dart']);
newFile([srcPath, 'internal.dart']);
@@ -526,6 +512,23 @@ class ContextManagerTest {
_checkPackageMap(projPath, equals(packageMapProvider.packageMap));
}
+ void test_setRoots_packageResolver() {
+ Uri uri = Uri.parse('package:foo/foo.dart');
+ Source source = new TestSource();
+ packageResolver = new TestUriResolver({uri: source});
+ String filePath = posix.join(projPath, 'foo.dart');
+ resourceProvider.newFile(filePath, 'contents');
+ manager.setRoots(<String>[projPath], <String>[], <String, String>{});
+
+ List<AnalysisContext> contextsInAnalysisRoot =
+ manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath));
+ expect(contextsInAnalysisRoot, hasLength(1));
+ AnalysisContext context = contextsInAnalysisRoot[0];
+ expect(context, isNotNull);
+ Source result = context.sourceFactory.forUri2(uri);
+ expect(result, same(source));
+ }
+
void test_setRoots_removeFolderWithoutPubspec() {
packageMapProvider.packageMap = null;
// add one root - there is a context
@@ -975,7 +978,7 @@ class ContextManagerTest {
}
}
-class TestContextManager extends ContextManager {
+class TestContextManager extends AbstractContextManager {
/**
* Source of timestamps stored in [currentContextFilePaths].
*/
@@ -1011,7 +1014,7 @@ class TestContextManager extends ContextManager {
<String, UriResolver>{};
TestContextManager(MemoryResourceProvider resourceProvider,
- ResolverProvider packageResolverProvider,
+ ResolverProvider packageResolverProvider,
OptimizingPubPackageMapProvider packageMapProvider)
: super(resourceProvider, packageResolverProvider, packageMapProvider,
InstrumentationService.NULL_SERVICE);
@@ -1098,6 +1101,16 @@ class TestContextManager extends ContextManager {
}
}
+/**
+ * A [Source] that knows it's [fullName].
+ */
+class TestSource implements Source {
+ TestSource();
+
+ @override
+ noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
+}
+
class TestUriResolver extends UriResolver {
Map<Uri, Source> uriMap;
@@ -1108,13 +1121,3 @@ class TestUriResolver extends UriResolver {
return uriMap[uri];
}
}
-
-/**
- * A [Source] that knows it's [fullName].
- */
-class TestSource implements Source {
- TestSource();
-
- @override
- noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
-}

Powered by Google App Engine
This is Rietveld 408576698