| 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/file_system/file_system.dart'; | 10 import 'package:analyzer/file_system/file_system.dart'; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 groupSep = ' | '; | 25 groupSep = ' | '; |
| 26 runReflectiveTests(ContextManagerTest); | 26 runReflectiveTests(ContextManagerTest); |
| 27 } | 27 } |
| 28 | 28 |
| 29 @reflectiveTest | 29 @reflectiveTest |
| 30 class ContextManagerTest { | 30 class ContextManagerTest { |
| 31 /** | 31 /** |
| 32 * The name of the 'bin' directory. | 32 * The name of the 'bin' directory. |
| 33 */ | 33 */ |
| 34 static const String BIN_NAME = 'bin'; | 34 static const String BIN_NAME = 'bin'; |
| 35 |
| 36 /** |
| 37 * The name of the 'example' directory. |
| 38 */ |
| 39 static const String EXAMPLE_NAME = 'example'; |
| 40 |
| 35 /** | 41 /** |
| 36 * The name of the 'lib' directory. | 42 * The name of the 'lib' directory. |
| 37 */ | 43 */ |
| 38 static const String LIB_NAME = 'lib'; | 44 static const String LIB_NAME = 'lib'; |
| 45 |
| 39 /** | 46 /** |
| 40 * The name of the 'src' directory. | 47 * The name of the 'src' directory. |
| 41 */ | 48 */ |
| 42 static const String SRC_NAME = 'src'; | 49 static const String SRC_NAME = 'src'; |
| 43 | 50 |
| 44 /** | 51 /** |
| 45 * The name of the 'test' directory. | 52 * The name of the 'test' directory. |
| 46 */ | 53 */ |
| 47 static const String TEST_NAME = 'test'; | 54 static const String TEST_NAME = 'test'; |
| 48 | 55 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 | 184 |
| 178 void test_setRoots_addFolderWithDummyLink() { | 185 void test_setRoots_addFolderWithDummyLink() { |
| 179 String filePath = posix.join(projPath, 'foo.dart'); | 186 String filePath = posix.join(projPath, 'foo.dart'); |
| 180 resourceProvider.newDummyLink(filePath); | 187 resourceProvider.newDummyLink(filePath); |
| 181 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 188 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
| 182 // verify | 189 // verify |
| 183 var filePaths = manager.currentContextFilePaths[projPath]; | 190 var filePaths = manager.currentContextFilePaths[projPath]; |
| 184 expect(filePaths, isEmpty); | 191 expect(filePaths, isEmpty); |
| 185 } | 192 } |
| 186 | 193 |
| 194 void test_setRoots_addFolderWithNestedPubspec() { |
| 195 String examplePath = newFolder([projPath, EXAMPLE_NAME]); |
| 196 String libPath = newFolder([projPath, LIB_NAME]); |
| 197 |
| 198 newFile([projPath, PUBSPEC_NAME]); |
| 199 newFile([libPath, 'main.dart']); |
| 200 newFile([examplePath, PUBSPEC_NAME]); |
| 201 newFile([examplePath, 'example.dart']); |
| 202 |
| 203 packageMapProvider.packageMap['proj'] = |
| 204 [resourceProvider.getResource(libPath)]; |
| 205 |
| 206 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
| 207 |
| 208 expect(manager.currentContextPaths, hasLength(2)); |
| 209 |
| 210 expect(manager.currentContextPaths, contains(projPath)); |
| 211 Set<Source> projSources = manager.currentContextSources[projPath]; |
| 212 expect(projSources, hasLength(1)); |
| 213 expect(projSources.first.uri.toString(), 'package:proj/main.dart'); |
| 214 |
| 215 expect(manager.currentContextPaths, contains(examplePath)); |
| 216 Set<Source> exampleSources = manager.currentContextSources[examplePath]; |
| 217 expect(exampleSources, hasLength(1)); |
| 218 expect(exampleSources.first.uri.toString(), |
| 219 'file:///my/proj/example/example.dart'); |
| 220 } |
| 221 |
| 187 void test_setRoots_addFolderWithoutPubspec() { | 222 void test_setRoots_addFolderWithoutPubspec() { |
| 188 packageMapProvider.packageMap = null; | 223 packageMapProvider.packageMap = null; |
| 189 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 224 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
| 190 // verify | 225 // verify |
| 191 expect(manager.currentContextPaths, hasLength(1)); | 226 expect(manager.currentContextPaths, hasLength(1)); |
| 192 expect(manager.currentContextPaths, contains(projPath)); | 227 expect(manager.currentContextPaths, contains(projPath)); |
| 193 expect(manager.currentContextFilePaths[projPath], hasLength(0)); | 228 expect(manager.currentContextFilePaths[projPath], hasLength(0)); |
| 194 } | 229 } |
| 195 | 230 |
| 196 void test_setRoots_addFolderWithPubspec() { | 231 void test_setRoots_addFolderWithPubspec() { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 208 String libPath = newFolder([projPath, LIB_NAME]); | 243 String libPath = newFolder([projPath, LIB_NAME]); |
| 209 String srcPath = newFolder([libPath, SRC_NAME]); | 244 String srcPath = newFolder([libPath, SRC_NAME]); |
| 210 String testPath = newFolder([projPath, TEST_NAME]); | 245 String testPath = newFolder([projPath, TEST_NAME]); |
| 211 | 246 |
| 212 newFile([projPath, PUBSPEC_NAME]); | 247 newFile([projPath, PUBSPEC_NAME]); |
| 213 String appPath = newFile([binPath, 'app.dart']); | 248 String appPath = newFile([binPath, 'app.dart']); |
| 214 newFile([libPath, 'main.dart']); | 249 newFile([libPath, 'main.dart']); |
| 215 newFile([srcPath, 'internal.dart']); | 250 newFile([srcPath, 'internal.dart']); |
| 216 String testFilePath = newFile([testPath, 'main_test.dart']); | 251 String testFilePath = newFile([testPath, 'main_test.dart']); |
| 217 | 252 |
| 218 packageMapProvider.packageMap['proj'] = [ | 253 packageMapProvider.packageMap['proj'] = |
| 219 resourceProvider.getResource(libPath) | 254 [resourceProvider.getResource(libPath)]; |
| 220 ]; | |
| 221 | 255 |
| 222 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 256 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
| 223 Set<Source> sources = manager.currentContextSources[projPath]; | 257 Set<Source> sources = manager.currentContextSources[projPath]; |
| 224 | 258 |
| 225 expect(manager.currentContextPaths, hasLength(1)); | 259 expect(manager.currentContextPaths, hasLength(1)); |
| 226 expect(manager.currentContextPaths, contains(projPath)); | 260 expect(manager.currentContextPaths, contains(projPath)); |
| 227 expect(sources, hasLength(4)); | 261 expect(sources, hasLength(4)); |
| 228 List<String> uris = | 262 List<String> uris = |
| 229 sources.map((Source source) => source.uri.toString()).toList(); | 263 sources.map((Source source) => source.uri.toString()).toList(); |
| 230 expect(uris, contains('file://$appPath')); | 264 expect(uris, contains('file://$appPath')); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 | 303 |
| 270 void test_setRoots_addPackageRoot() { | 304 void test_setRoots_addPackageRoot() { |
| 271 String packagePathFoo = '/package1/foo'; | 305 String packagePathFoo = '/package1/foo'; |
| 272 String packageRootPath = '/package2/foo'; | 306 String packageRootPath = '/package2/foo'; |
| 273 Folder packageFolder = resourceProvider.newFolder(packagePathFoo); | 307 Folder packageFolder = resourceProvider.newFolder(packagePathFoo); |
| 274 packageMapProvider.packageMap = {'foo': [packageFolder]}; | 308 packageMapProvider.packageMap = {'foo': [packageFolder]}; |
| 275 List<String> includedPaths = <String>[projPath]; | 309 List<String> includedPaths = <String>[projPath]; |
| 276 List<String> excludedPaths = <String>[]; | 310 List<String> excludedPaths = <String>[]; |
| 277 manager.setRoots(includedPaths, excludedPaths, <String, String>{}); | 311 manager.setRoots(includedPaths, excludedPaths, <String, String>{}); |
| 278 _checkPackageMap(projPath, equals(packageMapProvider.packageMap)); | 312 _checkPackageMap(projPath, equals(packageMapProvider.packageMap)); |
| 279 manager.setRoots(includedPaths, | 313 manager.setRoots(includedPaths, excludedPaths, <String, String>{ |
| 280 excludedPaths, <String, String>{projPath: packageRootPath}); | 314 projPath: packageRootPath |
| 315 }); |
| 281 _checkPackageRoot(projPath, equals(packageRootPath)); | 316 _checkPackageRoot(projPath, equals(packageRootPath)); |
| 282 } | 317 } |
| 283 | 318 |
| 284 void test_setRoots_changePackageRoot() { | 319 void test_setRoots_changePackageRoot() { |
| 285 String packageRootPath1 = '/package1'; | 320 String packageRootPath1 = '/package1'; |
| 286 String packageRootPath2 = '/package2'; | 321 String packageRootPath2 = '/package2'; |
| 287 List<String> includedPaths = <String>[projPath]; | 322 List<String> includedPaths = <String>[projPath]; |
| 288 List<String> excludedPaths = <String>[]; | 323 List<String> excludedPaths = <String>[]; |
| 289 manager.setRoots(includedPaths, excludedPaths, <String, String>{ | 324 manager.setRoots(includedPaths, excludedPaths, <String, String>{ |
| 290 projPath: packageRootPath1 | 325 projPath: packageRootPath1 |
| 291 }); | 326 }); |
| 292 _checkPackageRoot(projPath, equals(packageRootPath1)); | 327 _checkPackageRoot(projPath, equals(packageRootPath1)); |
| 293 manager.setRoots(includedPaths, | 328 manager.setRoots(includedPaths, excludedPaths, <String, String>{ |
| 294 excludedPaths, <String, String>{projPath: packageRootPath2}); | 329 projPath: packageRootPath2 |
| 330 }); |
| 295 _checkPackageRoot(projPath, equals(packageRootPath2)); | 331 _checkPackageRoot(projPath, equals(packageRootPath2)); |
| 296 } | 332 } |
| 297 | 333 |
| 298 void test_setRoots_exclude_newRoot_withExcludedFile() { | 334 void test_setRoots_exclude_newRoot_withExcludedFile() { |
| 299 // prepare paths | 335 // prepare paths |
| 300 String project = '/project'; | 336 String project = '/project'; |
| 301 String file1 = '$project/file1.dart'; | 337 String file1 = '$project/file1.dart'; |
| 302 String file2 = '$project/file2.dart'; | 338 String file2 = '$project/file2.dart'; |
| 303 // create files | 339 // create files |
| 304 resourceProvider.newFile(file1, '// 1'); | 340 resourceProvider.newFile(file1, '// 1'); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 // exclude "bbb/" | 448 // exclude "bbb/" |
| 413 manager.setRoots(<String>[project], <String>[folderB], <String, String>{}); | 449 manager.setRoots(<String>[project], <String>[folderB], <String, String>{}); |
| 414 manager.assertContextPaths([project]); | 450 manager.assertContextPaths([project]); |
| 415 manager.assertContextFiles(project, [fileA]); | 451 manager.assertContextFiles(project, [fileA]); |
| 416 // stop excluding "bbb/" | 452 // stop excluding "bbb/" |
| 417 manager.setRoots(<String>[project], <String>[], <String, String>{}); | 453 manager.setRoots(<String>[project], <String>[], <String, String>{}); |
| 418 manager.assertContextPaths([project]); | 454 manager.assertContextPaths([project]); |
| 419 manager.assertContextFiles(project, [fileA, fileB]); | 455 manager.assertContextFiles(project, [fileA, fileB]); |
| 420 } | 456 } |
| 421 | 457 |
| 422 void test_setRoots_ignoreSubContext_ofSubContext() { | |
| 423 // prepare paths | |
| 424 String root = '/root'; | |
| 425 String rootFile = '$root/root.dart'; | |
| 426 String subProject = '$root/sub'; | |
| 427 String subPubspec = '$subProject/pubspec.yaml'; | |
| 428 String subFile = '$subProject/bin/sub.dart'; | |
| 429 String subSubPubspec = '$subProject/subsub/pubspec.yaml'; | |
| 430 // create files | |
| 431 resourceProvider.newFile(rootFile, 'library root;'); | |
| 432 resourceProvider.newFile(subPubspec, 'pubspec'); | |
| 433 resourceProvider.newFile(subFile, 'library sub;'); | |
| 434 resourceProvider.newFile(subSubPubspec, 'pubspec'); | |
| 435 // set roots | |
| 436 manager.setRoots(<String>[root], <String>[], <String, String>{}); | |
| 437 manager.assertContextPaths([root, subProject]); | |
| 438 manager.assertContextFiles(root, [rootFile]); | |
| 439 manager.assertContextFiles(subProject, [subFile]); | |
| 440 } | |
| 441 | |
| 442 void test_setRoots_newFolderWithPackageRoot() { | 458 void test_setRoots_newFolderWithPackageRoot() { |
| 443 String packageRootPath = '/package'; | 459 String packageRootPath = '/package'; |
| 444 manager.setRoots(<String>[projPath], <String>[], <String, String>{ | 460 manager.setRoots(<String>[projPath], <String>[], <String, String>{ |
| 445 projPath: packageRootPath | 461 projPath: packageRootPath |
| 446 }); | 462 }); |
| 447 _checkPackageRoot(projPath, equals(packageRootPath)); | 463 _checkPackageRoot(projPath, equals(packageRootPath)); |
| 448 } | 464 } |
| 449 | 465 |
| 450 void test_setRoots_newlyAddedFoldersGetProperPackageMap() { | 466 void test_setRoots_newlyAddedFoldersGetProperPackageMap() { |
| 451 String packagePath = '/package/foo'; | 467 String packagePath = '/package/foo'; |
| (...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 940 currentContextSources.remove(path); | 956 currentContextSources.remove(path); |
| 941 currentContextPackageUriResolvers.remove(path); | 957 currentContextPackageUriResolvers.remove(path); |
| 942 } | 958 } |
| 943 | 959 |
| 944 @override | 960 @override |
| 945 void updateContextPackageUriResolver( | 961 void updateContextPackageUriResolver( |
| 946 Folder contextFolder, UriResolver packageUriResolver) { | 962 Folder contextFolder, UriResolver packageUriResolver) { |
| 947 currentContextPackageUriResolvers[contextFolder.path] = packageUriResolver; | 963 currentContextPackageUriResolvers[contextFolder.path] = packageUriResolver; |
| 948 } | 964 } |
| 949 } | 965 } |
| OLD | NEW |