| 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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 | 182 |
| 183 void test_setRoots_addFolderWithDummyLink() { | 183 void test_setRoots_addFolderWithDummyLink() { |
| 184 String filePath = posix.join(projPath, 'foo.dart'); | 184 String filePath = posix.join(projPath, 'foo.dart'); |
| 185 resourceProvider.newDummyLink(filePath); | 185 resourceProvider.newDummyLink(filePath); |
| 186 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 186 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
| 187 // verify | 187 // verify |
| 188 var filePaths = manager.currentContextFilePaths[projPath]; | 188 var filePaths = manager.currentContextFilePaths[projPath]; |
| 189 expect(filePaths, isEmpty); | 189 expect(filePaths, isEmpty); |
| 190 } | 190 } |
| 191 | 191 |
| 192 void test_setRoots_addFolderWithoutPubspec() { |
| 193 packageMapProvider.packageMap = null; |
| 194 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
| 195 // verify |
| 196 expect(manager.currentContextPaths, hasLength(1)); |
| 197 expect(manager.currentContextPaths, contains(projPath)); |
| 198 expect(manager.currentContextFilePaths[projPath], hasLength(0)); |
| 199 } |
| 200 |
| 192 void test_setRoots_addFolderWithPubspec() { | 201 void test_setRoots_addFolderWithPubspec() { |
| 193 String pubspecPath = posix.join(projPath, 'pubspec.yaml'); | 202 String pubspecPath = posix.join(projPath, 'pubspec.yaml'); |
| 194 resourceProvider.newFile(pubspecPath, 'pubspec'); | 203 resourceProvider.newFile(pubspecPath, 'pubspec'); |
| 195 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 204 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
| 196 // verify | 205 // verify |
| 197 expect(manager.currentContextPaths, hasLength(1)); | 206 expect(manager.currentContextPaths, hasLength(1)); |
| 198 expect(manager.currentContextPaths, contains(projPath)); | 207 expect(manager.currentContextPaths, contains(projPath)); |
| 199 expect(manager.currentContextFilePaths[projPath], hasLength(0)); | 208 expect(manager.currentContextFilePaths[projPath], hasLength(0)); |
| 200 } | 209 } |
| 201 | 210 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 // verify package maps | 270 // verify package maps |
| 262 _checkPackageMap(root, isNull); | 271 _checkPackageMap(root, isNull); |
| 263 _checkPackageMap( | 272 _checkPackageMap( |
| 264 subProjectA, | 273 subProjectA, |
| 265 equals(packageMapProvider.packageMaps[subProjectA])); | 274 equals(packageMapProvider.packageMaps[subProjectA])); |
| 266 _checkPackageMap( | 275 _checkPackageMap( |
| 267 subProjectB, | 276 subProjectB, |
| 268 equals(packageMapProvider.packageMaps[subProjectB])); | 277 equals(packageMapProvider.packageMaps[subProjectB])); |
| 269 } | 278 } |
| 270 | 279 |
| 271 void test_setRoots_addFolderWithoutPubspec() { | |
| 272 packageMapProvider.packageMap = null; | |
| 273 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | |
| 274 // verify | |
| 275 expect(manager.currentContextPaths, hasLength(1)); | |
| 276 expect(manager.currentContextPaths, contains(projPath)); | |
| 277 expect(manager.currentContextFilePaths[projPath], hasLength(0)); | |
| 278 } | |
| 279 | |
| 280 void test_setRoots_addPackageRoot() { | 280 void test_setRoots_addPackageRoot() { |
| 281 String packagePathFoo = '/package1/foo'; | 281 String packagePathFoo = '/package1/foo'; |
| 282 String packageRootPath = '/package2/foo'; | 282 String packageRootPath = '/package2/foo'; |
| 283 Folder packageFolder = resourceProvider.newFolder(packagePathFoo); | 283 Folder packageFolder = resourceProvider.newFolder(packagePathFoo); |
| 284 packageMapProvider.packageMap = { | 284 packageMapProvider.packageMap = { |
| 285 'foo': [packageFolder] | 285 'foo': [packageFolder] |
| 286 }; | 286 }; |
| 287 List<String> includedPaths = <String>[projPath]; | 287 List<String> includedPaths = <String>[projPath]; |
| 288 List<String> excludedPaths = <String>[]; | 288 List<String> excludedPaths = <String>[]; |
| 289 manager.setRoots(includedPaths, excludedPaths, <String, String>{}); | 289 manager.setRoots(includedPaths, excludedPaths, <String, String>{}); |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 void test_setRoots_newlyAddedFoldersGetProperPackageMap() { | 464 void test_setRoots_newlyAddedFoldersGetProperPackageMap() { |
| 465 String packagePath = '/package/foo'; | 465 String packagePath = '/package/foo'; |
| 466 Folder packageFolder = resourceProvider.newFolder(packagePath); | 466 Folder packageFolder = resourceProvider.newFolder(packagePath); |
| 467 packageMapProvider.packageMap = { | 467 packageMapProvider.packageMap = { |
| 468 'foo': [packageFolder] | 468 'foo': [packageFolder] |
| 469 }; | 469 }; |
| 470 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 470 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
| 471 _checkPackageMap(projPath, equals(packageMapProvider.packageMap)); | 471 _checkPackageMap(projPath, equals(packageMapProvider.packageMap)); |
| 472 } | 472 } |
| 473 | 473 |
| 474 void test_setRoots_removeFolderWithoutPubspec() { |
| 475 packageMapProvider.packageMap = null; |
| 476 // add one root - there is a context |
| 477 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
| 478 expect(manager.currentContextPaths, hasLength(1)); |
| 479 // set empty roots - no contexts |
| 480 manager.setRoots(<String>[], <String>[], <String, String>{}); |
| 481 expect(manager.currentContextPaths, hasLength(0)); |
| 482 expect(manager.currentContextFilePaths, hasLength(0)); |
| 483 } |
| 484 |
| 474 void test_setRoots_removeFolderWithPubspec() { | 485 void test_setRoots_removeFolderWithPubspec() { |
| 475 // create a pubspec | 486 // create a pubspec |
| 476 String pubspecPath = posix.join(projPath, 'pubspec.yaml'); | 487 String pubspecPath = posix.join(projPath, 'pubspec.yaml'); |
| 477 resourceProvider.newFile(pubspecPath, 'pubspec'); | 488 resourceProvider.newFile(pubspecPath, 'pubspec'); |
| 478 // add one root - there is a context | 489 // add one root - there is a context |
| 479 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 490 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
| 480 expect(manager.currentContextPaths, hasLength(1)); | 491 expect(manager.currentContextPaths, hasLength(1)); |
| 481 // set empty roots - no contexts | 492 // set empty roots - no contexts |
| 482 manager.setRoots(<String>[], <String>[], <String, String>{}); | 493 manager.setRoots(<String>[], <String>[], <String, String>{}); |
| 483 expect(manager.currentContextPaths, hasLength(0)); | 494 expect(manager.currentContextPaths, hasLength(0)); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 513 manager.assertContextFiles(projectB, [projectB_file]); | 524 manager.assertContextFiles(projectB, [projectB_file]); |
| 514 manager.assertContextFiles(subProjectA, [subProjectA_file]); | 525 manager.assertContextFiles(subProjectA, [subProjectA_file]); |
| 515 manager.assertContextFiles(subProjectB, [subProjectB_file]); | 526 manager.assertContextFiles(subProjectB, [subProjectB_file]); |
| 516 // remove "projectB" | 527 // remove "projectB" |
| 517 manager.setRoots(<String>[projectA], <String>[], <String, String>{}); | 528 manager.setRoots(<String>[projectA], <String>[], <String, String>{}); |
| 518 manager.assertContextPaths([projectA, subProjectA]); | 529 manager.assertContextPaths([projectA, subProjectA]); |
| 519 manager.assertContextFiles(projectA, [projectA_file]); | 530 manager.assertContextFiles(projectA, [projectA_file]); |
| 520 manager.assertContextFiles(subProjectA, [subProjectA_file]); | 531 manager.assertContextFiles(subProjectA, [subProjectA_file]); |
| 521 } | 532 } |
| 522 | 533 |
| 523 void test_setRoots_removeFolderWithoutPubspec() { | |
| 524 packageMapProvider.packageMap = null; | |
| 525 // add one root - there is a context | |
| 526 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | |
| 527 expect(manager.currentContextPaths, hasLength(1)); | |
| 528 // set empty roots - no contexts | |
| 529 manager.setRoots(<String>[], <String>[], <String, String>{}); | |
| 530 expect(manager.currentContextPaths, hasLength(0)); | |
| 531 expect(manager.currentContextFilePaths, hasLength(0)); | |
| 532 } | |
| 533 | |
| 534 void test_setRoots_removePackageRoot() { | 534 void test_setRoots_removePackageRoot() { |
| 535 String packagePathFoo = '/package1/foo'; | 535 String packagePathFoo = '/package1/foo'; |
| 536 String packageRootPath = '/package2/foo'; | 536 String packageRootPath = '/package2/foo'; |
| 537 Folder packageFolder = resourceProvider.newFolder(packagePathFoo); | 537 Folder packageFolder = resourceProvider.newFolder(packagePathFoo); |
| 538 packageMapProvider.packageMap = { | 538 packageMapProvider.packageMap = { |
| 539 'foo': [packageFolder] | 539 'foo': [packageFolder] |
| 540 }; | 540 }; |
| 541 List<String> includedPaths = <String>[projPath]; | 541 List<String> includedPaths = <String>[projPath]; |
| 542 List<String> excludedPaths = <String>[]; | 542 List<String> excludedPaths = <String>[]; |
| 543 manager.setRoots(includedPaths, excludedPaths, <String, String>{ | 543 manager.setRoots(includedPaths, excludedPaths, <String, String>{ |
| (...skipping 26 matching lines...) Expand all Loading... |
| 570 // add file | 570 // add file |
| 571 String filePath = posix.join(projPath, 'foo.dart'); | 571 String filePath = posix.join(projPath, 'foo.dart'); |
| 572 resourceProvider.newFile(filePath, 'contents'); | 572 resourceProvider.newFile(filePath, 'contents'); |
| 573 // the file was added | 573 // the file was added |
| 574 return pumpEventQueue().then((_) { | 574 return pumpEventQueue().then((_) { |
| 575 expect(filePaths, hasLength(1)); | 575 expect(filePaths, hasLength(1)); |
| 576 expect(filePaths, contains(filePath)); | 576 expect(filePaths, contains(filePath)); |
| 577 }); | 577 }); |
| 578 } | 578 } |
| 579 | 579 |
| 580 test_watch_addFileInSubfolder() { | |
| 581 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | |
| 582 // empty folder initially | |
| 583 Map<String, int> filePaths = manager.currentContextFilePaths[projPath]; | |
| 584 expect(filePaths, hasLength(0)); | |
| 585 // add file in subfolder | |
| 586 String filePath = posix.join(projPath, 'foo', 'bar.dart'); | |
| 587 resourceProvider.newFile(filePath, 'contents'); | |
| 588 // the file was added | |
| 589 return pumpEventQueue().then((_) { | |
| 590 expect(filePaths, hasLength(1)); | |
| 591 expect(filePaths, contains(filePath)); | |
| 592 }); | |
| 593 } | |
| 594 | |
| 595 test_watch_addFile_excluded() { | 580 test_watch_addFile_excluded() { |
| 596 // prepare paths | 581 // prepare paths |
| 597 String project = '/project'; | 582 String project = '/project'; |
| 598 String folderA = '$project/aaa'; | 583 String folderA = '$project/aaa'; |
| 599 String folderB = '$project/bbb'; | 584 String folderB = '$project/bbb'; |
| 600 String fileA = '$folderA/a.dart'; | 585 String fileA = '$folderA/a.dart'; |
| 601 String fileB = '$folderB/b.dart'; | 586 String fileB = '$folderB/b.dart'; |
| 602 // create files | 587 // create files |
| 603 resourceProvider.newFile(fileA, 'library a;'); | 588 resourceProvider.newFile(fileA, 'library a;'); |
| 604 // set roots | 589 // set roots |
| 605 manager.setRoots(<String>[project], <String>[folderB], <String, String>{}); | 590 manager.setRoots(<String>[project], <String>[folderB], <String, String>{}); |
| 606 manager.assertContextPaths([project]); | 591 manager.assertContextPaths([project]); |
| 607 manager.assertContextFiles(project, [fileA]); | 592 manager.assertContextFiles(project, [fileA]); |
| 608 // add a file, ignored as excluded | 593 // add a file, ignored as excluded |
| 609 resourceProvider.newFile(fileB, 'library b;'); | 594 resourceProvider.newFile(fileB, 'library b;'); |
| 610 return pumpEventQueue().then((_) { | 595 return pumpEventQueue().then((_) { |
| 611 manager.assertContextPaths([project]); | 596 manager.assertContextPaths([project]); |
| 612 manager.assertContextFiles(project, [fileA]); | 597 manager.assertContextFiles(project, [fileA]); |
| 613 }); | 598 }); |
| 614 } | 599 } |
| 615 | 600 |
| 601 test_watch_addFileInSubfolder() { |
| 602 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
| 603 // empty folder initially |
| 604 Map<String, int> filePaths = manager.currentContextFilePaths[projPath]; |
| 605 expect(filePaths, hasLength(0)); |
| 606 // add file in subfolder |
| 607 String filePath = posix.join(projPath, 'foo', 'bar.dart'); |
| 608 resourceProvider.newFile(filePath, 'contents'); |
| 609 // the file was added |
| 610 return pumpEventQueue().then((_) { |
| 611 expect(filePaths, hasLength(1)); |
| 612 expect(filePaths, contains(filePath)); |
| 613 }); |
| 614 } |
| 615 |
| 616 test_watch_addPubspec_toRoot() { | 616 test_watch_addPubspec_toRoot() { |
| 617 // prepare paths | 617 // prepare paths |
| 618 String root = '/root'; | 618 String root = '/root'; |
| 619 String rootFile = '$root/root.dart'; | 619 String rootFile = '$root/root.dart'; |
| 620 String rootPubspec = '$root/pubspec.yaml'; | 620 String rootPubspec = '$root/pubspec.yaml'; |
| 621 // create files | 621 // create files |
| 622 resourceProvider.newFile(rootFile, 'library root;'); | 622 resourceProvider.newFile(rootFile, 'library root;'); |
| 623 // set roots | 623 // set roots |
| 624 manager.setRoots(<String>[root], <String>[], <String, String>{}); | 624 manager.setRoots(<String>[root], <String>[], <String, String>{}); |
| 625 manager.assertContextPaths([root]); | 625 manager.assertContextPaths([root]); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 return pumpEventQueue().then((_) { | 679 return pumpEventQueue().then((_) { |
| 680 manager.assertContextPaths([root, subProject]); | 680 manager.assertContextPaths([root, subProject]); |
| 681 manager.assertContextFiles(root, [rootFile]); | 681 manager.assertContextFiles(root, [rootFile]); |
| 682 manager.assertContextFiles(subProject, [subFile]); | 682 manager.assertContextFiles(subProject, [subFile]); |
| 683 }); | 683 }); |
| 684 } | 684 } |
| 685 | 685 |
| 686 test_watch_deleteFile() { | 686 test_watch_deleteFile() { |
| 687 String filePath = posix.join(projPath, 'foo.dart'); | 687 String filePath = posix.join(projPath, 'foo.dart'); |
| 688 // add root with a file | 688 // add root with a file |
| 689 resourceProvider.newFile(filePath, 'contents'); | 689 File file = resourceProvider.newFile(filePath, 'contents'); |
| 690 Folder projFolder = file.parent; |
| 690 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 691 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
| 691 // the file was added | 692 // the file was added |
| 692 Map<String, int> filePaths = manager.currentContextFilePaths[projPath]; | 693 Map<String, int> filePaths = manager.currentContextFilePaths[projPath]; |
| 693 expect(filePaths, hasLength(1)); | 694 expect(filePaths, hasLength(1)); |
| 694 expect(filePaths, contains(filePath)); | 695 expect(filePaths, contains(filePath)); |
| 696 expect(file.exists, isTrue); |
| 697 expect(projFolder.exists, isTrue); |
| 695 // delete the file | 698 // delete the file |
| 696 resourceProvider.deleteFile(filePath); | 699 resourceProvider.deleteFile(filePath); |
| 697 return pumpEventQueue().then((_) { | 700 return pumpEventQueue().then((_) { |
| 701 expect(file.exists, isFalse); |
| 702 expect(projFolder.exists, isTrue); |
| 698 return expect(filePaths, hasLength(0)); | 703 return expect(filePaths, hasLength(0)); |
| 699 }); | 704 }); |
| 700 } | 705 } |
| 706 |
| 707 test_watch_deleteFolder() { |
| 708 String filePath = posix.join(projPath, 'foo.dart'); |
| 709 // add root with a file |
| 710 File file = resourceProvider.newFile(filePath, 'contents'); |
| 711 Folder projFolder = file.parent; |
| 712 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
| 713 // the file was added |
| 714 Map<String, int> filePaths = manager.currentContextFilePaths[projPath]; |
| 715 expect(filePaths, hasLength(1)); |
| 716 expect(filePaths, contains(filePath)); |
| 717 expect(file.exists, isTrue); |
| 718 expect(projFolder.exists, isTrue); |
| 719 // delete the folder |
| 720 resourceProvider.deleteFolder(projPath); |
| 721 return pumpEventQueue().then((_) { |
| 722 expect(file.exists, isFalse); |
| 723 expect(projFolder.exists, isFalse); |
| 724 return expect(filePaths, hasLength(0)); |
| 725 }); |
| 726 } |
| 701 | 727 |
| 702 test_watch_deletePubspec_fromRoot() { | 728 test_watch_deletePubspec_fromRoot() { |
| 703 // prepare paths | 729 // prepare paths |
| 704 String root = '/root'; | 730 String root = '/root'; |
| 705 String rootPubspec = '$root/pubspec.yaml'; | 731 String rootPubspec = '$root/pubspec.yaml'; |
| 706 String rootFile = '$root/root.dart'; | 732 String rootFile = '$root/root.dart'; |
| 707 // create files | 733 // create files |
| 708 resourceProvider.newFile(rootPubspec, 'pubspec'); | 734 resourceProvider.newFile(rootPubspec, 'pubspec'); |
| 709 resourceProvider.newFile(rootFile, 'library root;'); | 735 resourceProvider.newFile(rootFile, 'library root;'); |
| 710 // set roots | 736 // set roots |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 929 currentContextSources.remove(path); | 955 currentContextSources.remove(path); |
| 930 currentContextPackageUriResolvers.remove(path); | 956 currentContextPackageUriResolvers.remove(path); |
| 931 } | 957 } |
| 932 | 958 |
| 933 @override | 959 @override |
| 934 void updateContextPackageUriResolver(Folder contextFolder, | 960 void updateContextPackageUriResolver(Folder contextFolder, |
| 935 UriResolver packageUriResolver) { | 961 UriResolver packageUriResolver) { |
| 936 currentContextPackageUriResolvers[contextFolder.path] = packageUriResolver; | 962 currentContextPackageUriResolvers[contextFolder.path] = packageUriResolver; |
| 937 } | 963 } |
| 938 } | 964 } |
| OLD | NEW |