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

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

Issue 553193002: Implement "analysis.reanalyze" in analysis server. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebuild contexts by calling setRoot Created 6 years, 3 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 a60bb60264d725633e996ac158da449eee73b6ba..73b260726332e3e074e144339a4186c90f633490 100644
--- a/pkg/analysis_server/test/context_manager_test.dart
+++ b/pkg/analysis_server/test/context_manager_test.dart
@@ -78,6 +78,47 @@ class ContextManagerTest {
expect(manager.isInAnalysisRoot('/test.dart'), isFalse);
}
+ test_refresh_folder_with_pubspec() {
+ // create a context with a pubspec.yaml file
+ String pubspecPath = posix.join(projPath, 'pubspec.yaml');
+ resourceProvider.newFile(pubspecPath, 'pubspec');
+ manager.setRoots(<String>[projPath], <String>[]);
+ return pumpEventQueue().then((_) {
+ expect(manager.currentContextPaths.toList(), [projPath]);
+ manager.now++;
+ manager.refresh();
+ return pumpEventQueue().then((_) {
+ expect(manager.currentContextPaths.toList(), [projPath]);
+ expect(manager.currentContextTimestamps[projPath], manager.now);
+ });
+ });
+ }
+
+ test_refresh_folder_with_pubspec_subfolders() {
+ // Create a folder with no pubspec.yaml, containing two subfolders with
+ // pubspec.yaml files.
+ String subdir1Path = posix.join(projPath, 'subdir1');
+ String subdir2Path = posix.join(projPath, 'subdir2');
+ String pubspec1Path = posix.join(subdir1Path, 'pubspec.yaml');
+ String pubspec2Path = posix.join(subdir2Path, 'pubspec.yaml');
+ resourceProvider.newFile(pubspec1Path, 'pubspec');
+ resourceProvider.newFile(pubspec2Path, 'pubspec');
+ manager.setRoots(<String>[projPath], <String>[]);
+ return pumpEventQueue().then((_) {
+ expect(manager.currentContextPaths.toSet(),
+ [projPath, subdir1Path, subdir2Path].toSet());
+ manager.now++;
+ manager.refresh();
+ return pumpEventQueue().then((_) {
+ expect(manager.currentContextPaths.toSet(),
+ [projPath, subdir1Path, subdir2Path].toSet());
+ expect(manager.currentContextTimestamps[projPath], manager.now);
+ expect(manager.currentContextTimestamps[subdir1Path], manager.now);
+ expect(manager.currentContextTimestamps[subdir2Path], manager.now);
+ });
+ });
+ }
+
void test_setRoots_addFolderWithDartFile() {
String filePath = posix.join(projPath, 'foo.dart');
resourceProvider.newFile(filePath, 'contents');
@@ -638,7 +679,15 @@ class TestContextManager extends ContextManager {
*/
int now = 0;
- final Set<String> currentContextPaths = new Set<String>();
+ /**
+ * Map from context to the timestamp when the context was created.
+ */
+ Map<String, int> currentContextTimestamps = <String, int>{};
+
+ /**
+ * Iterable of the paths to contexts that currently exist.
+ */
+ Iterable<String> get currentContextPaths => currentContextTimestamps.keys;
/**
* Map from context to (map from file path to timestamp of last event).
@@ -659,7 +708,8 @@ class TestContextManager extends ContextManager {
@override
void addContext(Folder folder, Map<String, List<Folder>> packageMap) {
String path = folder.path;
- currentContextPaths.add(path);
+ expect(currentContextPaths, isNot(contains(path)));
+ currentContextTimestamps[path] = now;
currentContextFilePaths[path] = <String, int>{};
currentContextPackageMaps[path] = packageMap;
}
@@ -693,7 +743,8 @@ class TestContextManager extends ContextManager {
@override
void removeContext(Folder folder) {
String path = folder.path;
- currentContextPaths.remove(path);
+ expect(currentContextPaths, contains(path));
+ currentContextTimestamps.remove(path);
currentContextFilePaths.remove(path);
currentContextPackageMaps.remove(path);
}

Powered by Google App Engine
This is Rietveld 408576698