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 import 'dart:io' as io; | 8 import 'dart:io' as io; |
9 | 9 |
10 import 'package:analysis_server/src/context_manager.dart'; | 10 import 'package:analysis_server/src/context_manager.dart'; |
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 | 437 |
438 void test_setRoots_addFolderWithNestedPackageSpec() { | 438 void test_setRoots_addFolderWithNestedPackageSpec() { |
439 String examplePath = newFolder([projPath, ContextManagerTest.EXAMPLE_NAME]); | 439 String examplePath = newFolder([projPath, ContextManagerTest.EXAMPLE_NAME]); |
440 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]); | 440 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]); |
441 | 441 |
442 newFile([projPath, ContextManagerImpl.PACKAGE_SPEC_NAME]); | 442 newFile([projPath, ContextManagerImpl.PACKAGE_SPEC_NAME]); |
443 newFile([libPath, 'main.dart']); | 443 newFile([libPath, 'main.dart']); |
444 newFile([examplePath, ContextManagerImpl.PACKAGE_SPEC_NAME]); | 444 newFile([examplePath, ContextManagerImpl.PACKAGE_SPEC_NAME]); |
445 newFile([examplePath, 'example.dart']); | 445 newFile([examplePath, 'example.dart']); |
446 | 446 |
| 447 packageMapProvider.packageMap['proj'] = <Folder>[ |
| 448 resourceProvider.getResource(libPath) |
| 449 ]; |
| 450 |
447 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 451 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
448 | 452 |
449 expect(callbacks.currentContextPaths, hasLength(2)); | 453 expect(callbacks.currentContextPaths, hasLength(2)); |
450 | 454 |
451 expect(callbacks.currentContextPaths, contains(projPath)); | 455 expect(callbacks.currentContextPaths, contains(projPath)); |
452 Set<Source> projSources = callbacks.currentContextSources[projPath]; | 456 Set<Source> projSources = callbacks.currentContextSources[projPath]; |
453 expect(projSources, hasLength(1)); | 457 expect(projSources, hasLength(1)); |
454 expect(projSources.first.uri.toString(), 'file:///my/proj/lib/main.dart'); | 458 expect(projSources.first.uri.toString(), 'file:///my/proj/lib/main.dart'); |
455 | 459 |
456 expect(callbacks.currentContextPaths, contains(examplePath)); | 460 expect(callbacks.currentContextPaths, contains(examplePath)); |
(...skipping 23 matching lines...) Expand all Loading... |
480 expect(projSources.first.uri.toString(), 'package:proj/main.dart'); | 484 expect(projSources.first.uri.toString(), 'package:proj/main.dart'); |
481 | 485 |
482 expect(callbacks.currentContextPaths, contains(examplePath)); | 486 expect(callbacks.currentContextPaths, contains(examplePath)); |
483 Set<Source> exampleSources = callbacks.currentContextSources[examplePath]; | 487 Set<Source> exampleSources = callbacks.currentContextSources[examplePath]; |
484 expect(exampleSources, hasLength(1)); | 488 expect(exampleSources, hasLength(1)); |
485 expect(exampleSources.first.uri.toString(), | 489 expect(exampleSources.first.uri.toString(), |
486 'file:///my/proj/example/example.dart'); | 490 'file:///my/proj/example/example.dart'); |
487 } | 491 } |
488 | 492 |
489 void test_setRoots_addFolderWithoutPubspec() { | 493 void test_setRoots_addFolderWithoutPubspec() { |
| 494 packageMapProvider.packageMap = null; |
490 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 495 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
491 // verify | 496 // verify |
492 expect(callbacks.currentContextPaths, hasLength(1)); | 497 expect(callbacks.currentContextPaths, hasLength(1)); |
493 expect(callbacks.currentContextPaths, contains(projPath)); | 498 expect(callbacks.currentContextPaths, contains(projPath)); |
494 expect(callbacks.currentContextFilePaths[projPath], hasLength(0)); | 499 expect(callbacks.currentContextFilePaths[projPath], hasLength(0)); |
495 } | 500 } |
496 | 501 |
497 void test_setRoots_addFolderWithPackagespec() { | 502 void test_setRoots_addFolderWithPackagespec() { |
498 String packagespecPath = posix.join(projPath, '.packages'); | 503 String packagespecPath = posix.join(projPath, '.packages'); |
499 resourceProvider.newFile(packagespecPath, | 504 resourceProvider.newFile(packagespecPath, |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
970 String fileA = '$project/foo.dart'; | 975 String fileA = '$project/foo.dart'; |
971 String fileB = '$project/.pub/bar.dart'; | 976 String fileB = '$project/.pub/bar.dart'; |
972 resourceProvider.newFile(fileA, ''); | 977 resourceProvider.newFile(fileA, ''); |
973 resourceProvider.newFile(fileB, ''); | 978 resourceProvider.newFile(fileB, ''); |
974 manager.setRoots(<String>[project], <String>[], <String, String>{}); | 979 manager.setRoots(<String>[project], <String>[], <String, String>{}); |
975 callbacks.assertContextPaths([project]); | 980 callbacks.assertContextPaths([project]); |
976 callbacks.assertContextFiles(project, [fileA]); | 981 callbacks.assertContextFiles(project, [fileA]); |
977 } | 982 } |
978 | 983 |
979 void test_setRoots_removeFolderWithoutPubspec() { | 984 void test_setRoots_removeFolderWithoutPubspec() { |
| 985 packageMapProvider.packageMap = null; |
980 // add one root - there is a context | 986 // add one root - there is a context |
981 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 987 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
982 expect(callbacks.currentContextPaths, hasLength(1)); | 988 expect(callbacks.currentContextPaths, hasLength(1)); |
983 // set empty roots - no contexts | 989 // set empty roots - no contexts |
984 manager.setRoots(<String>[], <String>[], <String, String>{}); | 990 manager.setRoots(<String>[], <String>[], <String, String>{}); |
985 expect(callbacks.currentContextPaths, hasLength(0)); | 991 expect(callbacks.currentContextPaths, hasLength(0)); |
986 expect(callbacks.currentContextFilePaths, hasLength(0)); | 992 expect(callbacks.currentContextFilePaths, hasLength(0)); |
987 } | 993 } |
988 | 994 |
989 void test_setRoots_removeFolderWithPackagespec() { | 995 void test_setRoots_removeFolderWithPackagespec() { |
(...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1606 resourceProvider.modifyFile(filePath, 'new contents'); | 1612 resourceProvider.modifyFile(filePath, 'new contents'); |
1607 return pumpEventQueue().then((_) { | 1613 return pumpEventQueue().then((_) { |
1608 return expect(filePaths[filePath], equals(callbacks.now)); | 1614 return expect(filePaths[filePath], equals(callbacks.now)); |
1609 }); | 1615 }); |
1610 } | 1616 } |
1611 | 1617 |
1612 test_watch_modifyPackageMapDependency_fail() async { | 1618 test_watch_modifyPackageMapDependency_fail() async { |
1613 // create a dependency file | 1619 // create a dependency file |
1614 String dependencyPath = posix.join(projPath, 'dep'); | 1620 String dependencyPath = posix.join(projPath, 'dep'); |
1615 resourceProvider.newFile(dependencyPath, 'contents'); | 1621 resourceProvider.newFile(dependencyPath, 'contents'); |
| 1622 packageMapProvider.dependencies.add(dependencyPath); |
1616 // create a Dart file | 1623 // create a Dart file |
1617 String dartFilePath = posix.join(projPath, 'main.dart'); | 1624 String dartFilePath = posix.join(projPath, 'main.dart'); |
1618 resourceProvider.newFile(dartFilePath, 'contents'); | 1625 resourceProvider.newFile(dartFilePath, 'contents'); |
1619 // the created context has the expected empty package map | 1626 // the created context has the expected empty package map |
1620 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 1627 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
1621 expect(_currentPackageMap, isEmpty); | 1628 expect(_currentPackageMap, isEmpty); |
1622 // Change the package map dependency so that the packageMapProvider is | 1629 // Change the package map dependency so that the packageMapProvider is |
1623 // re-run, and arrange for it to return null from computePackageMap(). | 1630 // re-run, and arrange for it to return null from computePackageMap(). |
| 1631 packageMapProvider.packageMap = null; |
1624 resourceProvider.modifyFile(dependencyPath, 'new contents'); | 1632 resourceProvider.modifyFile(dependencyPath, 'new contents'); |
1625 await pumpEventQueue(); | 1633 await pumpEventQueue(); |
1626 // The package map should have been changed to null. | 1634 // The package map should have been changed to null. |
1627 expect(_currentPackageMap, isEmpty); | 1635 expect(_currentPackageMap, isEmpty); |
1628 } | 1636 } |
1629 | 1637 |
1630 test_watch_modifyPackagespec() { | 1638 test_watch_modifyPackagespec() { |
1631 String packagesPath = '$projPath/.packages'; | 1639 String packagesPath = '$projPath/.packages'; |
1632 String filePath = '$projPath/bin/main.dart'; | 1640 String filePath = '$projPath/bin/main.dart'; |
1633 | 1641 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1695 * The name of the 'test' directory. | 1703 * The name of the 'test' directory. |
1696 */ | 1704 */ |
1697 static const String TEST_NAME = 'test'; | 1705 static const String TEST_NAME = 'test'; |
1698 | 1706 |
1699 ContextManagerImpl manager; | 1707 ContextManagerImpl manager; |
1700 | 1708 |
1701 TestContextManagerCallbacks callbacks; | 1709 TestContextManagerCallbacks callbacks; |
1702 | 1710 |
1703 MemoryResourceProvider resourceProvider; | 1711 MemoryResourceProvider resourceProvider; |
1704 | 1712 |
| 1713 MockPackageMapProvider packageMapProvider; |
| 1714 |
1705 UriResolver packageResolver = null; | 1715 UriResolver packageResolver = null; |
1706 | 1716 |
1707 String projPath = '/my/proj'; | 1717 String projPath = '/my/proj'; |
1708 | 1718 |
1709 AnalysisError missing_required_param = new AnalysisError( | 1719 AnalysisError missing_required_param = new AnalysisError( |
1710 new TestSource(), 0, 1, HintCode.MISSING_REQUIRED_PARAM, [ | 1720 new TestSource(), 0, 1, HintCode.MISSING_REQUIRED_PARAM, [ |
1711 ['x'] | 1721 ['x'] |
1712 ]); | 1722 ]); |
1713 | 1723 |
1714 AnalysisError missing_return = | 1724 AnalysisError missing_return = |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1777 plugins.add(linterPlugin); | 1787 plugins.add(linterPlugin); |
1778 ExtensionManager manager = new ExtensionManager(); | 1788 ExtensionManager manager = new ExtensionManager(); |
1779 manager.processPlugins(plugins); | 1789 manager.processPlugins(plugins); |
1780 } | 1790 } |
1781 | 1791 |
1782 UriResolver providePackageResolver(Folder folder) => packageResolver; | 1792 UriResolver providePackageResolver(Folder folder) => packageResolver; |
1783 | 1793 |
1784 void setUp() { | 1794 void setUp() { |
1785 processRequiredPlugins(); | 1795 processRequiredPlugins(); |
1786 resourceProvider = new MemoryResourceProvider(); | 1796 resourceProvider = new MemoryResourceProvider(); |
| 1797 packageMapProvider = new MockPackageMapProvider(); |
1787 DartSdk sdk = new MockSdk(resourceProvider: resourceProvider); | 1798 DartSdk sdk = new MockSdk(resourceProvider: resourceProvider); |
1788 DartSdkManager sdkManager = new DartSdkManager('/', false, (_) => sdk); | 1799 DartSdkManager sdkManager = new DartSdkManager('/', false, (_) => sdk); |
1789 manager = new ContextManagerImpl( | 1800 manager = new ContextManagerImpl( |
1790 resourceProvider, | 1801 resourceProvider, |
1791 sdkManager, | 1802 sdkManager, |
1792 providePackageResolver, | 1803 providePackageResolver, |
| 1804 packageMapProvider, |
1793 analysisFilesGlobs, | 1805 analysisFilesGlobs, |
1794 InstrumentationService.NULL_SERVICE, | 1806 InstrumentationService.NULL_SERVICE, |
1795 new AnalysisOptionsImpl()); | 1807 new AnalysisOptionsImpl()); |
1796 callbacks = new TestContextManagerCallbacks(resourceProvider); | 1808 callbacks = new TestContextManagerCallbacks(resourceProvider); |
1797 manager.callbacks = callbacks; | 1809 manager.callbacks = callbacks; |
1798 resourceProvider.newFolder(projPath); | 1810 resourceProvider.newFolder(projPath); |
1799 } | 1811 } |
1800 | 1812 |
1801 /** | 1813 /** |
1802 * Verify that package URI's for source files in [path] will be resolved | 1814 * Verify that package URI's for source files in [path] will be resolved |
(...skipping 887 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2690 void assertContextFiles(String contextPath, List<String> expectedFiles) { | 2702 void assertContextFiles(String contextPath, List<String> expectedFiles) { |
2691 var actualFiles = currentContextFilePaths[contextPath].keys; | 2703 var actualFiles = currentContextFilePaths[contextPath].keys; |
2692 expect(actualFiles, unorderedEquals(expectedFiles)); | 2704 expect(actualFiles, unorderedEquals(expectedFiles)); |
2693 } | 2705 } |
2694 | 2706 |
2695 void assertContextPaths(List<String> expected) { | 2707 void assertContextPaths(List<String> expected) { |
2696 expect(currentContextPaths, unorderedEquals(expected)); | 2708 expect(currentContextPaths, unorderedEquals(expected)); |
2697 } | 2709 } |
2698 | 2710 |
2699 @override | 2711 @override |
| 2712 void computingPackageMap(bool computing) { |
| 2713 // Do nothing. |
| 2714 } |
| 2715 |
| 2716 @override |
2700 ContextBuilder createContextBuilder(Folder folder, AnalysisOptions options) { | 2717 ContextBuilder createContextBuilder(Folder folder, AnalysisOptions options) { |
2701 DartSdkManager sdkManager = new DartSdkManager('/', false, null); | 2718 DartSdkManager sdkManager = new DartSdkManager('/', false, null); |
2702 ContextBuilder builder = | 2719 ContextBuilder builder = |
2703 new ContextBuilder(resourceProvider, sdkManager, new ContentCache()); | 2720 new ContextBuilder(resourceProvider, sdkManager, new ContentCache()); |
2704 builder.defaultOptions = options; | 2721 builder.defaultOptions = options; |
2705 return builder; | 2722 return builder; |
2706 } | 2723 } |
2707 | 2724 |
2708 @override | 2725 @override |
2709 void moveContext(Folder from, Folder to) { | 2726 void moveContext(Folder from, Folder to) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2749 class TestUriResolver extends UriResolver { | 2766 class TestUriResolver extends UriResolver { |
2750 Map<Uri, Source> uriMap; | 2767 Map<Uri, Source> uriMap; |
2751 | 2768 |
2752 TestUriResolver(this.uriMap); | 2769 TestUriResolver(this.uriMap); |
2753 | 2770 |
2754 @override | 2771 @override |
2755 Source resolveAbsolute(Uri uri, [Uri actualUri]) { | 2772 Source resolveAbsolute(Uri uri, [Uri actualUri]) { |
2756 return uriMap[uri]; | 2773 return uriMap[uri]; |
2757 } | 2774 } |
2758 } | 2775 } |
OLD | NEW |