Chromium Code Reviews| Index: pkg/analysis_server/test/src/plugin/plugin_manager_test.dart |
| diff --git a/pkg/analysis_server/test/src/plugin/plugin_manager_test.dart b/pkg/analysis_server/test/src/plugin/plugin_manager_test.dart |
| index fbd394257a60b2c6b7debb1edf84a9f092b3b6ae..b289fbc684b435070fe3f5c18ef2e23d0e1b8e40 100644 |
| --- a/pkg/analysis_server/test/src/plugin/plugin_manager_test.dart |
| +++ b/pkg/analysis_server/test/src/plugin/plugin_manager_test.dart |
| @@ -394,6 +394,86 @@ class PluginManagerTest { |
| expect(manager.notificationManager, notificationManager); |
| } |
| + void test_pathsFor_withPackagesFile() { |
| + path.Context context = resourceProvider.pathContext; |
| + // |
| + // Build the minimal directory structure for a plugin package that includes |
| + // a .packages file. |
| + // |
| + String pluginDirPath = resourceProvider.convertPath('/plugin'); |
| + resourceProvider.newFolder(pluginDirPath); |
| + String binPath = context.join(pluginDirPath, 'bin'); |
| + resourceProvider.newFolder(binPath); |
| + String pluginFilePath = context.join(binPath, 'plugin.dart'); |
| + resourceProvider.newFile(pluginFilePath, ''); |
|
scheglov
2017/07/24 15:35:34
MemoryResourceProvider.newFile() creates all enclo
Brian Wilkerson
2017/07/24 15:57:42
Done
|
| + String packagesFilePath = context.join(pluginDirPath, '.packages'); |
| + resourceProvider.newFile(packagesFilePath, ''); |
| + // |
| + // Test path computation. |
| + // |
| + List<String> paths = manager.pathsFor(pluginDirPath); |
| + expect(paths, hasLength(2)); |
| + expect(paths[0], pluginFilePath); |
| + expect(paths[1], packagesFilePath); |
| + } |
| + |
| + void test_pathsFor_withPubspec_inBazelWorkspace() { |
| + path.Context context = resourceProvider.pathContext; |
| + // |
| + // Build a Bazel workspace containing four packages, including the plugin. |
| + // |
| + String rootPath = resourceProvider.convertPath('/workspaceRoot'); |
| + resourceProvider.newFolder(rootPath); |
| + resourceProvider.newFile(context.join(rootPath, 'WORKSPACE'), ''); |
| + resourceProvider.newFolder(context.join(rootPath, 'bazel-bin')); |
| + resourceProvider.newFolder(context.join(rootPath, 'bazel-genfiles')); |
| + |
| + String newPackage(String packageName, [List<String> dependencies]) { |
| + String packageRoot = |
| + context.join(rootPath, 'third_party', 'dart', packageName); |
| + resourceProvider.newFile( |
| + context.join(packageRoot, 'lib', packageName + '.dart'), ''); |
| + StringBuffer buffer = new StringBuffer(); |
| + if (dependencies != null) { |
| + buffer.writeln('dependencies:'); |
| + for (String dependency in dependencies) { |
| + buffer.writeln(' $dependency: any'); |
| + } |
| + } |
| + resourceProvider.newFile( |
| + context.join(packageRoot, 'pubspec.yaml'), buffer.toString()); |
| + return packageRoot; |
| + } |
| + |
| + String pluginDirPath = newPackage('plugin', ['b', 'c']); |
| + newPackage('b', ['d']); |
| + newPackage('c', ['d']); |
| + newPackage('d'); |
| + String binPath = context.join(pluginDirPath, 'bin'); |
| + resourceProvider.newFolder(binPath); |
| + String pluginFilePath = context.join(binPath, 'plugin.dart'); |
| + resourceProvider.newFile(pluginFilePath, ''); |
| + // |
| + // Test path computation. |
| + // |
| + List<String> paths = manager.pathsFor(pluginDirPath); |
| + expect(paths, hasLength(2)); |
| + expect(paths[0], pluginFilePath); |
| + File packagesFile = resourceProvider.getFile(paths[1]); |
| + expect(packagesFile.exists, isTrue); |
| + String content = packagesFile.readAsStringSync(); |
| + List<String> lines = content.split('\n'); |
| + expect( |
| + lines, |
| + unorderedEquals([ |
| + 'plugin:file:///workspaceRoot/third_party/dart/plugin/lib', |
| + 'b:file:///workspaceRoot/third_party/dart/b/lib', |
| + 'c:file:///workspaceRoot/third_party/dart/c/lib', |
| + 'd:file:///workspaceRoot/third_party/dart/d/lib', |
| + '' |
| + ])); |
| + } |
| + |
| void test_pluginsForContextRoot_none() { |
| ContextRoot contextRoot = new ContextRoot('/pkg1', []); |
| expect(manager.pluginsForContextRoot(contextRoot), isEmpty); |