OLD | NEW |
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:analyzer/error/error.dart'; | 10 import 'package:analyzer/error/error.dart'; |
11 import 'package:analyzer/file_system/file_system.dart'; | 11 import 'package:analyzer/file_system/file_system.dart'; |
12 import 'package:analyzer/file_system/memory_file_system.dart'; | 12 import 'package:analyzer/file_system/memory_file_system.dart'; |
13 import 'package:analyzer/instrumentation/instrumentation.dart'; | 13 import 'package:analyzer/instrumentation/instrumentation.dart'; |
14 import 'package:analyzer/source/analysis_options_provider.dart'; | |
15 import 'package:analyzer/source/error_processor.dart'; | 14 import 'package:analyzer/source/error_processor.dart'; |
16 import 'package:analyzer/src/context/builder.dart'; | 15 import 'package:analyzer/src/context/builder.dart'; |
17 import 'package:analyzer/src/dart/analysis/driver.dart'; | 16 import 'package:analyzer/src/dart/analysis/driver.dart'; |
18 import 'package:analyzer/src/error/codes.dart'; | 17 import 'package:analyzer/src/error/codes.dart'; |
19 import 'package:analyzer/src/generated/engine.dart'; | 18 import 'package:analyzer/src/generated/engine.dart'; |
20 import 'package:analyzer/src/generated/sdk.dart'; | 19 import 'package:analyzer/src/generated/sdk.dart'; |
21 import 'package:analyzer/src/generated/source.dart'; | 20 import 'package:analyzer/src/generated/source.dart'; |
22 import 'package:analyzer/src/generated/source_io.dart'; | 21 import 'package:analyzer/src/generated/source_io.dart'; |
23 import 'package:analyzer/src/services/lint.dart'; | 22 import 'package:analyzer/src/services/lint.dart'; |
24 import 'package:analyzer/src/task/options.dart' | 23 import 'package:analyzer/src/task/options.dart' |
25 show CONFIGURED_ERROR_PROCESSORS; | 24 show CONFIGURED_ERROR_PROCESSORS; |
26 import 'package:analyzer/src/util/glob.dart'; | 25 import 'package:analyzer/src/util/glob.dart'; |
27 import 'package:linter/src/plugin/linter_plugin.dart'; | 26 import 'package:linter/src/plugin/linter_plugin.dart'; |
28 import 'package:linter/src/rules/avoid_as.dart'; | 27 import 'package:linter/src/rules/avoid_as.dart'; |
29 import 'package:path/path.dart'; | 28 import 'package:path/path.dart' as path; |
30 import 'package:plugin/manager.dart'; | 29 import 'package:plugin/manager.dart'; |
31 import 'package:plugin/plugin.dart'; | 30 import 'package:plugin/plugin.dart'; |
32 import 'package:test/test.dart'; | 31 import 'package:test/test.dart'; |
33 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 32 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
34 | 33 |
35 import 'mock_sdk.dart'; | 34 import 'mock_sdk.dart'; |
36 import 'mocks.dart'; | 35 import 'mocks.dart'; |
37 | 36 |
38 main() { | 37 main() { |
39 defineReflectiveSuite(() { | 38 defineReflectiveSuite(() { |
40 defineReflectiveTests(AbstractContextManagerTest); | 39 defineReflectiveTests(AbstractContextManagerTest); |
41 defineReflectiveTests(ContextManagerWithNewOptionsTest); | 40 defineReflectiveTests(ContextManagerWithNewOptionsTest); |
42 defineReflectiveTests(ContextManagerWithOldOptionsTest); | 41 defineReflectiveTests(ContextManagerWithOldOptionsTest); |
43 }); | 42 }); |
44 } | 43 } |
45 | 44 |
46 @reflectiveTest | 45 @reflectiveTest |
47 class AbstractContextManagerTest extends ContextManagerTest { | 46 class AbstractContextManagerTest extends ContextManagerTest { |
48 void test_contextsInAnalysisRoot_nestedContext() { | 47 void test_contextsInAnalysisRoot_nestedContext() { |
49 String subProjPath = posix.join(projPath, 'subproj'); | 48 String subProjPath = path.posix.join(projPath, 'subproj'); |
50 Folder subProjFolder = resourceProvider.newFolder(subProjPath); | 49 Folder subProjFolder = resourceProvider.newFolder(subProjPath); |
51 resourceProvider.newFile( | 50 resourceProvider.newFile( |
52 posix.join(subProjPath, 'pubspec.yaml'), 'contents'); | 51 path.posix.join(subProjPath, 'pubspec.yaml'), 'contents'); |
53 String subProjFilePath = posix.join(subProjPath, 'file.dart'); | 52 String subProjFilePath = path.posix.join(subProjPath, 'file.dart'); |
54 resourceProvider.newFile(subProjFilePath, 'contents'); | 53 resourceProvider.newFile(subProjFilePath, 'contents'); |
55 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 54 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
56 // Make sure that there really are contexts for both the main project and | 55 // Make sure that there really are contexts for both the main project and |
57 // the subproject. | 56 // the subproject. |
58 Folder projFolder = resourceProvider.getFolder(projPath); | 57 Folder projFolder = resourceProvider.getFolder(projPath); |
59 ContextInfo projContextInfo = manager.getContextInfoFor(projFolder); | 58 ContextInfo projContextInfo = manager.getContextInfoFor(projFolder); |
60 expect(projContextInfo, isNotNull); | 59 expect(projContextInfo, isNotNull); |
61 expect(projContextInfo.folder, projFolder); | 60 expect(projContextInfo.folder, projFolder); |
62 ContextInfo subProjContextInfo = manager.getContextInfoFor(subProjFolder); | 61 ContextInfo subProjContextInfo = manager.getContextInfoFor(subProjFolder); |
63 expect(subProjContextInfo, isNotNull); | 62 expect(subProjContextInfo, isNotNull); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 // We can't find dart:core because we didn't list it in our | 160 // We can't find dart:core because we didn't list it in our |
162 // embedded_libs map. | 161 // embedded_libs map. |
163 expect(context.sourceFactory.forUri('dart:core'), isNull); | 162 expect(context.sourceFactory.forUri('dart:core'), isNull); |
164 // We can find dart:typed_data because we listed it in our | 163 // We can find dart:typed_data because we listed it in our |
165 // embedded_libs map. | 164 // embedded_libs map. |
166 expect(context.sourceFactory.forUri('dart:typed_data'), isNotNull); | 165 expect(context.sourceFactory.forUri('dart:typed_data'), isNotNull); |
167 } | 166 } |
168 | 167 |
169 test_ignoreFilesInPackagesFolder() { | 168 test_ignoreFilesInPackagesFolder() { |
170 // create a context with a pubspec.yaml file | 169 // create a context with a pubspec.yaml file |
171 String pubspecPath = posix.join(projPath, 'pubspec.yaml'); | 170 String pubspecPath = path.posix.join(projPath, 'pubspec.yaml'); |
172 resourceProvider.newFile(pubspecPath, 'pubspec'); | 171 resourceProvider.newFile(pubspecPath, 'pubspec'); |
173 // create a file in the "packages" folder | 172 // create a file in the "packages" folder |
174 String filePath1 = posix.join(projPath, 'packages', 'file1.dart'); | 173 String filePath1 = path.posix.join(projPath, 'packages', 'file1.dart'); |
175 resourceProvider.newFile(filePath1, 'contents'); | 174 resourceProvider.newFile(filePath1, 'contents'); |
176 // "packages" files are ignored initially | 175 // "packages" files are ignored initially |
177 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 176 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
178 expect(callbacks.currentContextFilePaths[projPath], isEmpty); | 177 expect(callbacks.currentContextFilePaths[projPath], isEmpty); |
179 // "packages" files are ignored during watch | 178 // "packages" files are ignored during watch |
180 String filePath2 = posix.join(projPath, 'packages', 'file2.dart'); | 179 String filePath2 = path.posix.join(projPath, 'packages', 'file2.dart'); |
181 resourceProvider.newFile(filePath2, 'contents'); | 180 resourceProvider.newFile(filePath2, 'contents'); |
182 return pumpEventQueue().then((_) { | 181 return pumpEventQueue().then((_) { |
183 expect(callbacks.currentContextFilePaths[projPath], isEmpty); | 182 expect(callbacks.currentContextFilePaths[projPath], isEmpty); |
184 }); | 183 }); |
185 } | 184 } |
186 | 185 |
187 void test_isInAnalysisRoot_excluded() { | 186 void test_isInAnalysisRoot_excluded() { |
188 // prepare paths | 187 // prepare paths |
189 String project = '/project'; | 188 String project = '/project'; |
190 String excludedFolder = '$project/excluded'; | 189 String excludedFolder = '$project/excluded'; |
191 // set roots | 190 // set roots |
192 resourceProvider.newFolder(project); | 191 resourceProvider.newFolder(project); |
193 resourceProvider.newFolder(excludedFolder); | 192 resourceProvider.newFolder(excludedFolder); |
194 manager.setRoots( | 193 manager.setRoots( |
195 <String>[project], <String>[excludedFolder], <String, String>{}); | 194 <String>[project], <String>[excludedFolder], <String, String>{}); |
196 // verify | 195 // verify |
197 expect(manager.isInAnalysisRoot('$excludedFolder/test.dart'), isFalse); | 196 expect(manager.isInAnalysisRoot('$excludedFolder/test.dart'), isFalse); |
198 } | 197 } |
199 | 198 |
200 void test_isInAnalysisRoot_inNestedContext() { | 199 void test_isInAnalysisRoot_inNestedContext() { |
201 String subProjPath = posix.join(projPath, 'subproj'); | 200 String subProjPath = path.posix.join(projPath, 'subproj'); |
202 Folder subProjFolder = resourceProvider.newFolder(subProjPath); | 201 Folder subProjFolder = resourceProvider.newFolder(subProjPath); |
203 resourceProvider.newFile( | 202 resourceProvider.newFile( |
204 posix.join(subProjPath, 'pubspec.yaml'), 'contents'); | 203 path.posix.join(subProjPath, 'pubspec.yaml'), 'contents'); |
205 String subProjFilePath = posix.join(subProjPath, 'file.dart'); | 204 String subProjFilePath = path.posix.join(subProjPath, 'file.dart'); |
206 resourceProvider.newFile(subProjFilePath, 'contents'); | 205 resourceProvider.newFile(subProjFilePath, 'contents'); |
207 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 206 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
208 // Make sure that there really is a context for the subproject. | 207 // Make sure that there really is a context for the subproject. |
209 ContextInfo subProjContextInfo = manager.getContextInfoFor(subProjFolder); | 208 ContextInfo subProjContextInfo = manager.getContextInfoFor(subProjFolder); |
210 expect(subProjContextInfo, isNotNull); | 209 expect(subProjContextInfo, isNotNull); |
211 expect(subProjContextInfo.folder, subProjFolder); | 210 expect(subProjContextInfo.folder, subProjFolder); |
212 // Check that isInAnalysisRoot() works. | 211 // Check that isInAnalysisRoot() works. |
213 expect(manager.isInAnalysisRoot(subProjFilePath), isTrue); | 212 expect(manager.isInAnalysisRoot(subProjFilePath), isTrue); |
214 } | 213 } |
215 | 214 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 Map<String, int> fileTimestamps = | 246 Map<String, int> fileTimestamps = |
248 callbacks.currentContextFilePaths[projPath]; | 247 callbacks.currentContextFilePaths[projPath]; |
249 expect(fileTimestamps, isNotEmpty); | 248 expect(fileTimestamps, isNotEmpty); |
250 List<String> files = fileTimestamps.keys.toList(); | 249 List<String> files = fileTimestamps.keys.toList(); |
251 expect(files.length, equals(1)); | 250 expect(files.length, equals(1)); |
252 expect(files[0], equals('/my/proj/lib/main.dart')); | 251 expect(files[0], equals('/my/proj/lib/main.dart')); |
253 } | 252 } |
254 | 253 |
255 test_refresh_folder_with_packagespec() { | 254 test_refresh_folder_with_packagespec() { |
256 // create a context with a .packages file | 255 // create a context with a .packages file |
257 String packagespecFile = posix.join(projPath, '.packages'); | 256 String packagespecFile = path.posix.join(projPath, '.packages'); |
258 resourceProvider.newFile(packagespecFile, ''); | 257 resourceProvider.newFile(packagespecFile, ''); |
259 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 258 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
260 return pumpEventQueue().then((_) { | 259 return pumpEventQueue().then((_) { |
261 expect(callbacks.currentContextPaths.toList(), [projPath]); | 260 expect(callbacks.currentContextPaths.toList(), [projPath]); |
262 callbacks.now++; | 261 callbacks.now++; |
263 manager.refresh(null); | 262 manager.refresh(null); |
264 return pumpEventQueue().then((_) { | 263 return pumpEventQueue().then((_) { |
265 expect(callbacks.currentContextPaths.toList(), [projPath]); | 264 expect(callbacks.currentContextPaths.toList(), [projPath]); |
266 expect(callbacks.currentContextTimestamps[projPath], callbacks.now); | 265 expect(callbacks.currentContextTimestamps[projPath], callbacks.now); |
267 }); | 266 }); |
268 }); | 267 }); |
269 } | 268 } |
270 | 269 |
271 // TODO(paulberry): This test only tests PackagesFileDisposition. | 270 // TODO(paulberry): This test only tests PackagesFileDisposition. |
272 // Once http://dartbug.com/23909 is fixed, add a test for sdk extensions | 271 // Once http://dartbug.com/23909 is fixed, add a test for sdk extensions |
273 // and PackageMapDisposition. | 272 // and PackageMapDisposition. |
274 test_refresh_folder_with_packagespec_subfolders() { | 273 test_refresh_folder_with_packagespec_subfolders() { |
275 // Create a folder with no .packages file, containing two subfolders with | 274 // Create a folder with no .packages file, containing two subfolders with |
276 // .packages files. | 275 // .packages files. |
277 String subdir1Path = posix.join(projPath, 'subdir1'); | 276 String subdir1Path = path.posix.join(projPath, 'subdir1'); |
278 String subdir2Path = posix.join(projPath, 'subdir2'); | 277 String subdir2Path = path.posix.join(projPath, 'subdir2'); |
279 String packagespec1Path = posix.join(subdir1Path, '.packages'); | 278 String packagespec1Path = path.posix.join(subdir1Path, '.packages'); |
280 String packagespec2Path = posix.join(subdir2Path, '.packages'); | 279 String packagespec2Path = path.posix.join(subdir2Path, '.packages'); |
281 resourceProvider.newFile(packagespec1Path, ''); | 280 resourceProvider.newFile(packagespec1Path, ''); |
282 resourceProvider.newFile(packagespec2Path, ''); | 281 resourceProvider.newFile(packagespec2Path, ''); |
283 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 282 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
284 return pumpEventQueue().then((_) { | 283 return pumpEventQueue().then((_) { |
285 expect(callbacks.currentContextPaths.toSet(), | 284 expect(callbacks.currentContextPaths.toSet(), |
286 [subdir1Path, subdir2Path, projPath].toSet()); | 285 [subdir1Path, subdir2Path, projPath].toSet()); |
287 callbacks.now++; | 286 callbacks.now++; |
288 manager.refresh(null); | 287 manager.refresh(null); |
289 return pumpEventQueue().then((_) { | 288 return pumpEventQueue().then((_) { |
290 expect(callbacks.currentContextPaths.toSet(), | 289 expect(callbacks.currentContextPaths.toSet(), |
291 [subdir1Path, subdir2Path, projPath].toSet()); | 290 [subdir1Path, subdir2Path, projPath].toSet()); |
292 expect(callbacks.currentContextTimestamps[projPath], callbacks.now); | 291 expect(callbacks.currentContextTimestamps[projPath], callbacks.now); |
293 expect(callbacks.currentContextTimestamps[subdir1Path], callbacks.now); | 292 expect(callbacks.currentContextTimestamps[subdir1Path], callbacks.now); |
294 expect(callbacks.currentContextTimestamps[subdir2Path], callbacks.now); | 293 expect(callbacks.currentContextTimestamps[subdir2Path], callbacks.now); |
295 }); | 294 }); |
296 }); | 295 }); |
297 } | 296 } |
298 | 297 |
299 test_refresh_folder_with_pubspec() { | 298 test_refresh_folder_with_pubspec() { |
300 // create a context with a pubspec.yaml file | 299 // create a context with a pubspec.yaml file |
301 String pubspecPath = posix.join(projPath, 'pubspec.yaml'); | 300 String pubspecPath = path.posix.join(projPath, 'pubspec.yaml'); |
302 resourceProvider.newFile(pubspecPath, 'pubspec'); | 301 resourceProvider.newFile(pubspecPath, 'pubspec'); |
303 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 302 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
304 return pumpEventQueue().then((_) { | 303 return pumpEventQueue().then((_) { |
305 expect(callbacks.currentContextPaths.toList(), [projPath]); | 304 expect(callbacks.currentContextPaths.toList(), [projPath]); |
306 callbacks.now++; | 305 callbacks.now++; |
307 manager.refresh(null); | 306 manager.refresh(null); |
308 return pumpEventQueue().then((_) { | 307 return pumpEventQueue().then((_) { |
309 expect(callbacks.currentContextPaths.toList(), [projPath]); | 308 expect(callbacks.currentContextPaths.toList(), [projPath]); |
310 expect(callbacks.currentContextTimestamps[projPath], callbacks.now); | 309 expect(callbacks.currentContextTimestamps[projPath], callbacks.now); |
311 }); | 310 }); |
312 }); | 311 }); |
313 } | 312 } |
314 | 313 |
315 test_refresh_folder_with_pubspec_subfolders() { | 314 test_refresh_folder_with_pubspec_subfolders() { |
316 // Create a folder with no pubspec.yaml, containing two subfolders with | 315 // Create a folder with no pubspec.yaml, containing two subfolders with |
317 // pubspec.yaml files. | 316 // pubspec.yaml files. |
318 String subdir1Path = posix.join(projPath, 'subdir1'); | 317 String subdir1Path = path.posix.join(projPath, 'subdir1'); |
319 String subdir2Path = posix.join(projPath, 'subdir2'); | 318 String subdir2Path = path.posix.join(projPath, 'subdir2'); |
320 String pubspec1Path = posix.join(subdir1Path, 'pubspec.yaml'); | 319 String pubspec1Path = path.posix.join(subdir1Path, 'pubspec.yaml'); |
321 String pubspec2Path = posix.join(subdir2Path, 'pubspec.yaml'); | 320 String pubspec2Path = path.posix.join(subdir2Path, 'pubspec.yaml'); |
322 resourceProvider.newFile(pubspec1Path, 'pubspec'); | 321 resourceProvider.newFile(pubspec1Path, 'pubspec'); |
323 resourceProvider.newFile(pubspec2Path, 'pubspec'); | 322 resourceProvider.newFile(pubspec2Path, 'pubspec'); |
324 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 323 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
325 return pumpEventQueue().then((_) { | 324 return pumpEventQueue().then((_) { |
326 expect(callbacks.currentContextPaths.toSet(), | 325 expect(callbacks.currentContextPaths.toSet(), |
327 [subdir1Path, subdir2Path, projPath].toSet()); | 326 [subdir1Path, subdir2Path, projPath].toSet()); |
328 callbacks.now++; | 327 callbacks.now++; |
329 manager.refresh(null); | 328 manager.refresh(null); |
330 return pumpEventQueue().then((_) { | 329 return pumpEventQueue().then((_) { |
331 expect(callbacks.currentContextPaths.toSet(), | 330 expect(callbacks.currentContextPaths.toSet(), |
332 [subdir1Path, subdir2Path, projPath].toSet()); | 331 [subdir1Path, subdir2Path, projPath].toSet()); |
333 expect(callbacks.currentContextTimestamps[projPath], callbacks.now); | 332 expect(callbacks.currentContextTimestamps[projPath], callbacks.now); |
334 expect(callbacks.currentContextTimestamps[subdir1Path], callbacks.now); | 333 expect(callbacks.currentContextTimestamps[subdir1Path], callbacks.now); |
335 expect(callbacks.currentContextTimestamps[subdir2Path], callbacks.now); | 334 expect(callbacks.currentContextTimestamps[subdir2Path], callbacks.now); |
336 }); | 335 }); |
337 }); | 336 }); |
338 } | 337 } |
339 | 338 |
340 test_refresh_oneContext() { | 339 test_refresh_oneContext() { |
341 // create two contexts with pubspec.yaml files | 340 // create two contexts with pubspec.yaml files |
342 String pubspecPath = posix.join(projPath, 'pubspec.yaml'); | 341 String pubspecPath = path.posix.join(projPath, 'pubspec.yaml'); |
343 resourceProvider.newFile(pubspecPath, 'pubspec1'); | 342 resourceProvider.newFile(pubspecPath, 'pubspec1'); |
344 | 343 |
345 String proj2Path = '/my/proj2'; | 344 String proj2Path = '/my/proj2'; |
346 resourceProvider.newFolder(proj2Path); | 345 resourceProvider.newFolder(proj2Path); |
347 String pubspec2Path = posix.join(proj2Path, 'pubspec.yaml'); | 346 String pubspec2Path = path.posix.join(proj2Path, 'pubspec.yaml'); |
348 resourceProvider.newFile(pubspec2Path, 'pubspec2'); | 347 resourceProvider.newFile(pubspec2Path, 'pubspec2'); |
349 | 348 |
350 List<String> roots = <String>[projPath, proj2Path]; | 349 List<String> roots = <String>[projPath, proj2Path]; |
351 manager.setRoots(roots, <String>[], <String, String>{}); | 350 manager.setRoots(roots, <String>[], <String, String>{}); |
352 return pumpEventQueue().then((_) { | 351 return pumpEventQueue().then((_) { |
353 expect(callbacks.currentContextPaths.toList(), unorderedEquals(roots)); | 352 expect(callbacks.currentContextPaths.toList(), unorderedEquals(roots)); |
354 int then = callbacks.now; | 353 int then = callbacks.now; |
355 callbacks.now++; | 354 callbacks.now++; |
356 manager.refresh([resourceProvider.getResource(proj2Path)]); | 355 manager.refresh([resourceProvider.getResource(proj2Path)]); |
357 return pumpEventQueue().then((_) { | 356 return pumpEventQueue().then((_) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 var contexts = | 389 var contexts = |
391 manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath)); | 390 manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath)); |
392 expect(contexts, isNotNull); | 391 expect(contexts, isNotNull); |
393 expect(contexts.length, equals(1)); | 392 expect(contexts.length, equals(1)); |
394 var context = contexts[0]; | 393 var context = contexts[0]; |
395 var source = context.sourceFactory.forUri('dart:foobar'); | 394 var source = context.sourceFactory.forUri('dart:foobar'); |
396 expect(source.fullName, equals('/my/proj/sdk_ext/entry.dart')); | 395 expect(source.fullName, equals('/my/proj/sdk_ext/entry.dart')); |
397 } | 396 } |
398 | 397 |
399 void test_setRoots_addFolderWithDartFile() { | 398 void test_setRoots_addFolderWithDartFile() { |
400 String filePath = posix.join(projPath, 'foo.dart'); | 399 String filePath = path.posix.join(projPath, 'foo.dart'); |
401 resourceProvider.newFile(filePath, 'contents'); | 400 resourceProvider.newFile(filePath, 'contents'); |
402 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 401 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
403 // verify | 402 // verify |
404 var filePaths = callbacks.currentContextFilePaths[projPath]; | 403 var filePaths = callbacks.currentContextFilePaths[projPath]; |
405 expect(filePaths, hasLength(1)); | 404 expect(filePaths, hasLength(1)); |
406 expect(filePaths, contains(filePath)); | 405 expect(filePaths, contains(filePath)); |
407 List<AnalysisContext> contextsInAnalysisRoot = | 406 List<AnalysisContext> contextsInAnalysisRoot = |
408 manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath)); | 407 manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath)); |
409 expect(contextsInAnalysisRoot, hasLength(1)); | 408 expect(contextsInAnalysisRoot, hasLength(1)); |
410 AnalysisContext context = contextsInAnalysisRoot[0]; | 409 AnalysisContext context = contextsInAnalysisRoot[0]; |
411 expect(context, isNotNull); | 410 expect(context, isNotNull); |
412 Source result = context.sourceFactory.forUri('package:foo/foo.dart'); | 411 Source result = context.sourceFactory.forUri('package:foo/foo.dart'); |
413 expect(result, isNotNull); | 412 expect(result, isNotNull); |
414 expect(result.exists(), isFalse); | 413 expect(result.exists(), isFalse); |
415 } | 414 } |
416 | 415 |
417 void test_setRoots_addFolderWithDartFileInSubfolder() { | 416 void test_setRoots_addFolderWithDartFileInSubfolder() { |
418 String filePath = posix.join(projPath, 'foo', 'bar.dart'); | 417 String filePath = path.posix.join(projPath, 'foo', 'bar.dart'); |
419 resourceProvider.newFile(filePath, 'contents'); | 418 resourceProvider.newFile(filePath, 'contents'); |
420 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 419 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
421 // verify | 420 // verify |
422 var filePaths = callbacks.currentContextFilePaths[projPath]; | 421 var filePaths = callbacks.currentContextFilePaths[projPath]; |
423 expect(filePaths, hasLength(1)); | 422 expect(filePaths, hasLength(1)); |
424 expect(filePaths, contains(filePath)); | 423 expect(filePaths, contains(filePath)); |
425 } | 424 } |
426 | 425 |
427 void test_setRoots_addFolderWithDummyLink() { | 426 void test_setRoots_addFolderWithDummyLink() { |
428 String filePath = posix.join(projPath, 'foo.dart'); | 427 String filePath = path.posix.join(projPath, 'foo.dart'); |
429 resourceProvider.newDummyLink(filePath); | 428 resourceProvider.newDummyLink(filePath); |
430 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 429 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
431 // verify | 430 // verify |
432 var filePaths = callbacks.currentContextFilePaths[projPath]; | 431 var filePaths = callbacks.currentContextFilePaths[projPath]; |
433 expect(filePaths, isEmpty); | 432 expect(filePaths, isEmpty); |
434 } | 433 } |
435 | 434 |
436 void test_setRoots_addFolderWithNestedPackageSpec() { | 435 void test_setRoots_addFolderWithNestedPackageSpec() { |
437 String examplePath = newFolder([projPath, ContextManagerTest.EXAMPLE_NAME]); | 436 String examplePath = newFolder([projPath, ContextManagerTest.EXAMPLE_NAME]); |
438 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]); | 437 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 void test_setRoots_addFolderWithoutPubspec() { | 490 void test_setRoots_addFolderWithoutPubspec() { |
492 packageMapProvider.packageMap = null; | 491 packageMapProvider.packageMap = null; |
493 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 492 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
494 // verify | 493 // verify |
495 expect(callbacks.currentContextPaths, hasLength(1)); | 494 expect(callbacks.currentContextPaths, hasLength(1)); |
496 expect(callbacks.currentContextPaths, contains(projPath)); | 495 expect(callbacks.currentContextPaths, contains(projPath)); |
497 expect(callbacks.currentContextFilePaths[projPath], hasLength(0)); | 496 expect(callbacks.currentContextFilePaths[projPath], hasLength(0)); |
498 } | 497 } |
499 | 498 |
500 void test_setRoots_addFolderWithPackagespec() { | 499 void test_setRoots_addFolderWithPackagespec() { |
501 String packagespecPath = posix.join(projPath, '.packages'); | 500 String packagespecPath = path.posix.join(projPath, '.packages'); |
502 resourceProvider.newFile(packagespecPath, | 501 resourceProvider.newFile(packagespecPath, |
503 'unittest:file:///home/somebody/.pub/cache/unittest-0.9.9/lib/'); | 502 'unittest:file:///home/somebody/.pub/cache/unittest-0.9.9/lib/'); |
504 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]); | 503 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]); |
505 File mainFile = | 504 File mainFile = |
506 resourceProvider.newFile(posix.join(libPath, 'main.dart'), ''); | 505 resourceProvider.newFile(path.posix.join(libPath, 'main.dart'), ''); |
507 Source source = mainFile.createSource(); | 506 Source source = mainFile.createSource(); |
508 | 507 |
509 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 508 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
510 | 509 |
511 // verify | 510 // verify |
512 expect(callbacks.currentContextPaths, hasLength(1)); | 511 expect(callbacks.currentContextPaths, hasLength(1)); |
513 expect(callbacks.currentContextPaths, contains(projPath)); | 512 expect(callbacks.currentContextPaths, contains(projPath)); |
514 expect(callbacks.currentContextFilePaths[projPath], hasLength(1)); | 513 expect(callbacks.currentContextFilePaths[projPath], hasLength(1)); |
515 | 514 |
516 // smoketest resolution | 515 // smoketest resolution |
517 SourceFactory sourceFactory = callbacks.currentContext.sourceFactory; | 516 SourceFactory sourceFactory = callbacks.currentContext.sourceFactory; |
518 Source resolvedSource = | 517 Source resolvedSource = |
519 sourceFactory.resolveUri(source, 'package:unittest/unittest.dart'); | 518 sourceFactory.resolveUri(source, 'package:unittest/unittest.dart'); |
520 expect(resolvedSource, isNotNull); | 519 expect(resolvedSource, isNotNull); |
521 expect(resolvedSource.fullName, | 520 expect(resolvedSource.fullName, |
522 equals('/home/somebody/.pub/cache/unittest-0.9.9/lib/unittest.dart')); | 521 equals('/home/somebody/.pub/cache/unittest-0.9.9/lib/unittest.dart')); |
523 } | 522 } |
524 | 523 |
525 void test_setRoots_addFolderWithPackagespecAndPackageRoot() { | 524 void test_setRoots_addFolderWithPackagespecAndPackageRoot() { |
526 // The package root should take priority. | 525 // The package root should take priority. |
527 String packagespecPath = posix.join(projPath, '.packages'); | 526 String packagespecPath = path.posix.join(projPath, '.packages'); |
528 resourceProvider.newFile(packagespecPath, | 527 resourceProvider.newFile(packagespecPath, |
529 'unittest:file:///home/somebody/.pub/cache/unittest-0.9.9/lib/'); | 528 'unittest:file:///home/somebody/.pub/cache/unittest-0.9.9/lib/'); |
530 String packageRootPath = '/package/root/'; | 529 String packageRootPath = '/package/root/'; |
531 manager.setRoots(<String>[projPath], <String>[], | 530 manager.setRoots(<String>[projPath], <String>[], |
532 <String, String>{projPath: packageRootPath}); | 531 <String, String>{projPath: packageRootPath}); |
533 expect(callbacks.currentContextPaths, hasLength(1)); | 532 expect(callbacks.currentContextPaths, hasLength(1)); |
534 expect(callbacks.currentContextPaths, contains(projPath)); | 533 expect(callbacks.currentContextPaths, contains(projPath)); |
535 _checkPackageRoot(projPath, packageRootPath); | 534 _checkPackageRoot(projPath, packageRootPath); |
536 } | 535 } |
537 | 536 |
538 void test_setRoots_addFolderWithPubspec() { | 537 void test_setRoots_addFolderWithPubspec() { |
539 String pubspecPath = posix.join(projPath, 'pubspec.yaml'); | 538 String pubspecPath = path.posix.join(projPath, 'pubspec.yaml'); |
540 resourceProvider.newFile(pubspecPath, 'pubspec'); | 539 resourceProvider.newFile(pubspecPath, 'pubspec'); |
541 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 540 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
542 // verify | 541 // verify |
543 expect(callbacks.currentContextPaths, hasLength(1)); | 542 expect(callbacks.currentContextPaths, hasLength(1)); |
544 expect(callbacks.currentContextPaths, contains(projPath)); | 543 expect(callbacks.currentContextPaths, contains(projPath)); |
545 expect(callbacks.currentContextFilePaths[projPath], hasLength(0)); | 544 expect(callbacks.currentContextFilePaths[projPath], hasLength(0)); |
546 } | 545 } |
547 | 546 |
548 void test_setRoots_addFolderWithPubspec_andPackagespec() { | 547 void test_setRoots_addFolderWithPubspec_andPackagespec() { |
549 String pubspecPath = posix.join(projPath, 'pubspec.yaml'); | 548 String pubspecPath = path.posix.join(projPath, 'pubspec.yaml'); |
550 String packagespecPath = posix.join(projPath, '.packages'); | 549 String packagespecPath = path.posix.join(projPath, '.packages'); |
551 resourceProvider.newFile(pubspecPath, 'pubspec'); | 550 resourceProvider.newFile(pubspecPath, 'pubspec'); |
552 resourceProvider.newFile(packagespecPath, ''); | 551 resourceProvider.newFile(packagespecPath, ''); |
553 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 552 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
554 // verify | 553 // verify |
555 callbacks.assertContextPaths([projPath]); | 554 callbacks.assertContextPaths([projPath]); |
556 } | 555 } |
557 | 556 |
558 void test_setRoots_addFolderWithPubspecAndLib() { | 557 void test_setRoots_addFolderWithPubspecAndLib() { |
559 String binPath = newFolder([projPath, ContextManagerTest.BIN_NAME]); | 558 String binPath = newFolder([projPath, ContextManagerTest.BIN_NAME]); |
560 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]); | 559 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]); |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
925 String excludedPubspec = '$excludedFolder/pubspec.yaml'; | 924 String excludedPubspec = '$excludedFolder/pubspec.yaml'; |
926 // create files | 925 // create files |
927 resourceProvider.newFile(excludedPubspec, 'name: ignore-me'); | 926 resourceProvider.newFile(excludedPubspec, 'name: ignore-me'); |
928 // set "/project", and exclude "/project/excluded" | 927 // set "/project", and exclude "/project/excluded" |
929 manager.setRoots( | 928 manager.setRoots( |
930 <String>[project], <String>[excludedFolder], <String, String>{}); | 929 <String>[project], <String>[excludedFolder], <String, String>{}); |
931 callbacks.assertContextPaths([project]); | 930 callbacks.assertContextPaths([project]); |
932 } | 931 } |
933 | 932 |
934 void test_setRoots_noContext_inDotFolder() { | 933 void test_setRoots_noContext_inDotFolder() { |
935 String pubspecPath = posix.join(projPath, '.pub', 'pubspec.yaml'); | 934 String pubspecPath = path.posix.join(projPath, '.pub', 'pubspec.yaml'); |
936 resourceProvider.newFile(pubspecPath, 'name: test'); | 935 resourceProvider.newFile(pubspecPath, 'name: test'); |
937 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 936 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
938 // verify | 937 // verify |
939 expect(callbacks.currentContextPaths, hasLength(1)); | 938 expect(callbacks.currentContextPaths, hasLength(1)); |
940 expect(callbacks.currentContextPaths, contains(projPath)); | 939 expect(callbacks.currentContextPaths, contains(projPath)); |
941 expect(callbacks.currentContextFilePaths[projPath], hasLength(0)); | 940 expect(callbacks.currentContextFilePaths[projPath], hasLength(0)); |
942 } | 941 } |
943 | 942 |
944 void test_setRoots_noContext_inPackagesFolder() { | 943 void test_setRoots_noContext_inPackagesFolder() { |
945 String pubspecPath = posix.join(projPath, 'packages', 'pubspec.yaml'); | 944 String pubspecPath = path.posix.join(projPath, 'packages', 'pubspec.yaml'); |
946 resourceProvider.newFile(pubspecPath, 'name: test'); | 945 resourceProvider.newFile(pubspecPath, 'name: test'); |
947 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 946 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
948 // verify | 947 // verify |
949 expect(callbacks.currentContextPaths, hasLength(1)); | 948 expect(callbacks.currentContextPaths, hasLength(1)); |
950 expect(callbacks.currentContextPaths, contains(projPath)); | 949 expect(callbacks.currentContextPaths, contains(projPath)); |
951 expect(callbacks.currentContextFilePaths[projPath], hasLength(0)); | 950 expect(callbacks.currentContextFilePaths[projPath], hasLength(0)); |
952 } | 951 } |
953 | 952 |
954 void test_setRoots_packageResolver() { | 953 void test_setRoots_packageResolver() { |
955 String filePath = posix.join(projPath, 'lib', 'foo.dart'); | 954 String filePath = path.posix.join(projPath, 'lib', 'foo.dart'); |
956 newFile([projPath, ContextManagerImpl.PACKAGE_SPEC_NAME], 'foo:lib/'); | 955 newFile([projPath, ContextManagerImpl.PACKAGE_SPEC_NAME], 'foo:lib/'); |
957 resourceProvider.newFile(filePath, 'contents'); | 956 resourceProvider.newFile(filePath, 'contents'); |
958 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 957 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
959 | 958 |
960 List<AnalysisContext> contextsInAnalysisRoot = | 959 List<AnalysisContext> contextsInAnalysisRoot = |
961 manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath)); | 960 manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath)); |
962 expect(contextsInAnalysisRoot, hasLength(1)); | 961 expect(contextsInAnalysisRoot, hasLength(1)); |
963 AnalysisContext context = contextsInAnalysisRoot[0]; | 962 AnalysisContext context = contextsInAnalysisRoot[0]; |
964 expect(context, isNotNull); | 963 expect(context, isNotNull); |
965 Source result = context.sourceFactory.forUri('package:foo/foo.dart'); | 964 Source result = context.sourceFactory.forUri('package:foo/foo.dart'); |
(...skipping 19 matching lines...) Expand all Loading... |
985 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 984 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
986 expect(callbacks.currentContextPaths, hasLength(1)); | 985 expect(callbacks.currentContextPaths, hasLength(1)); |
987 // set empty roots - no contexts | 986 // set empty roots - no contexts |
988 manager.setRoots(<String>[], <String>[], <String, String>{}); | 987 manager.setRoots(<String>[], <String>[], <String, String>{}); |
989 expect(callbacks.currentContextPaths, hasLength(0)); | 988 expect(callbacks.currentContextPaths, hasLength(0)); |
990 expect(callbacks.currentContextFilePaths, hasLength(0)); | 989 expect(callbacks.currentContextFilePaths, hasLength(0)); |
991 } | 990 } |
992 | 991 |
993 void test_setRoots_removeFolderWithPackagespec() { | 992 void test_setRoots_removeFolderWithPackagespec() { |
994 // create a pubspec | 993 // create a pubspec |
995 String pubspecPath = posix.join(projPath, '.packages'); | 994 String pubspecPath = path.posix.join(projPath, '.packages'); |
996 resourceProvider.newFile(pubspecPath, ''); | 995 resourceProvider.newFile(pubspecPath, ''); |
997 // add one root - there is a context | 996 // add one root - there is a context |
998 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 997 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
999 expect(manager.changeSubscriptions, hasLength(1)); | 998 expect(manager.changeSubscriptions, hasLength(1)); |
1000 expect(callbacks.currentContextPaths, hasLength(1)); | 999 expect(callbacks.currentContextPaths, hasLength(1)); |
1001 // set empty roots - no contexts | 1000 // set empty roots - no contexts |
1002 manager.setRoots(<String>[], <String>[], <String, String>{}); | 1001 manager.setRoots(<String>[], <String>[], <String, String>{}); |
1003 expect(manager.changeSubscriptions, hasLength(0)); | 1002 expect(manager.changeSubscriptions, hasLength(0)); |
1004 expect(callbacks.currentContextPaths, hasLength(0)); | 1003 expect(callbacks.currentContextPaths, hasLength(0)); |
1005 expect(callbacks.currentContextFilePaths, hasLength(0)); | 1004 expect(callbacks.currentContextFilePaths, hasLength(0)); |
(...skipping 29 matching lines...) Expand all Loading... |
1035 callbacks.assertContextFiles(subProjectB, [subProjectB_file]); | 1034 callbacks.assertContextFiles(subProjectB, [subProjectB_file]); |
1036 // remove "projectB" | 1035 // remove "projectB" |
1037 manager.setRoots(<String>[projectA], <String>[], <String, String>{}); | 1036 manager.setRoots(<String>[projectA], <String>[], <String, String>{}); |
1038 callbacks.assertContextPaths([projectA, subProjectA]); | 1037 callbacks.assertContextPaths([projectA, subProjectA]); |
1039 callbacks.assertContextFiles(projectA, [projectA_file]); | 1038 callbacks.assertContextFiles(projectA, [projectA_file]); |
1040 callbacks.assertContextFiles(subProjectA, [subProjectA_file]); | 1039 callbacks.assertContextFiles(subProjectA, [subProjectA_file]); |
1041 } | 1040 } |
1042 | 1041 |
1043 void test_setRoots_removeFolderWithPubspec() { | 1042 void test_setRoots_removeFolderWithPubspec() { |
1044 // create a pubspec | 1043 // create a pubspec |
1045 String pubspecPath = posix.join(projPath, 'pubspec.yaml'); | 1044 String pubspecPath = path.posix.join(projPath, 'pubspec.yaml'); |
1046 resourceProvider.newFile(pubspecPath, 'pubspec'); | 1045 resourceProvider.newFile(pubspecPath, 'pubspec'); |
1047 // add one root - there is a context | 1046 // add one root - there is a context |
1048 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 1047 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
1049 expect(callbacks.currentContextPaths, hasLength(1)); | 1048 expect(callbacks.currentContextPaths, hasLength(1)); |
1050 // set empty roots - no contexts | 1049 // set empty roots - no contexts |
1051 manager.setRoots(<String>[], <String>[], <String, String>{}); | 1050 manager.setRoots(<String>[], <String>[], <String, String>{}); |
1052 expect(callbacks.currentContextPaths, hasLength(0)); | 1051 expect(callbacks.currentContextPaths, hasLength(0)); |
1053 expect(callbacks.currentContextFilePaths, hasLength(0)); | 1052 expect(callbacks.currentContextFilePaths, hasLength(0)); |
1054 } | 1053 } |
1055 | 1054 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1118 callbacks.assertContextPaths([project]); | 1117 callbacks.assertContextPaths([project]); |
1119 callbacks.assertContextFiles(project, [fileA]); | 1118 callbacks.assertContextFiles(project, [fileA]); |
1120 } | 1119 } |
1121 | 1120 |
1122 test_watch_addDummyLink() { | 1121 test_watch_addDummyLink() { |
1123 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 1122 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
1124 // empty folder initially | 1123 // empty folder initially |
1125 Map<String, int> filePaths = callbacks.currentContextFilePaths[projPath]; | 1124 Map<String, int> filePaths = callbacks.currentContextFilePaths[projPath]; |
1126 expect(filePaths, isEmpty); | 1125 expect(filePaths, isEmpty); |
1127 // add link | 1126 // add link |
1128 String filePath = posix.join(projPath, 'foo.dart'); | 1127 String filePath = path.posix.join(projPath, 'foo.dart'); |
1129 resourceProvider.newDummyLink(filePath); | 1128 resourceProvider.newDummyLink(filePath); |
1130 // the link was ignored | 1129 // the link was ignored |
1131 return pumpEventQueue().then((_) { | 1130 return pumpEventQueue().then((_) { |
1132 expect(filePaths, isEmpty); | 1131 expect(filePaths, isEmpty); |
1133 }); | 1132 }); |
1134 } | 1133 } |
1135 | 1134 |
1136 test_watch_addFile() { | 1135 test_watch_addFile() { |
1137 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 1136 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
1138 // empty folder initially | 1137 // empty folder initially |
1139 Map<String, int> filePaths = callbacks.currentContextFilePaths[projPath]; | 1138 Map<String, int> filePaths = callbacks.currentContextFilePaths[projPath]; |
1140 expect(filePaths, hasLength(0)); | 1139 expect(filePaths, hasLength(0)); |
1141 // add file | 1140 // add file |
1142 String filePath = posix.join(projPath, 'foo.dart'); | 1141 String filePath = path.posix.join(projPath, 'foo.dart'); |
1143 resourceProvider.newFile(filePath, 'contents'); | 1142 resourceProvider.newFile(filePath, 'contents'); |
1144 // the file was added | 1143 // the file was added |
1145 return pumpEventQueue().then((_) { | 1144 return pumpEventQueue().then((_) { |
1146 expect(filePaths, hasLength(1)); | 1145 expect(filePaths, hasLength(1)); |
1147 expect(filePaths, contains(filePath)); | 1146 expect(filePaths, contains(filePath)); |
1148 }); | 1147 }); |
1149 } | 1148 } |
1150 | 1149 |
1151 test_watch_addFile_excluded() { | 1150 test_watch_addFile_excluded() { |
1152 // prepare paths | 1151 // prepare paths |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1238 callbacks.assertContextPaths([project]); | 1237 callbacks.assertContextPaths([project]); |
1239 callbacks.assertContextFiles(project, [fileA, fileB]); | 1238 callbacks.assertContextFiles(project, [fileA, fileB]); |
1240 } | 1239 } |
1241 | 1240 |
1242 test_watch_addFileInSubfolder() { | 1241 test_watch_addFileInSubfolder() { |
1243 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 1242 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
1244 // empty folder initially | 1243 // empty folder initially |
1245 Map<String, int> filePaths = callbacks.currentContextFilePaths[projPath]; | 1244 Map<String, int> filePaths = callbacks.currentContextFilePaths[projPath]; |
1246 expect(filePaths, hasLength(0)); | 1245 expect(filePaths, hasLength(0)); |
1247 // add file in subfolder | 1246 // add file in subfolder |
1248 String filePath = posix.join(projPath, 'foo', 'bar.dart'); | 1247 String filePath = path.posix.join(projPath, 'foo', 'bar.dart'); |
1249 resourceProvider.newFile(filePath, 'contents'); | 1248 resourceProvider.newFile(filePath, 'contents'); |
1250 // the file was added | 1249 // the file was added |
1251 return pumpEventQueue().then((_) { | 1250 return pumpEventQueue().then((_) { |
1252 expect(filePaths, hasLength(1)); | 1251 expect(filePaths, hasLength(1)); |
1253 expect(filePaths, contains(filePath)); | 1252 expect(filePaths, contains(filePath)); |
1254 }); | 1253 }); |
1255 } | 1254 } |
1256 | 1255 |
1257 test_watch_addPackagespec_toRoot() { | 1256 test_watch_addPackagespec_toRoot() { |
1258 // prepare paths | 1257 // prepare paths |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1419 // add pubspec - ignore, because is already in a pubspec-based context | 1418 // add pubspec - ignore, because is already in a pubspec-based context |
1420 resourceProvider.newFile(subSubPubspec, 'pubspec'); | 1419 resourceProvider.newFile(subSubPubspec, 'pubspec'); |
1421 return pumpEventQueue().then((_) { | 1420 return pumpEventQueue().then((_) { |
1422 callbacks.assertContextPaths([root, subProject]); | 1421 callbacks.assertContextPaths([root, subProject]); |
1423 callbacks.assertContextFiles(root, [rootFile]); | 1422 callbacks.assertContextFiles(root, [rootFile]); |
1424 callbacks.assertContextFiles(subProject, [subFile]); | 1423 callbacks.assertContextFiles(subProject, [subFile]); |
1425 }); | 1424 }); |
1426 } | 1425 } |
1427 | 1426 |
1428 test_watch_deleteFile() { | 1427 test_watch_deleteFile() { |
1429 String filePath = posix.join(projPath, 'foo.dart'); | 1428 String filePath = path.posix.join(projPath, 'foo.dart'); |
1430 // add root with a file | 1429 // add root with a file |
1431 File file = resourceProvider.newFile(filePath, 'contents'); | 1430 File file = resourceProvider.newFile(filePath, 'contents'); |
1432 Folder projFolder = file.parent; | 1431 Folder projFolder = file.parent; |
1433 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 1432 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
1434 // the file was added | 1433 // the file was added |
1435 Map<String, int> filePaths = callbacks.currentContextFilePaths[projPath]; | 1434 Map<String, int> filePaths = callbacks.currentContextFilePaths[projPath]; |
1436 expect(filePaths, hasLength(1)); | 1435 expect(filePaths, hasLength(1)); |
1437 expect(filePaths, contains(filePath)); | 1436 expect(filePaths, contains(filePath)); |
1438 expect(file.exists, isTrue); | 1437 expect(file.exists, isTrue); |
1439 expect(projFolder.exists, isTrue); | 1438 expect(projFolder.exists, isTrue); |
1440 // delete the file | 1439 // delete the file |
1441 resourceProvider.deleteFile(filePath); | 1440 resourceProvider.deleteFile(filePath); |
1442 return pumpEventQueue().then((_) { | 1441 return pumpEventQueue().then((_) { |
1443 expect(file.exists, isFalse); | 1442 expect(file.exists, isFalse); |
1444 expect(projFolder.exists, isTrue); | 1443 expect(projFolder.exists, isTrue); |
1445 return expect(filePaths, hasLength(0)); | 1444 return expect(filePaths, hasLength(0)); |
1446 }); | 1445 }); |
1447 } | 1446 } |
1448 | 1447 |
1449 test_watch_deleteFolder() { | 1448 test_watch_deleteFolder() { |
1450 String filePath = posix.join(projPath, 'foo.dart'); | 1449 String filePath = path.posix.join(projPath, 'foo.dart'); |
1451 // add root with a file | 1450 // add root with a file |
1452 File file = resourceProvider.newFile(filePath, 'contents'); | 1451 File file = resourceProvider.newFile(filePath, 'contents'); |
1453 Folder projFolder = file.parent; | 1452 Folder projFolder = file.parent; |
1454 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 1453 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
1455 // the file was added | 1454 // the file was added |
1456 Map<String, int> filePaths = callbacks.currentContextFilePaths[projPath]; | 1455 Map<String, int> filePaths = callbacks.currentContextFilePaths[projPath]; |
1457 expect(filePaths, hasLength(1)); | 1456 expect(filePaths, hasLength(1)); |
1458 expect(filePaths, contains(filePath)); | 1457 expect(filePaths, contains(filePath)); |
1459 expect(file.exists, isTrue); | 1458 expect(file.exists, isTrue); |
1460 expect(projFolder.exists, isTrue); | 1459 expect(projFolder.exists, isTrue); |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1589 callbacks.assertContextFiles(subProject, [subFile]); | 1588 callbacks.assertContextFiles(subProject, [subFile]); |
1590 // delete the pubspec | 1589 // delete the pubspec |
1591 resourceProvider.deleteFile(subPubspec); | 1590 resourceProvider.deleteFile(subPubspec); |
1592 return pumpEventQueue().then((_) { | 1591 return pumpEventQueue().then((_) { |
1593 callbacks.assertContextPaths([root]); | 1592 callbacks.assertContextPaths([root]); |
1594 callbacks.assertContextFiles(root, [rootFile, subFile]); | 1593 callbacks.assertContextFiles(root, [rootFile, subFile]); |
1595 }); | 1594 }); |
1596 } | 1595 } |
1597 | 1596 |
1598 test_watch_modifyFile() { | 1597 test_watch_modifyFile() { |
1599 String filePath = posix.join(projPath, 'foo.dart'); | 1598 String filePath = path.posix.join(projPath, 'foo.dart'); |
1600 // add root with a file | 1599 // add root with a file |
1601 resourceProvider.newFile(filePath, 'contents'); | 1600 resourceProvider.newFile(filePath, 'contents'); |
1602 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 1601 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
1603 // the file was added | 1602 // the file was added |
1604 Map<String, int> filePaths = callbacks.currentContextFilePaths[projPath]; | 1603 Map<String, int> filePaths = callbacks.currentContextFilePaths[projPath]; |
1605 expect(filePaths, hasLength(1)); | 1604 expect(filePaths, hasLength(1)); |
1606 expect(filePaths, contains(filePath)); | 1605 expect(filePaths, contains(filePath)); |
1607 expect(filePaths[filePath], equals(callbacks.now)); | 1606 expect(filePaths[filePath], equals(callbacks.now)); |
1608 // update the file | 1607 // update the file |
1609 callbacks.now++; | 1608 callbacks.now++; |
1610 resourceProvider.modifyFile(filePath, 'new contents'); | 1609 resourceProvider.modifyFile(filePath, 'new contents'); |
1611 return pumpEventQueue().then((_) { | 1610 return pumpEventQueue().then((_) { |
1612 return expect(filePaths[filePath], equals(callbacks.now)); | 1611 return expect(filePaths[filePath], equals(callbacks.now)); |
1613 }); | 1612 }); |
1614 } | 1613 } |
1615 | 1614 |
1616 test_watch_modifyPackageMapDependency_fail() async { | 1615 test_watch_modifyPackageMapDependency_fail() async { |
1617 // create a dependency file | 1616 // create a dependency file |
1618 String dependencyPath = posix.join(projPath, 'dep'); | 1617 String dependencyPath = path.posix.join(projPath, 'dep'); |
1619 resourceProvider.newFile(dependencyPath, 'contents'); | 1618 resourceProvider.newFile(dependencyPath, 'contents'); |
1620 packageMapProvider.dependencies.add(dependencyPath); | 1619 packageMapProvider.dependencies.add(dependencyPath); |
1621 // create a Dart file | 1620 // create a Dart file |
1622 String dartFilePath = posix.join(projPath, 'main.dart'); | 1621 String dartFilePath = path.posix.join(projPath, 'main.dart'); |
1623 resourceProvider.newFile(dartFilePath, 'contents'); | 1622 resourceProvider.newFile(dartFilePath, 'contents'); |
1624 // the created context has the expected empty package map | 1623 // the created context has the expected empty package map |
1625 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 1624 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
1626 expect(_currentPackageMap, isEmpty); | 1625 expect(_currentPackageMap, isEmpty); |
1627 // Change the package map dependency so that the packageMapProvider is | 1626 // Change the package map dependency so that the packageMapProvider is |
1628 // re-run, and arrange for it to return null from computePackageMap(). | 1627 // re-run, and arrange for it to return null from computePackageMap(). |
1629 packageMapProvider.packageMap = null; | 1628 packageMapProvider.packageMap = null; |
1630 resourceProvider.modifyFile(dependencyPath, 'new contents'); | 1629 resourceProvider.modifyFile(dependencyPath, 'new contents'); |
1631 await pumpEventQueue(); | 1630 await pumpEventQueue(); |
1632 // The package map should have been changed to null. | 1631 // The package map should have been changed to null. |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1737 | 1736 |
1738 List<Glob> get analysisFilesGlobs { | 1737 List<Glob> get analysisFilesGlobs { |
1739 List<String> patterns = <String>[ | 1738 List<String> patterns = <String>[ |
1740 '**/*.${AnalysisEngine.SUFFIX_DART}', | 1739 '**/*.${AnalysisEngine.SUFFIX_DART}', |
1741 '**/*.${AnalysisEngine.SUFFIX_HTML}', | 1740 '**/*.${AnalysisEngine.SUFFIX_HTML}', |
1742 '**/*.${AnalysisEngine.SUFFIX_HTM}', | 1741 '**/*.${AnalysisEngine.SUFFIX_HTM}', |
1743 '**/${AnalysisEngine.ANALYSIS_OPTIONS_FILE}', | 1742 '**/${AnalysisEngine.ANALYSIS_OPTIONS_FILE}', |
1744 '**/${AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE}' | 1743 '**/${AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE}' |
1745 ]; | 1744 ]; |
1746 return patterns | 1745 return patterns |
1747 .map((pattern) => new Glob(posix.separator, pattern)) | 1746 .map((pattern) => new Glob(path.posix.separator, pattern)) |
1748 .toList(); | 1747 .toList(); |
1749 } | 1748 } |
1750 | 1749 |
1751 List<ErrorProcessor> get errorProcessors => callbacks.currentContext | 1750 List<ErrorProcessor> get errorProcessors => callbacks.currentContext |
1752 .getConfigurationData(CONFIGURED_ERROR_PROCESSORS); | 1751 .getConfigurationData(CONFIGURED_ERROR_PROCESSORS); |
1753 | 1752 |
1754 List<Linter> get lints => getLints(callbacks.currentContext); | 1753 List<Linter> get lints => getLints(callbacks.currentContext); |
1755 | 1754 |
1756 AnalysisOptions get options => callbacks.currentContext.analysisOptions; | 1755 AnalysisOptions get options => callbacks.currentContext.analysisOptions; |
1757 | 1756 |
1758 Map<String, List<Folder>> get _currentPackageMap => _packageMap(projPath); | 1757 Map<String, List<Folder>> get _currentPackageMap => _packageMap(projPath); |
1759 | 1758 |
1760 void deleteFile(List<String> pathComponents) { | 1759 void deleteFile(List<String> pathComponents) { |
1761 String filePath = posix.joinAll(pathComponents); | 1760 String filePath = path.posix.joinAll(pathComponents); |
1762 resourceProvider.deleteFile(filePath); | 1761 resourceProvider.deleteFile(filePath); |
1763 } | 1762 } |
1764 | 1763 |
1765 ErrorProcessor getProcessor(AnalysisError error) => | 1764 ErrorProcessor getProcessor(AnalysisError error) => |
1766 ErrorProcessor.getProcessor(callbacks.currentContext, error); | 1765 ErrorProcessor.getProcessor(callbacks.currentContext, error); |
1767 | 1766 |
1768 String newFile(List<String> pathComponents, [String content = '']) { | 1767 String newFile(List<String> pathComponents, [String content = '']) { |
1769 String filePath = posix.joinAll(pathComponents); | 1768 String filePath = path.posix.joinAll(pathComponents); |
1770 resourceProvider.newFile(filePath, content); | 1769 resourceProvider.newFile(filePath, content); |
1771 return filePath; | 1770 return filePath; |
1772 } | 1771 } |
1773 | 1772 |
1774 String newFolder(List<String> pathComponents) { | 1773 String newFolder(List<String> pathComponents) { |
1775 String folderPath = posix.joinAll(pathComponents); | 1774 String folderPath = path.posix.joinAll(pathComponents); |
1776 resourceProvider.newFolder(folderPath); | 1775 resourceProvider.newFolder(folderPath); |
1777 return folderPath; | 1776 return folderPath; |
1778 } | 1777 } |
1779 | 1778 |
1780 void processRequiredPlugins() { | 1779 void processRequiredPlugins() { |
1781 List<Plugin> plugins = <Plugin>[]; | 1780 List<Plugin> plugins = <Plugin>[]; |
1782 plugins.addAll(AnalysisEngine.instance.requiredPlugins); | 1781 plugins.addAll(AnalysisEngine.instance.requiredPlugins); |
1783 plugins.add(AnalysisEngine.instance.commandLinePlugin); | 1782 plugins.add(AnalysisEngine.instance.commandLinePlugin); |
1784 plugins.add(AnalysisEngine.instance.optionsPlugin); | 1783 plugins.add(AnalysisEngine.instance.optionsPlugin); |
1785 plugins.add(linterPlugin); | 1784 plugins.add(linterPlugin); |
(...skipping 1019 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2805 class TestUriResolver extends UriResolver { | 2804 class TestUriResolver extends UriResolver { |
2806 Map<Uri, Source> uriMap; | 2805 Map<Uri, Source> uriMap; |
2807 | 2806 |
2808 TestUriResolver(this.uriMap); | 2807 TestUriResolver(this.uriMap); |
2809 | 2808 |
2810 @override | 2809 @override |
2811 Source resolveAbsolute(Uri uri, [Uri actualUri]) { | 2810 Source resolveAbsolute(Uri uri, [Uri actualUri]) { |
2812 return uriMap[uri]; | 2811 return uriMap[uri]; |
2813 } | 2812 } |
2814 } | 2813 } |
OLD | NEW |