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

Side by Side Diff: pkg/analysis_server/test/context_manager_test.dart

Issue 2572233002: Add more tests of the driver (Closed)
Patch Set: Created 4 years 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.context.directory.manager; 5 library test.context.directory.manager;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analysis_server/src/context_manager.dart'; 9 import 'package:analysis_server/src/context_manager.dart';
10 import 'package:analysis_server/src/utilities/null_string_sink.dart'; 10 import 'package:analysis_server/src/utilities/null_string_sink.dart';
(...skipping 21 matching lines...) Expand all
32 import 'package:plugin/plugin.dart'; 32 import 'package:plugin/plugin.dart';
33 import 'package:test/test.dart'; 33 import 'package:test/test.dart';
34 import 'package:test_reflective_loader/test_reflective_loader.dart'; 34 import 'package:test_reflective_loader/test_reflective_loader.dart';
35 35
36 import 'mock_sdk.dart'; 36 import 'mock_sdk.dart';
37 import 'mocks.dart'; 37 import 'mocks.dart';
38 38
39 main() { 39 main() {
40 defineReflectiveSuite(() { 40 defineReflectiveSuite(() {
41 defineReflectiveTests(AbstractContextManagerTest); 41 defineReflectiveTests(AbstractContextManagerTest);
42 defineReflectiveTests(AbstractContextManagerTest_Driver);
42 defineReflectiveTests(ContextManagerWithNewOptionsTest); 43 defineReflectiveTests(ContextManagerWithNewOptionsTest);
43 defineReflectiveTests(ContextManagerWithNewOptionsTest_Driver); 44 defineReflectiveTests(ContextManagerWithNewOptionsTest_Driver);
44 defineReflectiveTests(ContextManagerWithOldOptionsTest); 45 defineReflectiveTests(ContextManagerWithOldOptionsTest);
45 defineReflectiveTests(ContextManagerWithOldOptionsTest_Driver); 46 defineReflectiveTests(ContextManagerWithOldOptionsTest_Driver);
46 }); 47 });
47 } 48 }
48 49
49 @reflectiveTest 50 @reflectiveTest
50 class AbstractContextManagerTest extends ContextManagerTest { 51 class AbstractContextManagerTest extends ContextManagerTest {
51 void test_contextsInAnalysisRoot_nestedContext() { 52 void test_contextsInAnalysisRoot_nestedContext() {
52 String subProjPath = path.posix.join(projPath, 'subproj'); 53 String subProjPath = path.posix.join(projPath, 'subproj');
53 Folder subProjFolder = resourceProvider.newFolder(subProjPath); 54 Folder subProjFolder = resourceProvider.newFolder(subProjPath);
54 resourceProvider.newFile( 55 resourceProvider.newFile(
55 path.posix.join(subProjPath, 'pubspec.yaml'), 'contents'); 56 path.posix.join(subProjPath, 'pubspec.yaml'), 'contents');
56 String subProjFilePath = path.posix.join(subProjPath, 'file.dart'); 57 String subProjFilePath = path.posix.join(subProjPath, 'file.dart');
57 resourceProvider.newFile(subProjFilePath, 'contents'); 58 resourceProvider.newFile(subProjFilePath, 'contents');
58 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 59 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
59 // Make sure that there really are contexts for both the main project and 60 // Make sure that there really are contexts for both the main project and
60 // the subproject. 61 // the subproject.
61 Folder projFolder = resourceProvider.getFolder(projPath); 62 Folder projectFolder = resourceProvider.getFolder(projPath);
62 ContextInfo projContextInfo = manager.getContextInfoFor(projFolder); 63 ContextInfo projContextInfo = manager.getContextInfoFor(projectFolder);
63 expect(projContextInfo, isNotNull); 64 expect(projContextInfo, isNotNull);
64 expect(projContextInfo.folder, projFolder); 65 expect(projContextInfo.folder, projectFolder);
65 ContextInfo subProjContextInfo = manager.getContextInfoFor(subProjFolder); 66 ContextInfo subProjContextInfo = manager.getContextInfoFor(subProjFolder);
66 expect(subProjContextInfo, isNotNull); 67 expect(subProjContextInfo, isNotNull);
67 expect(subProjContextInfo.folder, subProjFolder); 68 expect(subProjContextInfo.folder, subProjFolder);
68 expect(projContextInfo.context != subProjContextInfo.context, isTrue); 69 if (enableAnalysisDriver) {
69 // Check that contextsInAnalysisRoot() works. 70 expect(projContextInfo.analysisDriver,
70 List<AnalysisContext> contexts = manager.contextsInAnalysisRoot(projFolder); 71 isNot(equals(subProjContextInfo.analysisDriver)));
71 expect(contexts, hasLength(2)); 72 // Check that getDriversInAnalysisRoot() works.
72 expect(contexts, contains(projContextInfo.context)); 73 List<AnalysisDriver> drivers =
73 expect(contexts, contains(subProjContextInfo.context)); 74 manager.getDriversInAnalysisRoot(projectFolder);
75 expect(drivers, isNotNull);
76 expect(drivers, hasLength(2));
77 expect(drivers, contains(projContextInfo.analysisDriver));
78 expect(drivers, contains(subProjContextInfo.analysisDriver));
79 } else {
80 expect(projContextInfo.context != subProjContextInfo.context, isTrue);
81 // Check that contextsInAnalysisRoot() works.
82 List<AnalysisContext> contexts =
83 manager.contextsInAnalysisRoot(projectFolder);
84 expect(contexts, hasLength(2));
85 expect(contexts, contains(projContextInfo.context));
86 expect(contexts, contains(subProjContextInfo.context));
87 }
74 } 88 }
75 89
76 test_embedder_added() async { 90 test_embedder_added() async {
77 // Create files. 91 // Create files.
78 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]); 92 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]);
79 newFile([libPath, 'main.dart']); 93 newFile([libPath, 'main.dart']);
80 newFile([libPath, 'nope.dart']); 94 newFile([libPath, 'nope.dart']);
81 String embedderPath = newFolder([projPath, 'embedder']); 95 String embedderPath = newFolder([projPath, 'embedder']);
82 newFile([embedderPath, 'entry.dart']); 96 newFile([embedderPath, 'entry.dart']);
83 String embedderSrcPath = newFolder([projPath, 'embedder', 'src']); 97 String embedderSrcPath = newFolder([projPath, 'embedder', 'src']);
84 newFile([embedderSrcPath, 'part.dart']); 98 newFile([embedderSrcPath, 'part.dart']);
85 99
86 // Setup _embedder.yaml. 100 // Setup _embedder.yaml.
87 newFile( 101 newFile(
88 [libPath, '_embedder.yaml'], 102 [libPath, '_embedder.yaml'],
89 r''' 103 r'''
90 embedded_libs: 104 embedded_libs:
91 "dart:foobar": "../embedder/entry.dart" 105 "dart:foobar": "../embedder/entry.dart"
92 "dart:typed_data": "../embedder/src/part" 106 "dart:typed_data": "../embedder/src/part"
93 '''); 107 ''');
94 108
95 Folder projectFolder = resourceProvider.newFolder(projPath); 109 Folder projectFolder = resourceProvider.newFolder(projPath);
96 110
97 // NOTE that this is Not in our package path yet. 111 // NOTE that this is Not in our package path yet.
98 112
99 // Setup context. 113 // Setup context.
100 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 114 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
101 await pumpEventQueue(); 115 await pumpEventQueue();
102 // Confirm that one context was created. 116 // Confirm that one driver / context was created.
103 List<AnalysisContext> contexts = 117 if (enableAnalysisDriver) {
104 manager.contextsInAnalysisRoot(projectFolder); 118 List<AnalysisDriver> drivers =
105 expect(contexts, isNotNull); 119 manager.getDriversInAnalysisRoot(projectFolder);
106 expect(contexts, hasLength(1)); 120 expect(drivers, isNotNull);
121 expect(drivers, hasLength(1));
122 } else {
123 List<AnalysisContext> contexts =
124 manager.contextsInAnalysisRoot(projectFolder);
125 expect(contexts, isNotNull);
126 expect(contexts, hasLength(1));
127 }
107 128
108 // No embedded libs yet. 129 // No embedded libs yet.
109 expect(contexts.first.sourceFactory.forUri('dart:typed_data'), isNull); 130 expect(sourceFactory.forUri('dart:typed_data'), isNull);
110 131
111 // Add .packages file that introduces a dependency with embedded libs. 132 // Add .packages file that introduces a dependency with embedded libs.
112 newFile( 133 newFile(
113 [projPath, '.packages'], 134 [projPath, '.packages'],
114 r''' 135 r'''
115 test_pack:lib/'''); 136 test_pack:lib/''');
116 137
117 await pumpEventQueue(); 138 await pumpEventQueue();
118 139
119 contexts = manager.contextsInAnalysisRoot(projectFolder); 140 // Confirm that we still have just one driver / context.
141 if (enableAnalysisDriver) {
142 List<AnalysisDriver> drivers =
143 manager.getDriversInAnalysisRoot(projectFolder);
144 expect(drivers, isNotNull);
145 expect(drivers, hasLength(1));
146 } else {
147 List<AnalysisContext> contexts =
148 manager.contextsInAnalysisRoot(projectFolder);
120 149
121 // Confirm that we still have just one context. 150 expect(contexts, isNotNull);
122 expect(contexts, isNotNull); 151 expect(contexts, hasLength(1));
123 expect(contexts, hasLength(1)); 152 }
124 153
125 // Embedded lib should be defined now. 154 // Embedded lib should be defined now.
126 expect(contexts.first.sourceFactory.forUri('dart:typed_data'), isNotNull); 155 expect(sourceFactory.forUri('dart:typed_data'), isNotNull);
127 } 156 }
128 157
129 test_embedder_packagespec() async { 158 test_embedder_packagespec() async {
130 // Create files. 159 // Create files.
131 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]); 160 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]);
132 newFile([libPath, 'main.dart']); 161 newFile([libPath, 'main.dart']);
133 newFile([libPath, 'nope.dart']); 162 newFile([libPath, 'nope.dart']);
134 String sdkExtPath = newFolder([projPath, 'sdk_ext']); 163 String sdkExtPath = newFolder([projPath, 'sdk_ext']);
135 newFile([sdkExtPath, 'entry.dart']); 164 newFile([sdkExtPath, 'entry.dart']);
136 String sdkExtSrcPath = newFolder([projPath, 'sdk_ext', 'src']); 165 String sdkExtSrcPath = newFolder([projPath, 'sdk_ext', 'src']);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 199
171 test_ignoreFilesInPackagesFolder() { 200 test_ignoreFilesInPackagesFolder() {
172 // create a context with a pubspec.yaml file 201 // create a context with a pubspec.yaml file
173 String pubspecPath = path.posix.join(projPath, 'pubspec.yaml'); 202 String pubspecPath = path.posix.join(projPath, 'pubspec.yaml');
174 resourceProvider.newFile(pubspecPath, 'pubspec'); 203 resourceProvider.newFile(pubspecPath, 'pubspec');
175 // create a file in the "packages" folder 204 // create a file in the "packages" folder
176 String filePath1 = path.posix.join(projPath, 'packages', 'file1.dart'); 205 String filePath1 = path.posix.join(projPath, 'packages', 'file1.dart');
177 resourceProvider.newFile(filePath1, 'contents'); 206 resourceProvider.newFile(filePath1, 'contents');
178 // "packages" files are ignored initially 207 // "packages" files are ignored initially
179 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 208 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
180 expect(callbacks.currentContextFilePaths[projPath], isEmpty); 209 expect(callbacks.currentFilePaths, isEmpty);
181 // "packages" files are ignored during watch 210 // "packages" files are ignored during watch
182 String filePath2 = path.posix.join(projPath, 'packages', 'file2.dart'); 211 String filePath2 = path.posix.join(projPath, 'packages', 'file2.dart');
183 resourceProvider.newFile(filePath2, 'contents'); 212 resourceProvider.newFile(filePath2, 'contents');
184 return pumpEventQueue().then((_) { 213 return pumpEventQueue().then((_) {
185 expect(callbacks.currentContextFilePaths[projPath], isEmpty); 214 expect(callbacks.currentFilePaths, isEmpty);
186 }); 215 });
187 } 216 }
188 217
189 void test_isInAnalysisRoot_excluded() { 218 void test_isInAnalysisRoot_excluded() {
190 // prepare paths 219 // prepare paths
191 String project = '/project'; 220 String project = '/project';
192 String excludedFolder = '$project/excluded'; 221 String excludedFolder = '$project/excluded';
193 // set roots 222 // set roots
194 resourceProvider.newFolder(project); 223 resourceProvider.newFolder(project);
195 resourceProvider.newFolder(excludedFolder); 224 resourceProvider.newFolder(excludedFolder);
(...skipping 26 matching lines...) Expand all
222 251
223 void test_isInAnalysisRoot_notInRoot() { 252 void test_isInAnalysisRoot_notInRoot() {
224 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 253 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
225 expect(manager.isInAnalysisRoot('/test.dart'), isFalse); 254 expect(manager.isInAnalysisRoot('/test.dart'), isFalse);
226 } 255 }
227 256
228 test_path_filter() async { 257 test_path_filter() async {
229 // Setup context. 258 // Setup context.
230 Folder root = resourceProvider.newFolder(projPath); 259 Folder root = resourceProvider.newFolder(projPath);
231 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 260 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
232 expect(callbacks.currentContextFilePaths[projPath], isEmpty); 261 expect(callbacks.currentFilePaths, isEmpty);
233 // Set ignore patterns for context. 262 // Set ignore patterns for context.
234 ContextInfo rootInfo = manager.getContextInfoFor(root); 263 ContextInfo rootInfo = manager.getContextInfoFor(root);
235 manager.setIgnorePatternsForContext( 264 manager.setIgnorePatternsForContext(
236 rootInfo, ['sdk_ext/**', 'lib/ignoreme.dart']); 265 rootInfo, ['sdk_ext/**', 'lib/ignoreme.dart']);
237 // Start creating files. 266 // Start creating files.
238 newFile([projPath, ContextManagerImpl.PUBSPEC_NAME]); 267 newFile([projPath, ContextManagerImpl.PUBSPEC_NAME]);
239 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]); 268 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]);
240 newFile([libPath, 'main.dart']); 269 newFile([libPath, 'main.dart']);
241 newFile([libPath, 'ignoreme.dart']); 270 newFile([libPath, 'ignoreme.dart']);
242 String sdkExtPath = newFolder([projPath, 'sdk_ext']); 271 String sdkExtPath = newFolder([projPath, 'sdk_ext']);
243 newFile([sdkExtPath, 'entry.dart']); 272 newFile([sdkExtPath, 'entry.dart']);
244 String sdkExtSrcPath = newFolder([projPath, 'sdk_ext', 'src']); 273 String sdkExtSrcPath = newFolder([projPath, 'sdk_ext', 'src']);
245 newFile([sdkExtSrcPath, 'part.dart']); 274 newFile([sdkExtSrcPath, 'part.dart']);
246 // Pump event loop so new files are discovered and added to context. 275 // Pump event loop so new files are discovered and added to context.
247 await pumpEventQueue(); 276 await pumpEventQueue();
248 // Verify that ignored files were ignored. 277 // Verify that ignored files were ignored.
249 Map<String, int> fileTimestamps = 278 Iterable<String> filePaths = callbacks.currentFilePaths;
250 callbacks.currentContextFilePaths[projPath]; 279 expect(filePaths, hasLength(1));
251 expect(fileTimestamps, isNotEmpty); 280 expect(filePaths, contains('/my/proj/lib/main.dart'));
252 List<String> files = fileTimestamps.keys.toList();
253 expect(files.length, equals(1));
254 expect(files[0], equals('/my/proj/lib/main.dart'));
255 } 281 }
256 282
257 test_refresh_folder_with_packagespec() { 283 test_refresh_folder_with_packagespec() {
258 // create a context with a .packages file 284 // create a context with a .packages file
259 String packagespecFile = path.posix.join(projPath, '.packages'); 285 String packagespecFile = path.posix.join(projPath, '.packages');
260 resourceProvider.newFile(packagespecFile, ''); 286 resourceProvider.newFile(packagespecFile, '');
261 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 287 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
262 return pumpEventQueue().then((_) { 288 return pumpEventQueue().then((_) {
263 expect(callbacks.currentContextPaths.toList(), [projPath]); 289 expect(callbacks.currentContextRoots, unorderedEquals([projPath]));
264 callbacks.now++; 290 callbacks.now++;
265 manager.refresh(null); 291 manager.refresh(null);
266 return pumpEventQueue().then((_) { 292 return pumpEventQueue().then((_) {
267 expect(callbacks.currentContextPaths.toList(), [projPath]); 293 expect(callbacks.currentContextRoots, unorderedEquals([projPath]));
268 expect(callbacks.currentContextTimestamps[projPath], callbacks.now); 294 expect(callbacks.currentContextTimestamps[projPath], callbacks.now);
269 }); 295 });
270 }); 296 });
271 } 297 }
272 298
273 // TODO(paulberry): This test only tests PackagesFileDisposition. 299 // TODO(paulberry): This test only tests PackagesFileDisposition.
274 // Once http://dartbug.com/23909 is fixed, add a test for sdk extensions 300 // Once http://dartbug.com/23909 is fixed, add a test for sdk extensions
275 // and PackageMapDisposition. 301 // and PackageMapDisposition.
276 test_refresh_folder_with_packagespec_subfolders() { 302 test_refresh_folder_with_packagespec_subfolders() {
277 // Create a folder with no .packages file, containing two subfolders with 303 // Create a folder with no .packages file, containing two subfolders with
278 // .packages files. 304 // .packages files.
279 String subdir1Path = path.posix.join(projPath, 'subdir1'); 305 String subdir1Path = path.posix.join(projPath, 'subdir1');
280 String subdir2Path = path.posix.join(projPath, 'subdir2'); 306 String subdir2Path = path.posix.join(projPath, 'subdir2');
281 String packagespec1Path = path.posix.join(subdir1Path, '.packages'); 307 String packagespec1Path = path.posix.join(subdir1Path, '.packages');
282 String packagespec2Path = path.posix.join(subdir2Path, '.packages'); 308 String packagespec2Path = path.posix.join(subdir2Path, '.packages');
283 resourceProvider.newFile(packagespec1Path, ''); 309 resourceProvider.newFile(packagespec1Path, '');
284 resourceProvider.newFile(packagespec2Path, ''); 310 resourceProvider.newFile(packagespec2Path, '');
285 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 311 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
286 return pumpEventQueue().then((_) { 312 return pumpEventQueue().then((_) {
287 expect(callbacks.currentContextPaths.toSet(), 313 expect(callbacks.currentContextRoots,
288 [subdir1Path, subdir2Path, projPath].toSet()); 314 unorderedEquals([subdir1Path, subdir2Path, projPath]));
289 callbacks.now++; 315 callbacks.now++;
290 manager.refresh(null); 316 manager.refresh(null);
291 return pumpEventQueue().then((_) { 317 return pumpEventQueue().then((_) {
292 expect(callbacks.currentContextPaths.toSet(), 318 expect(callbacks.currentContextRoots,
293 [subdir1Path, subdir2Path, projPath].toSet()); 319 unorderedEquals([subdir1Path, subdir2Path, projPath]));
294 expect(callbacks.currentContextTimestamps[projPath], callbacks.now); 320 expect(callbacks.currentContextTimestamps[projPath], callbacks.now);
295 expect(callbacks.currentContextTimestamps[subdir1Path], callbacks.now); 321 expect(callbacks.currentContextTimestamps[subdir1Path], callbacks.now);
296 expect(callbacks.currentContextTimestamps[subdir2Path], callbacks.now); 322 expect(callbacks.currentContextTimestamps[subdir2Path], callbacks.now);
297 }); 323 });
298 }); 324 });
299 } 325 }
300 326
301 test_refresh_folder_with_pubspec() { 327 test_refresh_folder_with_pubspec() {
302 // create a context with a pubspec.yaml file 328 // create a context with a pubspec.yaml file
303 String pubspecPath = path.posix.join(projPath, 'pubspec.yaml'); 329 String pubspecPath = path.posix.join(projPath, 'pubspec.yaml');
304 resourceProvider.newFile(pubspecPath, 'pubspec'); 330 resourceProvider.newFile(pubspecPath, 'pubspec');
305 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 331 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
306 return pumpEventQueue().then((_) { 332 return pumpEventQueue().then((_) {
307 expect(callbacks.currentContextPaths.toList(), [projPath]); 333 expect(callbacks.currentContextRoots, unorderedEquals([projPath]));
308 callbacks.now++; 334 callbacks.now++;
309 manager.refresh(null); 335 manager.refresh(null);
310 return pumpEventQueue().then((_) { 336 return pumpEventQueue().then((_) {
311 expect(callbacks.currentContextPaths.toList(), [projPath]); 337 expect(callbacks.currentContextRoots, unorderedEquals([projPath]));
312 expect(callbacks.currentContextTimestamps[projPath], callbacks.now); 338 expect(callbacks.currentContextTimestamps[projPath], callbacks.now);
313 }); 339 });
314 }); 340 });
315 } 341 }
316 342
317 test_refresh_folder_with_pubspec_subfolders() { 343 test_refresh_folder_with_pubspec_subfolders() {
318 // Create a folder with no pubspec.yaml, containing two subfolders with 344 // Create a folder with no pubspec.yaml, containing two subfolders with
319 // pubspec.yaml files. 345 // pubspec.yaml files.
320 String subdir1Path = path.posix.join(projPath, 'subdir1'); 346 String subdir1Path = path.posix.join(projPath, 'subdir1');
321 String subdir2Path = path.posix.join(projPath, 'subdir2'); 347 String subdir2Path = path.posix.join(projPath, 'subdir2');
322 String pubspec1Path = path.posix.join(subdir1Path, 'pubspec.yaml'); 348 String pubspec1Path = path.posix.join(subdir1Path, 'pubspec.yaml');
323 String pubspec2Path = path.posix.join(subdir2Path, 'pubspec.yaml'); 349 String pubspec2Path = path.posix.join(subdir2Path, 'pubspec.yaml');
324 resourceProvider.newFile(pubspec1Path, 'pubspec'); 350 resourceProvider.newFile(pubspec1Path, 'pubspec');
325 resourceProvider.newFile(pubspec2Path, 'pubspec'); 351 resourceProvider.newFile(pubspec2Path, 'pubspec');
326 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 352 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
327 return pumpEventQueue().then((_) { 353 return pumpEventQueue().then((_) {
328 expect(callbacks.currentContextPaths.toSet(), 354 expect(callbacks.currentContextRoots,
329 [subdir1Path, subdir2Path, projPath].toSet()); 355 unorderedEquals([subdir1Path, subdir2Path, projPath]));
330 callbacks.now++; 356 callbacks.now++;
331 manager.refresh(null); 357 manager.refresh(null);
332 return pumpEventQueue().then((_) { 358 return pumpEventQueue().then((_) {
333 expect(callbacks.currentContextPaths.toSet(), 359 expect(callbacks.currentContextRoots,
334 [subdir1Path, subdir2Path, projPath].toSet()); 360 unorderedEquals([subdir1Path, subdir2Path, projPath]));
335 expect(callbacks.currentContextTimestamps[projPath], callbacks.now); 361 expect(callbacks.currentContextTimestamps[projPath], callbacks.now);
336 expect(callbacks.currentContextTimestamps[subdir1Path], callbacks.now); 362 expect(callbacks.currentContextTimestamps[subdir1Path], callbacks.now);
337 expect(callbacks.currentContextTimestamps[subdir2Path], callbacks.now); 363 expect(callbacks.currentContextTimestamps[subdir2Path], callbacks.now);
338 }); 364 });
339 }); 365 });
340 } 366 }
341 367
342 test_refresh_oneContext() { 368 test_refresh_oneContext() {
343 // create two contexts with pubspec.yaml files 369 // create two contexts with pubspec.yaml files
344 String pubspecPath = path.posix.join(projPath, 'pubspec.yaml'); 370 String pubspecPath = path.posix.join(projPath, 'pubspec.yaml');
345 resourceProvider.newFile(pubspecPath, 'pubspec1'); 371 resourceProvider.newFile(pubspecPath, 'pubspec1');
346 372
347 String proj2Path = '/my/proj2'; 373 String proj2Path = '/my/proj2';
348 resourceProvider.newFolder(proj2Path); 374 resourceProvider.newFolder(proj2Path);
349 String pubspec2Path = path.posix.join(proj2Path, 'pubspec.yaml'); 375 String pubspec2Path = path.posix.join(proj2Path, 'pubspec.yaml');
350 resourceProvider.newFile(pubspec2Path, 'pubspec2'); 376 resourceProvider.newFile(pubspec2Path, 'pubspec2');
351 377
352 List<String> roots = <String>[projPath, proj2Path]; 378 List<String> roots = <String>[projPath, proj2Path];
353 manager.setRoots(roots, <String>[], <String, String>{}); 379 manager.setRoots(roots, <String>[], <String, String>{});
354 return pumpEventQueue().then((_) { 380 return pumpEventQueue().then((_) {
355 expect(callbacks.currentContextPaths.toList(), unorderedEquals(roots)); 381 expect(callbacks.currentContextRoots, unorderedEquals(roots));
356 int then = callbacks.now; 382 int then = callbacks.now;
357 callbacks.now++; 383 callbacks.now++;
358 manager.refresh([resourceProvider.getResource(proj2Path)]); 384 manager.refresh([resourceProvider.getResource(proj2Path)]);
359 return pumpEventQueue().then((_) { 385 return pumpEventQueue().then((_) {
360 expect(callbacks.currentContextPaths.toList(), unorderedEquals(roots)); 386 expect(callbacks.currentContextRoots, unorderedEquals(roots));
361 expect(callbacks.currentContextTimestamps[projPath], then); 387 expect(callbacks.currentContextTimestamps[projPath], then);
362 expect(callbacks.currentContextTimestamps[proj2Path], callbacks.now); 388 expect(callbacks.currentContextTimestamps[proj2Path], callbacks.now);
363 }); 389 });
364 }); 390 });
365 } 391 }
366 392
367 test_sdk_ext_packagespec() async { 393 test_sdk_ext_packagespec() async {
368 // Create files. 394 // Create files.
369 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]); 395 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]);
370 newFile([libPath, 'main.dart']); 396 newFile([libPath, 'main.dart']);
(...skipping 24 matching lines...) Expand all
395 expect(contexts.length, equals(1)); 421 expect(contexts.length, equals(1));
396 var source = sourceFactory.forUri('dart:foobar'); 422 var source = sourceFactory.forUri('dart:foobar');
397 expect(source.fullName, equals('/my/proj/sdk_ext/entry.dart')); 423 expect(source.fullName, equals('/my/proj/sdk_ext/entry.dart'));
398 } 424 }
399 425
400 void test_setRoots_addFolderWithDartFile() { 426 void test_setRoots_addFolderWithDartFile() {
401 String filePath = path.posix.join(projPath, 'foo.dart'); 427 String filePath = path.posix.join(projPath, 'foo.dart');
402 resourceProvider.newFile(filePath, 'contents'); 428 resourceProvider.newFile(filePath, 'contents');
403 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 429 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
404 // verify 430 // verify
405 var filePaths = callbacks.currentContextFilePaths[projPath]; 431 Iterable<String> filePaths = callbacks.currentFilePaths;
406 expect(filePaths, hasLength(1)); 432 expect(filePaths, hasLength(1));
407 expect(filePaths, contains(filePath)); 433 expect(filePaths, contains(filePath));
408 List<AnalysisContext> contextsInAnalysisRoot = 434 if (enableAnalysisDriver) {
409 manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath)); 435 List<AnalysisDriver> drivers = manager
410 expect(contextsInAnalysisRoot, hasLength(1)); 436 .getDriversInAnalysisRoot(resourceProvider.newFolder(projPath));
411 AnalysisContext context = contextsInAnalysisRoot[0]; 437 expect(drivers, hasLength(1));
412 expect(context, isNotNull); 438 expect(drivers[0], isNotNull);
439 } else {
440 List<AnalysisContext> contextsInAnalysisRoot =
441 manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath));
442 expect(contextsInAnalysisRoot, hasLength(1));
443 expect(contextsInAnalysisRoot[0], isNotNull);
444 }
413 Source result = sourceFactory.forUri('package:foo/foo.dart'); 445 Source result = sourceFactory.forUri('package:foo/foo.dart');
414 expect(result, isNotNull); 446 expect(result, isNotNull);
415 expect(result.exists(), isFalse); 447 expect(result.exists(), isFalse);
416 } 448 }
417 449
418 void test_setRoots_addFolderWithDartFileInSubfolder() { 450 void test_setRoots_addFolderWithDartFileInSubfolder() {
419 String filePath = path.posix.join(projPath, 'foo', 'bar.dart'); 451 String filePath = path.posix.join(projPath, 'foo', 'bar.dart');
420 resourceProvider.newFile(filePath, 'contents'); 452 resourceProvider.newFile(filePath, 'contents');
421 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 453 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
422 // verify 454 // verify
423 var filePaths = callbacks.currentContextFilePaths[projPath]; 455 Iterable<String> filePaths = callbacks.currentFilePaths;
424 expect(filePaths, hasLength(1)); 456 expect(filePaths, hasLength(1));
425 expect(filePaths, contains(filePath)); 457 expect(filePaths, contains(filePath));
426 } 458 }
427 459
428 void test_setRoots_addFolderWithDummyLink() { 460 void test_setRoots_addFolderWithDummyLink() {
429 String filePath = path.posix.join(projPath, 'foo.dart'); 461 String filePath = path.posix.join(projPath, 'foo.dart');
430 resourceProvider.newDummyLink(filePath); 462 resourceProvider.newDummyLink(filePath);
431 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 463 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
432 // verify 464 // verify
433 var filePaths = callbacks.currentContextFilePaths[projPath]; 465 expect(callbacks.currentFilePaths, isEmpty);
434 expect(filePaths, isEmpty);
435 } 466 }
436 467
437 void test_setRoots_addFolderWithNestedPackageSpec() { 468 void test_setRoots_addFolderWithNestedPackageSpec() {
438 String examplePath = newFolder([projPath, ContextManagerTest.EXAMPLE_NAME]); 469 String examplePath = newFolder([projPath, ContextManagerTest.EXAMPLE_NAME]);
439 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]); 470 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]);
440 471
441 newFile([projPath, ContextManagerImpl.PACKAGE_SPEC_NAME]); 472 newFile([projPath, ContextManagerImpl.PACKAGE_SPEC_NAME]);
442 newFile([libPath, 'main.dart']); 473 newFile([libPath, 'main.dart']);
443 newFile([examplePath, ContextManagerImpl.PACKAGE_SPEC_NAME]); 474 newFile([examplePath, ContextManagerImpl.PACKAGE_SPEC_NAME]);
444 newFile([examplePath, 'example.dart']); 475 newFile([examplePath, 'example.dart']);
445 476
446 packageMapProvider.packageMap['proj'] = <Folder>[ 477 packageMapProvider.packageMap['proj'] = <Folder>[
447 resourceProvider.getResource(libPath) 478 resourceProvider.getResource(libPath)
448 ]; 479 ];
449 480
450 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 481 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
451 482
452 expect(callbacks.currentContextPaths, hasLength(2)); 483 expect(callbacks.currentContextRoots, hasLength(2));
453 484
454 expect(callbacks.currentContextPaths, contains(projPath)); 485 expect(callbacks.currentContextRoots, contains(projPath));
455 Set<Source> projSources = callbacks.currentContextSources[projPath]; 486 Iterable<Source> projSources = callbacks.currentFileSources(projPath);
456 expect(projSources, hasLength(1)); 487 expect(projSources, hasLength(1));
457 expect(projSources.first.uri.toString(), 'file:///my/proj/lib/main.dart'); 488 expect(projSources.first.uri.toString(), 'file:///my/proj/lib/main.dart');
458 489
459 expect(callbacks.currentContextPaths, contains(examplePath)); 490 expect(callbacks.currentContextRoots, contains(examplePath));
460 Set<Source> exampleSources = callbacks.currentContextSources[examplePath]; 491 Iterable<Source> exampleSources = callbacks.currentFileSources(examplePath);
461 expect(exampleSources, hasLength(1)); 492 expect(exampleSources, hasLength(1));
462 expect(exampleSources.first.uri.toString(), 493 expect(exampleSources.first.uri.toString(),
463 'file:///my/proj/example/example.dart'); 494 'file:///my/proj/example/example.dart');
464 } 495 }
465 496
466 void test_setRoots_addFolderWithNestedPubspec() { 497 void test_setRoots_addFolderWithNestedPubspec() {
467 String examplePath = newFolder([projPath, ContextManagerTest.EXAMPLE_NAME]); 498 String examplePath = newFolder([projPath, ContextManagerTest.EXAMPLE_NAME]);
468 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]); 499 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]);
469 500
470 newFile([projPath, ContextManagerImpl.PUBSPEC_NAME]); 501 newFile([projPath, ContextManagerImpl.PUBSPEC_NAME]);
471 newFile([projPath, ContextManagerImpl.PACKAGE_SPEC_NAME], 'proj:lib/'); 502 newFile([projPath, ContextManagerImpl.PACKAGE_SPEC_NAME], 'proj:lib/');
472 newFile([libPath, 'main.dart']); 503 newFile([libPath, 'main.dart']);
473 newFile([examplePath, ContextManagerImpl.PUBSPEC_NAME]); 504 newFile([examplePath, ContextManagerImpl.PUBSPEC_NAME]);
474 newFile([examplePath, 'example.dart']); 505 newFile([examplePath, 'example.dart']);
475 506
476 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 507 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
477 508
478 expect(callbacks.currentContextPaths, hasLength(2)); 509 expect(callbacks.currentContextRoots, hasLength(2));
479 510
480 expect(callbacks.currentContextPaths, contains(projPath)); 511 expect(callbacks.currentContextRoots, contains(projPath));
481 Set<Source> projSources = callbacks.currentContextSources[projPath]; 512 Iterable<Source> projSources = callbacks.currentFileSources(projPath);
482 expect(projSources, hasLength(1)); 513 expect(projSources, hasLength(1));
483 expect(projSources.first.uri.toString(), 'package:proj/main.dart'); 514 expect(projSources.first.uri.toString(), 'package:proj/main.dart');
484 515
485 expect(callbacks.currentContextPaths, contains(examplePath)); 516 expect(callbacks.currentContextRoots, contains(examplePath));
486 Set<Source> exampleSources = callbacks.currentContextSources[examplePath]; 517 Iterable<Source> exampleSources = callbacks.currentFileSources(examplePath);
487 expect(exampleSources, hasLength(1)); 518 expect(exampleSources, hasLength(1));
488 expect(exampleSources.first.uri.toString(), 519 expect(exampleSources.first.uri.toString(),
489 'file:///my/proj/example/example.dart'); 520 'file:///my/proj/example/example.dart');
490 } 521 }
491 522
492 void test_setRoots_addFolderWithoutPubspec() { 523 void test_setRoots_addFolderWithoutPubspec() {
493 packageMapProvider.packageMap = null; 524 packageMapProvider.packageMap = null;
494 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 525 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
495 // verify 526 // verify
496 expect(callbacks.currentContextPaths, hasLength(1)); 527 expect(callbacks.currentContextRoots, unorderedEquals([projPath]));
497 expect(callbacks.currentContextPaths, contains(projPath)); 528 expect(callbacks.currentFilePaths, hasLength(0));
498 expect(callbacks.currentContextFilePaths[projPath], hasLength(0));
499 } 529 }
500 530
501 void test_setRoots_addFolderWithPackagespec() { 531 void test_setRoots_addFolderWithPackagespec() {
502 String packagespecPath = path.posix.join(projPath, '.packages'); 532 String packagespecPath = path.posix.join(projPath, '.packages');
503 resourceProvider.newFile(packagespecPath, 533 resourceProvider.newFile(packagespecPath,
504 'unittest:file:///home/somebody/.pub/cache/unittest-0.9.9/lib/'); 534 'unittest:file:///home/somebody/.pub/cache/unittest-0.9.9/lib/');
505 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]); 535 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]);
506 File mainFile = 536 File mainFile =
507 resourceProvider.newFile(path.posix.join(libPath, 'main.dart'), ''); 537 resourceProvider.newFile(path.posix.join(libPath, 'main.dart'), '');
508 Source source = mainFile.createSource(); 538 Source source = mainFile.createSource();
509 539
510 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 540 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
511 541
512 // verify 542 // verify
513 expect(callbacks.currentContextPaths, hasLength(1)); 543 expect(callbacks.currentContextRoots, unorderedEquals([projPath]));
514 expect(callbacks.currentContextPaths, contains(projPath)); 544 expect(callbacks.currentFilePaths, hasLength(1));
515 expect(callbacks.currentContextFilePaths[projPath], hasLength(1));
516 545
517 // smoketest resolution 546 // smoketest resolution
518 SourceFactory sourceFactory = callbacks.currentContext.sourceFactory;
519 Source resolvedSource = 547 Source resolvedSource =
520 sourceFactory.resolveUri(source, 'package:unittest/unittest.dart'); 548 sourceFactory.resolveUri(source, 'package:unittest/unittest.dart');
521 expect(resolvedSource, isNotNull); 549 expect(resolvedSource, isNotNull);
522 expect(resolvedSource.fullName, 550 expect(resolvedSource.fullName,
523 equals('/home/somebody/.pub/cache/unittest-0.9.9/lib/unittest.dart')); 551 equals('/home/somebody/.pub/cache/unittest-0.9.9/lib/unittest.dart'));
524 } 552 }
525 553
526 void test_setRoots_addFolderWithPackagespecAndPackageRoot() { 554 void test_setRoots_addFolderWithPackagespecAndPackageRoot() {
527 // The package root should take priority. 555 // The package root should take priority.
528 String packagespecPath = path.posix.join(projPath, '.packages'); 556 String packagespecPath = path.posix.join(projPath, '.packages');
529 resourceProvider.newFile(packagespecPath, 557 resourceProvider.newFile(packagespecPath,
530 'unittest:file:///home/somebody/.pub/cache/unittest-0.9.9/lib/'); 558 'unittest:file:///home/somebody/.pub/cache/unittest-0.9.9/lib/');
531 String packageRootPath = '/package/root/'; 559 String packageRootPath = '/package/root/';
532 manager.setRoots(<String>[projPath], <String>[], 560 manager.setRoots(<String>[projPath], <String>[],
533 <String, String>{projPath: packageRootPath}); 561 <String, String>{projPath: packageRootPath});
534 expect(callbacks.currentContextPaths, hasLength(1)); 562 expect(callbacks.currentContextRoots, unorderedEquals([projPath]));
535 expect(callbacks.currentContextPaths, contains(projPath));
536 _checkPackageRoot(projPath, packageRootPath); 563 _checkPackageRoot(projPath, packageRootPath);
537 } 564 }
538 565
539 void test_setRoots_addFolderWithPubspec() { 566 void test_setRoots_addFolderWithPubspec() {
540 String pubspecPath = path.posix.join(projPath, 'pubspec.yaml'); 567 String pubspecPath = path.posix.join(projPath, 'pubspec.yaml');
541 resourceProvider.newFile(pubspecPath, 'pubspec'); 568 resourceProvider.newFile(pubspecPath, 'pubspec');
542 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 569 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
543 // verify 570 // verify
544 expect(callbacks.currentContextPaths, hasLength(1)); 571 expect(callbacks.currentContextRoots, unorderedEquals([projPath]));
545 expect(callbacks.currentContextPaths, contains(projPath)); 572 expect(callbacks.currentFilePaths, hasLength(0));
546 expect(callbacks.currentContextFilePaths[projPath], hasLength(0));
547 } 573 }
548 574
549 void test_setRoots_addFolderWithPubspec_andPackagespec() { 575 void test_setRoots_addFolderWithPubspec_andPackagespec() {
550 String pubspecPath = path.posix.join(projPath, 'pubspec.yaml'); 576 String pubspecPath = path.posix.join(projPath, 'pubspec.yaml');
551 String packagespecPath = path.posix.join(projPath, '.packages'); 577 String packagespecPath = path.posix.join(projPath, '.packages');
552 resourceProvider.newFile(pubspecPath, 'pubspec'); 578 resourceProvider.newFile(pubspecPath, 'pubspec');
553 resourceProvider.newFile(packagespecPath, ''); 579 resourceProvider.newFile(packagespecPath, '');
554 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 580 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
555 // verify 581 // verify
556 callbacks.assertContextPaths([projPath]); 582 callbacks.assertContextPaths([projPath]);
557 } 583 }
558 584
559 void test_setRoots_addFolderWithPubspecAndLib() { 585 void test_setRoots_addFolderWithPubspecAndLib() {
560 String binPath = newFolder([projPath, ContextManagerTest.BIN_NAME]); 586 String binPath = newFolder([projPath, ContextManagerTest.BIN_NAME]);
561 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]); 587 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]);
562 String srcPath = newFolder([libPath, ContextManagerTest.SRC_NAME]); 588 String srcPath = newFolder([libPath, ContextManagerTest.SRC_NAME]);
563 String testPath = newFolder([projPath, ContextManagerTest.TEST_NAME]); 589 String testPath = newFolder([projPath, ContextManagerTest.TEST_NAME]);
564 590
565 newFile([projPath, ContextManagerImpl.PUBSPEC_NAME]); 591 newFile([projPath, ContextManagerImpl.PUBSPEC_NAME]);
566 newFile([projPath, ContextManagerImpl.PACKAGE_SPEC_NAME], 'proj:lib/'); 592 newFile([projPath, ContextManagerImpl.PACKAGE_SPEC_NAME], 'proj:lib/');
567 String appPath = newFile([binPath, 'app.dart']); 593 String appPath = newFile([binPath, 'app.dart']);
568 newFile([libPath, 'main.dart']); 594 newFile([libPath, 'main.dart']);
569 newFile([srcPath, 'internal.dart']); 595 newFile([srcPath, 'internal.dart']);
570 String testFilePath = newFile([testPath, 'main_test.dart']); 596 String testFilePath = newFile([testPath, 'main_test.dart']);
571 597
572 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 598 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
573 Set<Source> sources = callbacks.currentContextSources[projPath]; 599 Iterable<Source> sources = callbacks.currentFileSources(projPath);
574 600
575 expect(callbacks.currentContextPaths, hasLength(1)); 601 expect(callbacks.currentContextRoots, unorderedEquals([projPath]));
576 expect(callbacks.currentContextPaths, contains(projPath));
577 expect(sources, hasLength(4)); 602 expect(sources, hasLength(4));
578 List<String> uris = 603 List<String> uris =
579 sources.map((Source source) => source.uri.toString()).toList(); 604 sources.map((Source source) => source.uri.toString()).toList();
580 expect(uris, contains('file://$appPath')); 605 expect(uris, contains('file://$appPath'));
581 expect(uris, contains('package:proj/main.dart')); 606 expect(uris, contains('package:proj/main.dart'));
582 expect(uris, contains('package:proj/src/internal.dart')); 607 expect(uris, contains('package:proj/src/internal.dart'));
583 expect(uris, contains('file://$testFilePath')); 608 expect(uris, contains('file://$testFilePath'));
584 } 609 }
585 610
586 void test_setRoots_addFolderWithPubspecAndPackagespecFolders() { 611 void test_setRoots_addFolderWithPubspecAndPackagespecFolders() {
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 ContextInfo projectInfo = rootInfo.children[0]; 861 ContextInfo projectInfo = rootInfo.children[0];
837 expect(projectInfo.folder.path, project); 862 expect(projectInfo.folder.path, project);
838 expect(projectInfo.children, hasLength(1)); 863 expect(projectInfo.children, hasLength(1));
839 { 864 {
840 ContextInfo exampleInfo = projectInfo.children[0]; 865 ContextInfo exampleInfo = projectInfo.children[0];
841 expect(exampleInfo.folder.path, example); 866 expect(exampleInfo.folder.path, example);
842 expect(exampleInfo.children, isEmpty); 867 expect(exampleInfo.children, isEmpty);
843 } 868 }
844 } 869 }
845 } 870 }
846 expect(callbacks.currentContextPaths, hasLength(2)); 871 expect(callbacks.currentContextRoots, unorderedEquals([project, example]));
847 expect(callbacks.currentContextPaths, unorderedEquals([project, example]));
848 } 872 }
849 873
850 void test_setRoots_nested_includedByOuter_outerPubspec() { 874 void test_setRoots_nested_includedByOuter_outerPubspec() {
851 String project = '/project'; 875 String project = '/project';
852 String projectPubspec = '$project/pubspec.yaml'; 876 String projectPubspec = '$project/pubspec.yaml';
853 String example = '$project/example'; 877 String example = '$project/example';
854 // create files 878 // create files
855 resourceProvider.newFile(projectPubspec, 'name: project'); 879 resourceProvider.newFile(projectPubspec, 'name: project');
856 resourceProvider.newFolder(example); 880 resourceProvider.newFolder(example);
857 manager 881 manager
858 .setRoots(<String>[project, example], <String>[], <String, String>{}); 882 .setRoots(<String>[project, example], <String>[], <String, String>{});
859 // verify 883 // verify
860 { 884 {
861 ContextInfo rootInfo = manager.rootInfo; 885 ContextInfo rootInfo = manager.rootInfo;
862 expect(rootInfo.children, hasLength(1)); 886 expect(rootInfo.children, hasLength(1));
863 { 887 {
864 ContextInfo projectInfo = rootInfo.children[0]; 888 ContextInfo projectInfo = rootInfo.children[0];
865 expect(projectInfo.folder.path, project); 889 expect(projectInfo.folder.path, project);
866 expect(projectInfo.children, isEmpty); 890 expect(projectInfo.children, isEmpty);
867 } 891 }
868 } 892 }
869 expect(callbacks.currentContextPaths, hasLength(1)); 893 expect(callbacks.currentContextRoots, unorderedEquals([project]));
870 expect(callbacks.currentContextPaths, unorderedEquals([project]));
871 } 894 }
872 895
873 void test_setRoots_nested_includedByOuter_twoPubspecs() { 896 void test_setRoots_nested_includedByOuter_twoPubspecs() {
874 String project = '/project'; 897 String project = '/project';
875 String projectPubspec = '$project/pubspec.yaml'; 898 String projectPubspec = '$project/pubspec.yaml';
876 String example = '$project/example'; 899 String example = '$project/example';
877 String examplePubspec = '$example/pubspec.yaml'; 900 String examplePubspec = '$example/pubspec.yaml';
878 // create files 901 // create files
879 resourceProvider.newFile(projectPubspec, 'name: project'); 902 resourceProvider.newFile(projectPubspec, 'name: project');
880 resourceProvider.newFile(examplePubspec, 'name: example'); 903 resourceProvider.newFile(examplePubspec, 'name: example');
881 manager 904 manager
882 .setRoots(<String>[project, example], <String>[], <String, String>{}); 905 .setRoots(<String>[project, example], <String>[], <String, String>{});
883 // verify 906 // verify
884 { 907 {
885 ContextInfo rootInfo = manager.rootInfo; 908 ContextInfo rootInfo = manager.rootInfo;
886 expect(rootInfo.children, hasLength(1)); 909 expect(rootInfo.children, hasLength(1));
887 { 910 {
888 ContextInfo projectInfo = rootInfo.children[0]; 911 ContextInfo projectInfo = rootInfo.children[0];
889 expect(projectInfo.folder.path, project); 912 expect(projectInfo.folder.path, project);
890 expect(projectInfo.children, hasLength(1)); 913 expect(projectInfo.children, hasLength(1));
891 { 914 {
892 ContextInfo exampleInfo = projectInfo.children[0]; 915 ContextInfo exampleInfo = projectInfo.children[0];
893 expect(exampleInfo.folder.path, example); 916 expect(exampleInfo.folder.path, example);
894 expect(exampleInfo.children, isEmpty); 917 expect(exampleInfo.children, isEmpty);
895 } 918 }
896 } 919 }
897 } 920 }
898 expect(callbacks.currentContextPaths, hasLength(2)); 921 expect(callbacks.currentContextRoots, unorderedEquals([project, example]));
899 expect(callbacks.currentContextPaths, unorderedEquals([project, example]));
900 } 922 }
901 923
902 void test_setRoots_newFolderWithPackageRoot() { 924 void test_setRoots_newFolderWithPackageRoot() {
903 String packageRootPath = '/package'; 925 String packageRootPath = '/package';
904 manager.setRoots(<String>[projPath], <String>[], 926 manager.setRoots(<String>[projPath], <String>[],
905 <String, String>{projPath: packageRootPath}); 927 <String, String>{projPath: packageRootPath});
906 _checkPackageRoot(projPath, equals(packageRootPath)); 928 _checkPackageRoot(projPath, equals(packageRootPath));
907 } 929 }
908 930
909 void test_setRoots_newlyAddedFoldersGetProperPackageMap() { 931 void test_setRoots_newlyAddedFoldersGetProperPackageMap() {
(...skipping 20 matching lines...) Expand all
930 manager.setRoots( 952 manager.setRoots(
931 <String>[project], <String>[excludedFolder], <String, String>{}); 953 <String>[project], <String>[excludedFolder], <String, String>{});
932 callbacks.assertContextPaths([project]); 954 callbacks.assertContextPaths([project]);
933 } 955 }
934 956
935 void test_setRoots_noContext_inDotFolder() { 957 void test_setRoots_noContext_inDotFolder() {
936 String pubspecPath = path.posix.join(projPath, '.pub', 'pubspec.yaml'); 958 String pubspecPath = path.posix.join(projPath, '.pub', 'pubspec.yaml');
937 resourceProvider.newFile(pubspecPath, 'name: test'); 959 resourceProvider.newFile(pubspecPath, 'name: test');
938 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 960 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
939 // verify 961 // verify
940 expect(callbacks.currentContextPaths, hasLength(1)); 962 expect(callbacks.currentContextRoots, hasLength(1));
941 expect(callbacks.currentContextPaths, contains(projPath)); 963 expect(callbacks.currentContextRoots, contains(projPath));
942 expect(callbacks.currentContextFilePaths[projPath], hasLength(0)); 964 expect(callbacks.currentFilePaths, hasLength(0));
943 } 965 }
944 966
945 void test_setRoots_noContext_inPackagesFolder() { 967 void test_setRoots_noContext_inPackagesFolder() {
946 String pubspecPath = path.posix.join(projPath, 'packages', 'pubspec.yaml'); 968 String pubspecPath = path.posix.join(projPath, 'packages', 'pubspec.yaml');
947 resourceProvider.newFile(pubspecPath, 'name: test'); 969 resourceProvider.newFile(pubspecPath, 'name: test');
948 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 970 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
949 // verify 971 // verify
950 expect(callbacks.currentContextPaths, hasLength(1)); 972 expect(callbacks.currentContextRoots, hasLength(1));
951 expect(callbacks.currentContextPaths, contains(projPath)); 973 expect(callbacks.currentContextRoots, contains(projPath));
952 expect(callbacks.currentContextFilePaths[projPath], hasLength(0)); 974 expect(callbacks.currentFilePaths, hasLength(0));
953 } 975 }
954 976
955 void test_setRoots_packageResolver() { 977 void test_setRoots_packageResolver() {
956 String filePath = path.posix.join(projPath, 'lib', 'foo.dart'); 978 String filePath = path.posix.join(projPath, 'lib', 'foo.dart');
957 newFile([projPath, ContextManagerImpl.PACKAGE_SPEC_NAME], 'foo:lib/'); 979 newFile([projPath, ContextManagerImpl.PACKAGE_SPEC_NAME], 'foo:lib/');
958 resourceProvider.newFile(filePath, 'contents'); 980 resourceProvider.newFile(filePath, 'contents');
959 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 981 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
960 982
961 List<AnalysisContext> contextsInAnalysisRoot = 983 if (enableAnalysisDriver) {
962 manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath)); 984 var drivers = manager
963 expect(contextsInAnalysisRoot, hasLength(1)); 985 .getDriversInAnalysisRoot(resourceProvider.newFolder(projPath));
964 AnalysisContext context = contextsInAnalysisRoot[0]; 986 expect(drivers, hasLength(1));
965 expect(context, isNotNull); 987 expect(drivers[0], isNotNull);
988 } else {
989 List<AnalysisContext> contextsInAnalysisRoot =
990 manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath));
991 expect(contextsInAnalysisRoot, hasLength(1));
992 expect(contextsInAnalysisRoot[0], isNotNull);
993 }
966 Source result = sourceFactory.forUri('package:foo/foo.dart'); 994 Source result = sourceFactory.forUri('package:foo/foo.dart');
967 expect(result.fullName, filePath); 995 expect(result.fullName, filePath);
968 } 996 }
969 997
970 void test_setRoots_pathContainsDotFile() { 998 void test_setRoots_pathContainsDotFile() {
971 // If the path to a file (relative to the context root) contains a folder 999 // If the path to a file (relative to the context root) contains a folder
972 // whose name begins with '.', then the file is ignored. 1000 // whose name begins with '.', then the file is ignored.
973 String project = '/project'; 1001 String project = '/project';
974 String fileA = '$project/foo.dart'; 1002 String fileA = '$project/foo.dart';
975 String fileB = '$project/.pub/bar.dart'; 1003 String fileB = '$project/.pub/bar.dart';
976 resourceProvider.newFile(fileA, ''); 1004 resourceProvider.newFile(fileA, '');
977 resourceProvider.newFile(fileB, ''); 1005 resourceProvider.newFile(fileB, '');
978 manager.setRoots(<String>[project], <String>[], <String, String>{}); 1006 manager.setRoots(<String>[project], <String>[], <String, String>{});
979 callbacks.assertContextPaths([project]); 1007 callbacks.assertContextPaths([project]);
980 callbacks.assertContextFiles(project, [fileA]); 1008 callbacks.assertContextFiles(project, [fileA]);
981 } 1009 }
982 1010
983 void test_setRoots_removeFolderWithoutPubspec() { 1011 void test_setRoots_removeFolderWithoutPubspec() {
984 packageMapProvider.packageMap = null; 1012 packageMapProvider.packageMap = null;
985 // add one root - there is a context 1013 // add one root - there is a context
986 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 1014 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
987 expect(callbacks.currentContextPaths, hasLength(1)); 1015 expect(callbacks.currentContextRoots, hasLength(1));
988 // set empty roots - no contexts 1016 // set empty roots - no contexts
989 manager.setRoots(<String>[], <String>[], <String, String>{}); 1017 manager.setRoots(<String>[], <String>[], <String, String>{});
990 expect(callbacks.currentContextPaths, hasLength(0)); 1018 expect(callbacks.currentContextRoots, hasLength(0));
991 expect(callbacks.currentContextFilePaths, hasLength(0)); 1019 expect(callbacks.currentFilePaths, hasLength(0));
992 } 1020 }
993 1021
994 void test_setRoots_removeFolderWithPackagespec() { 1022 void test_setRoots_removeFolderWithPackagespec() {
995 // create a pubspec 1023 // create a pubspec
996 String pubspecPath = path.posix.join(projPath, '.packages'); 1024 String pubspecPath = path.posix.join(projPath, '.packages');
997 resourceProvider.newFile(pubspecPath, ''); 1025 resourceProvider.newFile(pubspecPath, '');
998 // add one root - there is a context 1026 // add one root - there is a context
999 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 1027 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
1000 expect(manager.changeSubscriptions, hasLength(1)); 1028 expect(manager.changeSubscriptions, hasLength(1));
1001 expect(callbacks.currentContextPaths, hasLength(1)); 1029 expect(callbacks.currentContextRoots, hasLength(1));
1002 // set empty roots - no contexts 1030 // set empty roots - no contexts
1003 manager.setRoots(<String>[], <String>[], <String, String>{}); 1031 manager.setRoots(<String>[], <String>[], <String, String>{});
1004 expect(manager.changeSubscriptions, hasLength(0)); 1032 expect(manager.changeSubscriptions, hasLength(0));
1005 expect(callbacks.currentContextPaths, hasLength(0)); 1033 expect(callbacks.currentContextRoots, hasLength(0));
1006 expect(callbacks.currentContextFilePaths, hasLength(0)); 1034 expect(callbacks.currentFilePaths, hasLength(0));
1007 } 1035 }
1008 1036
1009 void test_setRoots_removeFolderWithPackagespecFolder() { 1037 void test_setRoots_removeFolderWithPackagespecFolder() {
1010 // prepare paths 1038 // prepare paths
1011 String projectA = '/projectA'; 1039 String projectA = '/projectA';
1012 String projectB = '/projectB'; 1040 String projectB = '/projectB';
1013 String subProjectA = '$projectA/sub'; 1041 String subProjectA = '$projectA/sub';
1014 String subProjectB = '$projectB/sub'; 1042 String subProjectB = '$projectB/sub';
1015 String projectA_file = '$projectA/a.dart'; 1043 String projectA_file = '$projectA/a.dart';
1016 String projectB_file = '$projectB/a.dart'; 1044 String projectB_file = '$projectB/a.dart';
(...skipping 23 matching lines...) Expand all
1040 callbacks.assertContextFiles(projectA, [projectA_file]); 1068 callbacks.assertContextFiles(projectA, [projectA_file]);
1041 callbacks.assertContextFiles(subProjectA, [subProjectA_file]); 1069 callbacks.assertContextFiles(subProjectA, [subProjectA_file]);
1042 } 1070 }
1043 1071
1044 void test_setRoots_removeFolderWithPubspec() { 1072 void test_setRoots_removeFolderWithPubspec() {
1045 // create a pubspec 1073 // create a pubspec
1046 String pubspecPath = path.posix.join(projPath, 'pubspec.yaml'); 1074 String pubspecPath = path.posix.join(projPath, 'pubspec.yaml');
1047 resourceProvider.newFile(pubspecPath, 'pubspec'); 1075 resourceProvider.newFile(pubspecPath, 'pubspec');
1048 // add one root - there is a context 1076 // add one root - there is a context
1049 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 1077 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
1050 expect(callbacks.currentContextPaths, hasLength(1)); 1078 expect(callbacks.currentContextRoots, hasLength(1));
1051 // set empty roots - no contexts 1079 // set empty roots - no contexts
1052 manager.setRoots(<String>[], <String>[], <String, String>{}); 1080 manager.setRoots(<String>[], <String>[], <String, String>{});
1053 expect(callbacks.currentContextPaths, hasLength(0)); 1081 expect(callbacks.currentContextRoots, hasLength(0));
1054 expect(callbacks.currentContextFilePaths, hasLength(0)); 1082 expect(callbacks.currentFilePaths, hasLength(0));
1055 } 1083 }
1056 1084
1057 void test_setRoots_removeFolderWithPubspecFolder() { 1085 void test_setRoots_removeFolderWithPubspecFolder() {
1058 // prepare paths 1086 // prepare paths
1059 String projectA = '/projectA'; 1087 String projectA = '/projectA';
1060 String projectB = '/projectB'; 1088 String projectB = '/projectB';
1061 String subProjectA = '$projectA/sub'; 1089 String subProjectA = '$projectA/sub';
1062 String subProjectB = '$projectB/sub'; 1090 String subProjectB = '$projectB/sub';
1063 String projectA_file = '$projectA/a.dart'; 1091 String projectA_file = '$projectA/a.dart';
1064 String projectB_file = '$projectB/a.dart'; 1092 String projectB_file = '$projectB/a.dart';
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1116 String fileA = '$project/foo.dart'; 1144 String fileA = '$project/foo.dart';
1117 resourceProvider.newFile(fileA, ''); 1145 resourceProvider.newFile(fileA, '');
1118 manager.setRoots(<String>[project], <String>[], <String, String>{}); 1146 manager.setRoots(<String>[project], <String>[], <String, String>{});
1119 callbacks.assertContextPaths([project]); 1147 callbacks.assertContextPaths([project]);
1120 callbacks.assertContextFiles(project, [fileA]); 1148 callbacks.assertContextFiles(project, [fileA]);
1121 } 1149 }
1122 1150
1123 test_watch_addDummyLink() { 1151 test_watch_addDummyLink() {
1124 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 1152 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
1125 // empty folder initially 1153 // empty folder initially
1126 Map<String, int> filePaths = callbacks.currentContextFilePaths[projPath]; 1154 expect(callbacks.currentFilePaths, isEmpty);
1127 expect(filePaths, isEmpty);
1128 // add link 1155 // add link
1129 String filePath = path.posix.join(projPath, 'foo.dart'); 1156 String filePath = path.posix.join(projPath, 'foo.dart');
1130 resourceProvider.newDummyLink(filePath); 1157 resourceProvider.newDummyLink(filePath);
1131 // the link was ignored 1158 // the link was ignored
1132 return pumpEventQueue().then((_) { 1159 return pumpEventQueue().then((_) {
1133 expect(filePaths, isEmpty); 1160 expect(callbacks.currentFilePaths, isEmpty);
1134 }); 1161 });
1135 } 1162 }
1136 1163
1137 test_watch_addFile() { 1164 test_watch_addFile() {
1138 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 1165 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
1139 // empty folder initially 1166 // empty folder initially
1140 Map<String, int> filePaths = callbacks.currentContextFilePaths[projPath]; 1167 expect(callbacks.currentFilePaths, hasLength(0));
1141 expect(filePaths, hasLength(0));
1142 // add file 1168 // add file
1143 String filePath = path.posix.join(projPath, 'foo.dart'); 1169 String filePath = path.posix.join(projPath, 'foo.dart');
1144 resourceProvider.newFile(filePath, 'contents'); 1170 resourceProvider.newFile(filePath, 'contents');
1145 // the file was added 1171 // the file was added
1146 return pumpEventQueue().then((_) { 1172 return pumpEventQueue().then((_) {
1173 Iterable<String> filePaths = callbacks.currentFilePaths;
1147 expect(filePaths, hasLength(1)); 1174 expect(filePaths, hasLength(1));
1148 expect(filePaths, contains(filePath)); 1175 expect(filePaths, contains(filePath));
1149 }); 1176 });
1150 } 1177 }
1151 1178
1152 test_watch_addFile_excluded() { 1179 test_watch_addFile_excluded() {
1153 // prepare paths 1180 // prepare paths
1154 String project = '/project'; 1181 String project = '/project';
1155 String folderA = '$project/aaa'; 1182 String folderA = '$project/aaa';
1156 String folderB = '$project/bbb'; 1183 String folderB = '$project/bbb';
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1236 callbacks.assertContextFiles(project, [fileA]); 1263 callbacks.assertContextFiles(project, [fileA]);
1237 resourceProvider.newFile(fileB, ''); 1264 resourceProvider.newFile(fileB, '');
1238 await pumpEventQueue(); 1265 await pumpEventQueue();
1239 callbacks.assertContextPaths([project]); 1266 callbacks.assertContextPaths([project]);
1240 callbacks.assertContextFiles(project, [fileA, fileB]); 1267 callbacks.assertContextFiles(project, [fileA, fileB]);
1241 } 1268 }
1242 1269
1243 test_watch_addFileInSubfolder() { 1270 test_watch_addFileInSubfolder() {
1244 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 1271 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
1245 // empty folder initially 1272 // empty folder initially
1246 Map<String, int> filePaths = callbacks.currentContextFilePaths[projPath]; 1273 expect(callbacks.currentFilePaths, hasLength(0));
1247 expect(filePaths, hasLength(0));
1248 // add file in subfolder 1274 // add file in subfolder
1249 String filePath = path.posix.join(projPath, 'foo', 'bar.dart'); 1275 String filePath = path.posix.join(projPath, 'foo', 'bar.dart');
1250 resourceProvider.newFile(filePath, 'contents'); 1276 resourceProvider.newFile(filePath, 'contents');
1251 // the file was added 1277 // the file was added
1252 return pumpEventQueue().then((_) { 1278 return pumpEventQueue().then((_) {
1279 Iterable<String> filePaths = callbacks.currentFilePaths;
1253 expect(filePaths, hasLength(1)); 1280 expect(filePaths, hasLength(1));
1254 expect(filePaths, contains(filePath)); 1281 expect(filePaths, contains(filePath));
1255 }); 1282 });
1256 } 1283 }
1257 1284
1258 test_watch_addPackagespec_toRoot() { 1285 test_watch_addPackagespec_toRoot() {
1259 // prepare paths 1286 // prepare paths
1260 String root = '/root'; 1287 String root = '/root';
1261 String rootFile = '$root/root.dart'; 1288 String rootFile = '$root/root.dart';
1262 String rootPackagespec = '$root/.packages'; 1289 String rootPackagespec = '$root/.packages';
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
1426 }); 1453 });
1427 } 1454 }
1428 1455
1429 test_watch_deleteFile() { 1456 test_watch_deleteFile() {
1430 String filePath = path.posix.join(projPath, 'foo.dart'); 1457 String filePath = path.posix.join(projPath, 'foo.dart');
1431 // add root with a file 1458 // add root with a file
1432 File file = resourceProvider.newFile(filePath, 'contents'); 1459 File file = resourceProvider.newFile(filePath, 'contents');
1433 Folder projFolder = file.parent; 1460 Folder projFolder = file.parent;
1434 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 1461 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
1435 // the file was added 1462 // the file was added
1436 Map<String, int> filePaths = callbacks.currentContextFilePaths[projPath]; 1463 Iterable<String> filePaths = callbacks.currentFilePaths;
1437 expect(filePaths, hasLength(1)); 1464 expect(filePaths, hasLength(1));
1438 expect(filePaths, contains(filePath)); 1465 expect(filePaths, contains(filePath));
1439 expect(file.exists, isTrue); 1466 expect(file.exists, isTrue);
1440 expect(projFolder.exists, isTrue); 1467 expect(projFolder.exists, isTrue);
1441 // delete the file 1468 // delete the file
1442 resourceProvider.deleteFile(filePath); 1469 resourceProvider.deleteFile(filePath);
1443 return pumpEventQueue().then((_) { 1470 return pumpEventQueue().then((_) {
1444 expect(file.exists, isFalse); 1471 expect(file.exists, isFalse);
1445 expect(projFolder.exists, isTrue); 1472 expect(projFolder.exists, isTrue);
1446 return expect(filePaths, hasLength(0)); 1473 return expect(callbacks.currentFilePaths, hasLength(0));
1447 }); 1474 });
1448 } 1475 }
1449 1476
1450 test_watch_deleteFolder() { 1477 test_watch_deleteFolder() {
1451 String filePath = path.posix.join(projPath, 'foo.dart'); 1478 String filePath = path.posix.join(projPath, 'foo.dart');
1452 // add root with a file 1479 // add root with a file
1453 File file = resourceProvider.newFile(filePath, 'contents'); 1480 File file = resourceProvider.newFile(filePath, 'contents');
1454 Folder projFolder = file.parent; 1481 Folder projFolder = file.parent;
1455 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 1482 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
1456 // the file was added 1483 // the file was added
1457 Map<String, int> filePaths = callbacks.currentContextFilePaths[projPath]; 1484 Iterable<String> filePaths = callbacks.currentFilePaths;
1458 expect(filePaths, hasLength(1)); 1485 expect(filePaths, hasLength(1));
1459 expect(filePaths, contains(filePath)); 1486 expect(filePaths, contains(filePath));
1460 expect(file.exists, isTrue); 1487 expect(file.exists, isTrue);
1461 expect(projFolder.exists, isTrue); 1488 expect(projFolder.exists, isTrue);
1462 // delete the folder 1489 // delete the folder
1463 resourceProvider.deleteFolder(projPath); 1490 resourceProvider.deleteFolder(projPath);
1464 return pumpEventQueue().then((_) { 1491 return pumpEventQueue().then((_) {
1465 expect(file.exists, isFalse); 1492 expect(file.exists, isFalse);
1466 expect(projFolder.exists, isFalse); 1493 expect(projFolder.exists, isFalse);
1467 return expect(filePaths, hasLength(0)); 1494 return expect(callbacks.currentFilePaths, hasLength(0));
1468 }); 1495 });
1469 } 1496 }
1470 1497
1471 test_watch_deletePackagespec_fromRoot() { 1498 test_watch_deletePackagespec_fromRoot() {
1472 // prepare paths 1499 // prepare paths
1473 String root = '/root'; 1500 String root = '/root';
1474 String rootPubspec = '$root/.packages'; 1501 String rootPubspec = '$root/.packages';
1475 String rootFile = '$root/root.dart'; 1502 String rootFile = '$root/root.dart';
1476 // create files 1503 // create files
1477 resourceProvider.newFile(rootPubspec, ''); 1504 resourceProvider.newFile(rootPubspec, '');
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
1595 callbacks.assertContextFiles(root, [rootFile, subFile]); 1622 callbacks.assertContextFiles(root, [rootFile, subFile]);
1596 }); 1623 });
1597 } 1624 }
1598 1625
1599 test_watch_modifyFile() { 1626 test_watch_modifyFile() {
1600 String filePath = path.posix.join(projPath, 'foo.dart'); 1627 String filePath = path.posix.join(projPath, 'foo.dart');
1601 // add root with a file 1628 // add root with a file
1602 resourceProvider.newFile(filePath, 'contents'); 1629 resourceProvider.newFile(filePath, 'contents');
1603 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 1630 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
1604 // the file was added 1631 // the file was added
1605 Map<String, int> filePaths = callbacks.currentContextFilePaths[projPath]; 1632 if (enableAnalysisDriver) {
1606 expect(filePaths, hasLength(1)); 1633 Iterable<String> filePaths = callbacks.currentFilePaths;
1607 expect(filePaths, contains(filePath)); 1634 expect(filePaths, hasLength(1));
1608 expect(filePaths[filePath], equals(callbacks.now)); 1635 expect(filePaths, contains(filePath));
1636 // TODO(brianwilkerson) Test when the file was modified
1637 } else {
1638 Map<String, int> filePaths = callbacks.currentContextFilePaths[projPath];
1639 expect(filePaths, hasLength(1));
1640 expect(filePaths, contains(filePath));
1641 expect(filePaths[filePath], equals(callbacks.now));
1642 }
1609 // update the file 1643 // update the file
1610 callbacks.now++; 1644 callbacks.now++;
1611 resourceProvider.modifyFile(filePath, 'new contents'); 1645 resourceProvider.modifyFile(filePath, 'new contents');
1612 return pumpEventQueue().then((_) { 1646 return pumpEventQueue().then((_) {
1647 if (enableAnalysisDriver) {
1648 // TODO(brianwilkerson) Test when the file was modified
1649 return null;
1650 }
1651 Map<String, int> filePaths = callbacks.currentContextFilePaths[projPath];
1613 return expect(filePaths[filePath], equals(callbacks.now)); 1652 return expect(filePaths[filePath], equals(callbacks.now));
1614 }); 1653 });
1615 } 1654 }
1616 1655
1617 test_watch_modifyPackageMapDependency_fail() async { 1656 test_watch_modifyPackageMapDependency_fail() async {
1618 // create a dependency file 1657 // create a dependency file
1619 String dependencyPath = path.posix.join(projPath, 'dep'); 1658 String dependencyPath = path.posix.join(projPath, 'dep');
1620 resourceProvider.newFile(dependencyPath, 'contents'); 1659 resourceProvider.newFile(dependencyPath, 'contents');
1621 packageMapProvider.dependencies.add(dependencyPath); 1660 packageMapProvider.dependencies.add(dependencyPath);
1622 // create a Dart file 1661 // create a Dart file
(...skipping 13 matching lines...) Expand all
1636 1675
1637 test_watch_modifyPackagespec() { 1676 test_watch_modifyPackagespec() {
1638 String packagesPath = '$projPath/.packages'; 1677 String packagesPath = '$projPath/.packages';
1639 String filePath = '$projPath/bin/main.dart'; 1678 String filePath = '$projPath/bin/main.dart';
1640 1679
1641 resourceProvider.newFile(packagesPath, ''); 1680 resourceProvider.newFile(packagesPath, '');
1642 resourceProvider.newFile(filePath, 'library main;'); 1681 resourceProvider.newFile(filePath, 'library main;');
1643 1682
1644 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 1683 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
1645 1684
1646 Map<String, int> filePaths = callbacks.currentContextFilePaths[projPath]; 1685 Iterable<String> filePaths = callbacks.currentFilePaths;
1647 expect(filePaths, hasLength(1)); 1686 expect(filePaths, hasLength(1));
1648 expect(filePaths, contains(filePath)); 1687 expect(filePaths, contains(filePath));
1649 expect(_currentPackageMap, isEmpty); 1688 expect(_currentPackageMap, isEmpty);
1650 1689
1651 // update .packages 1690 // update .packages
1652 callbacks.now++; 1691 callbacks.now++;
1653 resourceProvider.modifyFile(packagesPath, 'main:./lib/'); 1692 resourceProvider.modifyFile(packagesPath, 'main:./lib/');
1654 return pumpEventQueue().then((_) { 1693 return pumpEventQueue().then((_) {
1655 // verify new package info 1694 // verify new package info
1656 expect(_currentPackageMap.keys, unorderedEquals(['main'])); 1695 expect(_currentPackageMap.keys, unorderedEquals(['main']));
1657 }); 1696 });
1658 } 1697 }
1659 1698
1660 /** 1699 /**
1661 * Verify that package URI's for source files in [path] will be resolved 1700 * Verify that package URI's for source files in [path] will be resolved
1662 * using a package root matching [expectation]. 1701 * using a package root matching [expectation].
1663 */ 1702 */
1664 void _checkPackageRoot(String path, expectation) { 1703 void _checkPackageRoot(String path, expectation) {
1665 // TODO(brianwilkerson) Figure out how to test this. Possibly by comparing 1704 // TODO(brianwilkerson) Figure out how to test this. Possibly by comparing
1666 // the contents of the package map (although that approach doesn't work at 1705 // the contents of the package map (although that approach doesn't work at
1667 // the moment). 1706 // the moment).
1668 // FolderDisposition disposition = callbacks.currentContextDispositions[path] ; 1707 // FolderDisposition disposition = callbacks.currentContextDispositions[path] ;
1669 // expect(disposition.packageRoot, expectation); 1708 // expect(disposition.packageRoot, expectation);
1670 // TODO(paulberry): we should also verify that the package map itself is 1709 // TODO(paulberry): we should also verify that the package map itself is
1671 // correct. See dartbug.com/23909. 1710 // correct. See dartbug.com/23909.
1672 } 1711 }
1712 }
1673 1713
1674 Map<String, List<Folder>> _packageMap(String contextPath) { 1714 @reflectiveTest
1675 Folder folder = resourceProvider.getFolder(contextPath); 1715 class AbstractContextManagerTest_Driver extends AbstractContextManagerTest {
1676 return manager.folderMap[folder]?.sourceFactory?.packageMap; 1716 bool get enableAnalysisDriver => true;
1717
1718 @failingTest
1719 test_embedder_added() {
1720 // NoSuchMethodError: The getter 'apiSignature' was called on null.
1721 // Receiver: null
1722 // Tried calling: apiSignature
1723 // dart:core Object .noSuchMethod
1724 // package:analyzer/src/dart/analysis/driver.dart 460:20 Analys isDriver.configure
1725 // package:analysis_server/src/context_manager.dart 1043:16 Contex tManagerImpl._checkForPackagespecUpdate
1726 // package:analysis_server/src/context_manager.dart 1553:5 Contex tManagerImpl._handleWatchEvent
1727 //return super.test_embedder_added();
1728 fail('NoSuchMethodError');
1729 }
1730
1731 @failingTest
1732 test_embedder_packagespec() async {
1733 // NoSuchMethodError: The getter 'apiSignature' was called on null.
1734 // Receiver: null
1735 // Tried calling: apiSignature
1736 // dart:core Object .noSuchMethod
1737 // package:analyzer/src/dart/analysis/driver.dart 248:20 Analys isDriver.AnalysisDriver
1738 // test/context_manager_test.dart 2698:25 TestCo ntextManagerCallbacks.addAnalysisDriver
1739 // package:analysis_server/src/context_manager.dart 1186:39 Contex tManagerImpl._createContext
1740 // package:analysis_server/src/context_manager.dart 1247:16 Contex tManagerImpl._createContexts
1741 // package:analysis_server/src/context_manager.dart 886:9 Contex tManagerImpl.setRoots
1742 // test/context_manager_test.dart 154:13 Abstra ctContextManagerTest.test_embedder_packagespec.<async>
1743 return super.test_embedder_packagespec();
1744 }
1745
1746 @failingTest
1747 void test_setRoots_addPackageRoot() {
1748 // Bad state: Should not be used with the new analysis driver
1749 // package:analysis_server/src/context_manager.dart 561:7 Contex tManagerImpl.folderMap
1750 // package:analysis_server/src/context_manager.dart 1709:31 Contex tManagerImpl._updateContextPackageUriResolver
1751 // package:analysis_server/src/context_manager.dart 1668:5 Contex tManagerImpl._recomputeFolderDisposition
1752 // package:analysis_server/src/context_manager.dart 1420:7 Contex tManagerImpl._handleWatchEvent
1753 return super.test_setRoots_addPackageRoot();
1754 }
1755
1756 @failingTest
1757 void test_setRoots_changePackageRoot() {
1758 // Bad state: Should not be used with the new analysis driver
1759 // package:analysis_server/src/context_manager.dart 561:7 Contex tManagerImpl.folderMap
1760 // package:analysis_server/src/context_manager.dart 1709:31 Contex tManagerImpl._updateContextPackageUriResolver
1761 // package:analysis_server/src/context_manager.dart 1668:5 Contex tManagerImpl._recomputeFolderDisposition
1762 // package:analysis_server/src/context_manager.dart 1420:7 Contex tManagerImpl._handleWatchEvent
1763 return super.test_setRoots_changePackageRoot();
1764 }
1765
1766 @failingTest
1767 void test_setRoots_removePackageRoot() {
1768 // Bad state: Should not be used with the new analysis driver
1769 // package:analysis_server/src/context_manager.dart 561:7 Contex tManagerImpl.folderMap
1770 // package:analysis_server/src/context_manager.dart 1709:31 Contex tManagerImpl._updateContextPackageUriResolver
1771 // package:analysis_server/src/context_manager.dart 1668:5 Contex tManagerImpl._recomputeFolderDisposition
1772 // package:analysis_server/src/context_manager.dart 1420:7 Contex tManagerImpl._handleWatchEvent
1773 return super.test_setRoots_removePackageRoot();
1774 }
1775
1776 @failingTest
1777 test_watch_modifyPackageMapDependency_fail() async {
1778 // Bad state: Should not be used with the new analysis driver
1779 // package:analysis_server/src/context_manager.dart 561:7 Contex tManagerImpl.folderMap
1780 // package:analysis_server/src/context_manager.dart 1709:31 Contex tManagerImpl._updateContextPackageUriResolver
1781 // package:analysis_server/src/context_manager.dart 1668:5 Contex tManagerImpl._recomputeFolderDisposition
1782 // package:analysis_server/src/context_manager.dart 1420:7 Contex tManagerImpl._handleWatchEvent
1783 //return super.test_watch_modifyPackageMapDependency_fail();
1784 fail('StateError thrown');
1677 } 1785 }
1678 } 1786 }
1679 1787
1680 abstract class ContextManagerTest { 1788 abstract class ContextManagerTest {
1681 /** 1789 /**
1682 * The name of the 'bin' directory. 1790 * The name of the 'bin' directory.
1683 */ 1791 */
1684 static const String BIN_NAME = 'bin'; 1792 static const String BIN_NAME = 'bin';
1685 1793
1686 /** 1794 /**
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
1839 // the contents of the package map (although that approach doesn't work at 1947 // the contents of the package map (although that approach doesn't work at
1840 // the moment). 1948 // the moment).
1841 // FolderDisposition disposition = callbacks.currentContextDispositions[path] ; 1949 // FolderDisposition disposition = callbacks.currentContextDispositions[path] ;
1842 // expect(disposition.packageRoot, expectation); 1950 // expect(disposition.packageRoot, expectation);
1843 // TODO(paulberry): we should also verify that the package map itself is 1951 // TODO(paulberry): we should also verify that the package map itself is
1844 // correct. See dartbug.com/23909. 1952 // correct. See dartbug.com/23909.
1845 } 1953 }
1846 1954
1847 Map<String, List<Folder>> _packageMap(String contextPath) { 1955 Map<String, List<Folder>> _packageMap(String contextPath) {
1848 Folder folder = resourceProvider.getFolder(contextPath); 1956 Folder folder = resourceProvider.getFolder(contextPath);
1849 return manager.folderMap[folder]?.sourceFactory?.packageMap; 1957 if (enableAnalysisDriver) {
1958 ContextInfo info = manager.getContextInfoFor(folder);
1959 return info.analysisDriver.sourceFactory?.packageMap;
1960 } else {
1961 return manager.folderMap[folder]?.sourceFactory?.packageMap;
1962 }
1850 } 1963 }
1851 } 1964 }
1852 1965
1853 @reflectiveTest 1966 @reflectiveTest
1854 class ContextManagerWithNewOptionsTest extends ContextManagerWithOptionsTest { 1967 class ContextManagerWithNewOptionsTest extends ContextManagerWithOptionsTest {
1855 String get optionsFileName => AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE; 1968 String get optionsFileName => AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE;
1856 } 1969 }
1857 1970
1858 @reflectiveTest 1971 @reflectiveTest
1859 class ContextManagerWithNewOptionsTest_Driver 1972 class ContextManagerWithNewOptionsTest_Driver
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after
2390 - 'other_lib' 2503 - 'other_lib'
2391 '''); 2504 ''');
2392 // Setup context. 2505 // Setup context.
2393 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 2506 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
2394 // Verify that the context in other_lib wasn't created and that the 2507 // Verify that the context in other_lib wasn't created and that the
2395 // context in lib was created. 2508 // context in lib was created.
2396 Folder projectFolder = resourceProvider.newFolder(projPath); 2509 Folder projectFolder = resourceProvider.newFolder(projPath);
2397 if (enableAnalysisDriver) { 2510 if (enableAnalysisDriver) {
2398 var drivers = manager.getDriversInAnalysisRoot(projectFolder); 2511 var drivers = manager.getDriversInAnalysisRoot(projectFolder);
2399 expect(drivers, hasLength(2)); 2512 expect(drivers, hasLength(2));
2400 expect(drivers[0].name, equals('proj')); 2513 expect(drivers[0].name, equals('/my/proj'));
2401 expect(drivers[1].name, equals('lib')); 2514 expect(drivers[1].name, equals('/my/proj/lib'));
2402 } else { 2515 } else {
2403 var contexts = 2516 var contexts =
2404 manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath)); 2517 manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath));
2405 expect(contexts.length, 2); 2518 expect(contexts.length, 2);
2406 expect(contexts[0].name, equals('/my/proj')); 2519 expect(contexts[0].name, equals('/my/proj'));
2407 expect(contexts[1].name, equals('/my/proj/lib')); 2520 expect(contexts[1].name, equals('/my/proj/lib'));
2408 } 2521 }
2409 } 2522 }
2410 2523
2411 test_path_filter_recursive_wildcard_child_contexts_option() async { 2524 test_path_filter_recursive_wildcard_child_contexts_option() async {
(...skipping 23 matching lines...) Expand all
2435 '''); 2548 ''');
2436 // Setup context. 2549 // Setup context.
2437 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 2550 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
2438 2551
2439 // Verify that the context in other_lib wasn't created and that the 2552 // Verify that the context in other_lib wasn't created and that the
2440 // context in lib was created. 2553 // context in lib was created.
2441 Folder projectFolder = resourceProvider.newFolder(projPath); 2554 Folder projectFolder = resourceProvider.newFolder(projPath);
2442 if (enableAnalysisDriver) { 2555 if (enableAnalysisDriver) {
2443 var drivers = manager.getDriversInAnalysisRoot(projectFolder); 2556 var drivers = manager.getDriversInAnalysisRoot(projectFolder);
2444 expect(drivers, hasLength(2)); 2557 expect(drivers, hasLength(2));
2445 expect(drivers[0].name, equals('proj')); 2558 expect(drivers[0].name, equals('/my/proj'));
2446 expect(drivers[1].name, equals('lib')); 2559 expect(drivers[1].name, equals('/my/proj/lib'));
2447 } else { 2560 } else {
2448 var contexts = manager.contextsInAnalysisRoot(projectFolder); 2561 var contexts = manager.contextsInAnalysisRoot(projectFolder);
2449 expect(contexts.length, 2); 2562 expect(contexts.length, 2);
2450 expect(contexts[0].name, equals('/my/proj')); 2563 expect(contexts[0].name, equals('/my/proj'));
2451 expect(contexts[1].name, equals('/my/proj/lib')); 2564 expect(contexts[1].name, equals('/my/proj/lib'));
2452 } 2565 }
2453 } 2566 }
2454 2567
2455 test_path_filter_wildcard_child_contexts_option() async { 2568 test_path_filter_wildcard_child_contexts_option() async {
2456 // Create files. 2569 // Create files.
(...skipping 20 matching lines...) Expand all
2477 exclude: 2590 exclude:
2478 - 'other_lib/*' 2591 - 'other_lib/*'
2479 '''); 2592 ''');
2480 // Setup context / driver. 2593 // Setup context / driver.
2481 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 2594 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
2482 2595
2483 Folder projectFolder = resourceProvider.newFolder(projPath); 2596 Folder projectFolder = resourceProvider.newFolder(projPath);
2484 if (enableAnalysisDriver) { 2597 if (enableAnalysisDriver) {
2485 var drivers = manager.getDriversInAnalysisRoot(projectFolder); 2598 var drivers = manager.getDriversInAnalysisRoot(projectFolder);
2486 expect(drivers, hasLength(2)); 2599 expect(drivers, hasLength(2));
2487 expect(drivers[0].name, equals('proj')); 2600 expect(drivers[0].name, equals('/my/proj'));
2488 expect(drivers[1].name, equals('lib')); 2601 expect(drivers[1].name, equals('/my/proj/lib'));
2489 } else { 2602 } else {
2490 // Verify that the context in other_lib wasn't created and that the 2603 // Verify that the context in other_lib wasn't created and that the
2491 // context in lib was created. 2604 // context in lib was created.
2492 var contexts = manager.contextsInAnalysisRoot(projectFolder); 2605 var contexts = manager.contextsInAnalysisRoot(projectFolder);
2493 expect(contexts, hasLength(2)); 2606 expect(contexts, hasLength(2));
2494 expect(contexts[0].name, equals('/my/proj')); 2607 expect(contexts[0].name, equals('/my/proj'));
2495 expect(contexts[1].name, equals('/my/proj/lib')); 2608 expect(contexts[1].name, equals('/my/proj/lib'));
2496 } 2609 }
2497 } 2610 }
2498 2611
(...skipping 22 matching lines...) Expand all
2521 ContextInfo projectInfo = rootInfo.children[0]; 2634 ContextInfo projectInfo = rootInfo.children[0];
2522 expect(projectInfo.folder.path, project); 2635 expect(projectInfo.folder.path, project);
2523 expect(projectInfo.children, hasLength(1)); 2636 expect(projectInfo.children, hasLength(1));
2524 { 2637 {
2525 ContextInfo exampleInfo = projectInfo.children[0]; 2638 ContextInfo exampleInfo = projectInfo.children[0];
2526 expect(exampleInfo.folder.path, example); 2639 expect(exampleInfo.folder.path, example);
2527 expect(exampleInfo.children, isEmpty); 2640 expect(exampleInfo.children, isEmpty);
2528 } 2641 }
2529 } 2642 }
2530 } 2643 }
2531 expect(callbacks.currentContextPaths, hasLength(2)); 2644 expect(callbacks.currentContextRoots, hasLength(2));
2532 expect(callbacks.currentContextPaths, unorderedEquals([project, example])); 2645 expect(callbacks.currentContextRoots, unorderedEquals([project, example]));
2533 } 2646 }
2534 2647
2535 void test_setRoots_nested_excludedByOuter_deep() { 2648 void test_setRoots_nested_excludedByOuter_deep() {
2536 String a = '/a'; 2649 String a = '/a';
2537 String c = '$a/b/c'; 2650 String c = '$a/b/c';
2538 String aPubspec = '$a/pubspec.yaml'; 2651 String aPubspec = '$a/pubspec.yaml';
2539 String cPubspec = '$c/pubspec.yaml'; 2652 String cPubspec = '$c/pubspec.yaml';
2540 // create files 2653 // create files
2541 resourceProvider.newFile(aPubspec, 'name: aaa'); 2654 resourceProvider.newFile(aPubspec, 'name: aaa');
2542 resourceProvider.newFile(cPubspec, 'name: ccc'); 2655 resourceProvider.newFile(cPubspec, 'name: ccc');
(...skipping 13 matching lines...) Expand all
2556 ContextInfo aInfo = rootInfo.children[0]; 2669 ContextInfo aInfo = rootInfo.children[0];
2557 expect(aInfo.folder.path, a); 2670 expect(aInfo.folder.path, a);
2558 expect(aInfo.children, hasLength(1)); 2671 expect(aInfo.children, hasLength(1));
2559 { 2672 {
2560 ContextInfo cInfo = aInfo.children[0]; 2673 ContextInfo cInfo = aInfo.children[0];
2561 expect(cInfo.folder.path, c); 2674 expect(cInfo.folder.path, c);
2562 expect(cInfo.children, isEmpty); 2675 expect(cInfo.children, isEmpty);
2563 } 2676 }
2564 } 2677 }
2565 } 2678 }
2566 expect(callbacks.currentContextPaths, hasLength(2)); 2679 expect(callbacks.currentContextRoots, hasLength(2));
2567 expect(callbacks.currentContextPaths, unorderedEquals([a, c])); 2680 expect(callbacks.currentContextRoots, unorderedEquals([a, c]));
2568 } 2681 }
2569 2682
2570 test_strong_mode_analysis_option() async { 2683 test_strong_mode_analysis_option() async {
2571 // Create files. 2684 // Create files.
2572 newFile( 2685 newFile(
2573 [projPath, optionsFileName], 2686 [projPath, optionsFileName],
2574 r''' 2687 r'''
2575 analyzer: 2688 analyzer:
2576 strong-mode: true 2689 strong-mode: true
2577 '''); 2690 ''');
(...skipping 16 matching lines...) Expand all
2594 * The analysis context that was created. 2707 * The analysis context that was created.
2595 */ 2708 */
2596 AnalysisContext currentContext; 2709 AnalysisContext currentContext;
2597 2710
2598 /** 2711 /**
2599 * The analysis driver that was created. 2712 * The analysis driver that was created.
2600 */ 2713 */
2601 AnalysisDriver currentDriver; 2714 AnalysisDriver currentDriver;
2602 2715
2603 /** 2716 /**
2717 * A table mapping paths to the analysis driver associated with that path.
2718 */
2719 Map<String, AnalysisDriver> driverMap = <String, AnalysisDriver>{};
2720
2721 /**
2604 * Map from context to the timestamp when the context was created. 2722 * Map from context to the timestamp when the context was created.
2605 */ 2723 */
2606 Map<String, int> currentContextTimestamps = <String, int>{}; 2724 Map<String, int> currentContextTimestamps = <String, int>{};
2607 2725
2608 /** 2726 /**
2609 * Map from context to (map from file path to timestamp of last event). 2727 * Map from context to (map from file path to timestamp of last event).
2610 */ 2728 */
2611 final Map<String, Map<String, int>> currentContextFilePaths = 2729 final Map<String, Map<String, int>> currentContextFilePaths =
2612 <String, Map<String, int>>{}; 2730 <String, Map<String, int>>{};
2613 2731
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2647 this.resourceProvider, this.sdkManager, this.logger, this.scheduler); 2765 this.resourceProvider, this.sdkManager, this.logger, this.scheduler);
2648 2766
2649 /** 2767 /**
2650 * Return the current set of analysis options. 2768 * Return the current set of analysis options.
2651 */ 2769 */
2652 AnalysisOptions get analysisOptions => currentDriver == null 2770 AnalysisOptions get analysisOptions => currentDriver == null
2653 ? currentContext.analysisOptions 2771 ? currentContext.analysisOptions
2654 : currentDriver.analysisOptions; 2772 : currentDriver.analysisOptions;
2655 2773
2656 /** 2774 /**
2657 * Iterable of the paths to contexts that currently exist. 2775 * Return the paths to the context roots that currently exist.
2658 */ 2776 */
2659 Iterable<String> get currentContextPaths => currentContextTimestamps.keys; 2777 Iterable<String> get currentContextRoots {
2778 return currentContextTimestamps.keys;
2779 }
2780
2781 /**
2782 * Return the paths to the files being analyzed in the current context root.
2783 */
2784 Iterable<String> get currentFilePaths {
2785 if (currentDriver == null) {
2786 if (currentContext == null) {
2787 return <String>[];
2788 }
2789 Map<String, int> fileMap = currentContextFilePaths[currentContext.name];
2790 if (fileMap == null) {
2791 return <String>[];
2792 }
2793 return fileMap.keys;
2794 }
2795 return currentDriver.addedFiles;
2796 }
2660 2797
2661 /** 2798 /**
2662 * Return the current source factory. 2799 * Return the current source factory.
2663 */ 2800 */
2664 SourceFactory get sourceFactory => currentDriver == null 2801 SourceFactory get sourceFactory => currentDriver == null
2665 ? currentContext.sourceFactory 2802 ? currentContext.sourceFactory
2666 : currentDriver.sourceFactory; 2803 : currentDriver.sourceFactory;
2667 2804
2668 @override 2805 @override
2669 AnalysisDriver addAnalysisDriver(Folder folder, AnalysisOptions options) { 2806 AnalysisDriver addAnalysisDriver(Folder folder, AnalysisOptions options) {
2670 String path = folder.path; 2807 String path = folder.path;
2671 expect(currentContextPaths, isNot(contains(path))); 2808 expect(currentContextRoots, isNot(contains(path)));
2672 currentContextTimestamps[path] = now; 2809 currentContextTimestamps[path] = now;
2673 2810
2674 ContextBuilder builder = 2811 ContextBuilder builder =
2675 createContextBuilder(folder, options, useSummaries: true); 2812 createContextBuilder(folder, options, useSummaries: true);
2676 AnalysisContext context = builder.buildContext(folder.path); 2813 AnalysisContext context = builder.buildContext(folder.path);
2677 SourceFactory sourceFactory = context.sourceFactory; 2814 SourceFactory sourceFactory = context.sourceFactory;
2678 AnalysisOptions analysisOptions = context.analysisOptions; 2815 AnalysisOptions analysisOptions = context.analysisOptions;
2679 context.dispose(); 2816 context.dispose();
2680 2817
2681 currentDriver = new AnalysisDriver( 2818 currentDriver = new AnalysisDriver(
2682 scheduler, 2819 scheduler,
2683 logger, 2820 logger,
2684 resourceProvider, 2821 resourceProvider,
2685 new MemoryByteStore(), 2822 new MemoryByteStore(),
2686 new FileContentOverlay(), 2823 new FileContentOverlay(),
2687 sourceFactory, 2824 sourceFactory,
2688 analysisOptions); 2825 analysisOptions);
2689 currentDriver.name = folder.shortName; 2826 currentDriver.name = path;
2827 driverMap[path] = currentDriver;
2690 currentDriver.exceptions.listen((ExceptionResult result) { 2828 currentDriver.exceptions.listen((ExceptionResult result) {
2691 AnalysisEngine.instance.logger 2829 AnalysisEngine.instance.logger
2692 .logError('Analysis failed: ${result.path}', result.exception); 2830 .logError('Analysis failed: ${result.path}', result.exception);
2693 }); 2831 });
2694 return currentDriver; 2832 return currentDriver;
2695 } 2833 }
2696 2834
2697 @override 2835 @override
2698 AnalysisContext addContext(Folder folder, AnalysisOptions options) { 2836 AnalysisContext addContext(Folder folder, AnalysisOptions options) {
2699 String path = folder.path; 2837 String path = folder.path;
2700 expect(currentContextPaths, isNot(contains(path))); 2838 expect(currentContextRoots, isNot(contains(path)));
2701 currentContextTimestamps[path] = now; 2839 currentContextTimestamps[path] = now;
2702 currentContextFilePaths[path] = <String, int>{}; 2840 currentContextFilePaths[path] = <String, int>{};
2703 currentContextSources[path] = new HashSet<Source>(); 2841 currentContextSources[path] = new HashSet<Source>();
2704 2842
2705 ContextBuilder builder = createContextBuilder(folder, options); 2843 ContextBuilder builder = createContextBuilder(folder, options);
2706 currentContext = builder.buildContext(folder.path); 2844 currentContext = builder.buildContext(path);
2845 currentContext.name = path;
2707 return currentContext; 2846 return currentContext;
2708 } 2847 }
2709 2848
2710 @override 2849 @override
2711 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet) { 2850 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet) {
2712 if (currentDriver != null) { 2851 AnalysisDriver driver = driverMap[contextFolder.path];
2852 if (driver != null) {
2713 changeSet.addedSources.forEach((source) { 2853 changeSet.addedSources.forEach((source) {
2714 currentDriver.addFile(source.fullName); 2854 driver.addFile(source.fullName);
2715 }); 2855 });
2716 changeSet.changedSources.forEach((source) { 2856 changeSet.changedSources.forEach((source) {
2717 currentDriver.changeFile(source.fullName); 2857 driver.changeFile(source.fullName);
2718 }); 2858 });
2719 changeSet.removedSources.forEach((source) { 2859 changeSet.removedSources.forEach((source) {
2720 currentDriver.removeFile(source.fullName); 2860 driver.removeFile(source.fullName);
2721 }); 2861 });
2722 } else { 2862 } else {
2723 Map<String, int> filePaths = currentContextFilePaths[contextFolder.path]; 2863 Map<String, int> filePaths = currentContextFilePaths[contextFolder.path];
2724 Set<Source> sources = currentContextSources[contextFolder.path]; 2864 Set<Source> sources = currentContextSources[contextFolder.path];
2725 2865
2726 for (Source source in changeSet.addedSources) { 2866 for (Source source in changeSet.addedSources) {
2727 expect(filePaths, isNot(contains(source.fullName))); 2867 expect(filePaths, isNot(contains(source.fullName)));
2728 filePaths[source.fullName] = now; 2868 filePaths[source.fullName] = now;
2729 sources.add(source); 2869 sources.add(source);
2730 } 2870 }
(...skipping 10 matching lines...) Expand all
2741 currentContext.applyChanges(changeSet); 2881 currentContext.applyChanges(changeSet);
2742 } 2882 }
2743 } 2883 }
2744 2884
2745 @override 2885 @override
2746 void applyFileRemoved(AnalysisDriver driver, String file) { 2886 void applyFileRemoved(AnalysisDriver driver, String file) {
2747 driver.removeFile(file); 2887 driver.removeFile(file);
2748 } 2888 }
2749 2889
2750 void assertContextFiles(String contextPath, List<String> expectedFiles) { 2890 void assertContextFiles(String contextPath, List<String> expectedFiles) {
2751 var actualFiles = currentContextFilePaths[contextPath].keys; 2891 expect(getCurrentFilePaths(contextPath), unorderedEquals(expectedFiles));
2752 expect(actualFiles, unorderedEquals(expectedFiles));
2753 } 2892 }
2754 2893
2755 void assertContextPaths(List<String> expected) { 2894 void assertContextPaths(List<String> expected) {
2756 expect(currentContextPaths, unorderedEquals(expected)); 2895 expect(currentContextRoots, unorderedEquals(expected));
2757 } 2896 }
2758 2897
2759 @override 2898 @override
2760 void computingPackageMap(bool computing) { 2899 void computingPackageMap(bool computing) {
2761 // Do nothing. 2900 // Do nothing.
2762 } 2901 }
2763 2902
2764 @override 2903 @override
2765 ContextBuilder createContextBuilder(Folder folder, AnalysisOptions options, 2904 ContextBuilder createContextBuilder(Folder folder, AnalysisOptions options,
2766 {bool useSummaries = false}) { 2905 {bool useSummaries = false}) {
2767 ContextBuilderOptions builderOptions = new ContextBuilderOptions(); 2906 ContextBuilderOptions builderOptions = new ContextBuilderOptions();
2768 builderOptions.defaultOptions = options; 2907 builderOptions.defaultOptions = options;
2769 ContextBuilder builder = new ContextBuilder( 2908 ContextBuilder builder = new ContextBuilder(
2770 resourceProvider, sdkManager, new ContentCache(), 2909 resourceProvider, sdkManager, new ContentCache(),
2771 options: builderOptions); 2910 options: builderOptions);
2772 return builder; 2911 return builder;
2773 } 2912 }
2774 2913
2914 /**
2915 * Return the paths to the files being analyzed in the current context root.
2916 */
2917 Iterable<Source> currentFileSources(String contextPath) {
2918 if (currentDriver == null) {
2919 if (currentContext == null) {
2920 return <Source>[];
2921 }
2922 Set<Source> sources = currentContextSources[contextPath];
2923 return sources ?? <Source>[];
2924 }
2925 AnalysisDriver driver = driverMap[contextPath];
2926 SourceFactory sourceFactory = driver.sourceFactory;
2927 return driver.addedFiles.map((String path) {
2928 File file = resourceProvider.getFile(path);
2929 Source source = file.createSource();
2930 Uri uri = sourceFactory.restoreUri(source);
2931 return file.createSource(uri);
2932 });
2933 }
2934
2935 /**
2936 * Return the paths to the files being analyzed in the current context root.
2937 */
2938 Iterable<String> getCurrentFilePaths(String contextPath) {
2939 if (currentDriver == null) {
2940 if (currentContext == null) {
2941 return <String>[];
2942 }
2943 Map<String, int> fileMap = currentContextFilePaths[contextPath];
2944 if (fileMap == null) {
2945 return <String>[];
2946 }
2947 return fileMap.keys;
2948 }
2949 return driverMap[contextPath].addedFiles;
2950 }
2951
2775 @override 2952 @override
2776 void moveContext(Folder from, Folder to) { 2953 void moveContext(Folder from, Folder to) {
2777 String path = from.path; 2954 String path = from.path;
2778 String path2 = to.path; 2955 String path2 = to.path;
2779 expect(currentContextFilePaths, contains(path)); 2956 expect(currentContextFilePaths, contains(path));
2780 expect(currentContextTimestamps, contains(path)); 2957 expect(currentContextTimestamps, contains(path));
2781 expect(currentContextSources, contains(path)); 2958 expect(currentContextSources, contains(path));
2782 expect(currentContextFilePaths, isNot(contains(path2))); 2959 expect(currentContextFilePaths, isNot(contains(path2)));
2783 expect(currentContextTimestamps, isNot(contains(path2))); 2960 expect(currentContextTimestamps, isNot(contains(path2)));
2784 expect(currentContextSources, isNot(contains(path2))); 2961 expect(currentContextSources, isNot(contains(path2)));
2785 currentContextFilePaths[path2] = currentContextFilePaths.remove(path); 2962 currentContextFilePaths[path2] = currentContextFilePaths.remove(path);
2786 currentContextTimestamps[path2] = currentContextTimestamps.remove(path); 2963 currentContextTimestamps[path2] = currentContextTimestamps.remove(path);
2787 currentContextSources[path2] = currentContextSources.remove(path); 2964 currentContextSources[path2] = currentContextSources.remove(path);
2788 } 2965 }
2789 2966
2790 @override 2967 @override
2791 void removeContext(Folder folder, List<String> flushedFiles) { 2968 void removeContext(Folder folder, List<String> flushedFiles) {
2792 String path = folder.path; 2969 String path = folder.path;
2793 expect(currentContextPaths, contains(path)); 2970 expect(currentContextRoots, contains(path));
2794 currentContextTimestamps.remove(path); 2971 currentContextTimestamps.remove(path);
2795 currentContextFilePaths.remove(path); 2972 currentContextFilePaths.remove(path);
2796 currentContextSources.remove(path); 2973 currentContextSources.remove(path);
2797 lastFlushedFiles = flushedFiles; 2974 lastFlushedFiles = flushedFiles;
2798 } 2975 }
2799 2976
2800 @override 2977 @override
2801 void updateContextPackageUriResolver(AnalysisContext context) { 2978 void updateContextPackageUriResolver(AnalysisContext context) {
2802 // Nothing to do. 2979 // Nothing to do.
2803 } 2980 }
(...skipping 12 matching lines...) Expand all
2816 class TestUriResolver extends UriResolver { 2993 class TestUriResolver extends UriResolver {
2817 Map<Uri, Source> uriMap; 2994 Map<Uri, Source> uriMap;
2818 2995
2819 TestUriResolver(this.uriMap); 2996 TestUriResolver(this.uriMap);
2820 2997
2821 @override 2998 @override
2822 Source resolveAbsolute(Uri uri, [Uri actualUri]) { 2999 Source resolveAbsolute(Uri uri, [Uri actualUri]) {
2823 return uriMap[uri]; 3000 return uriMap[uri];
2824 } 3001 }
2825 } 3002 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698