Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1132)

Unified Diff: pkg/analysis_server/test/src/plugin/plugin_locator_test.dart

Issue 2671773007: Add code to locate a plugin within a package (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/analysis_server/test/src/plugin/plugin_locator_test.dart
diff --git a/pkg/analysis_server/test/src/plugin/plugin_locator_test.dart b/pkg/analysis_server/test/src/plugin/plugin_locator_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..956987cc473e14adb4474ad04a5a34a2e84f4944
--- /dev/null
+++ b/pkg/analysis_server/test/src/plugin/plugin_locator_test.dart
@@ -0,0 +1,90 @@
+// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'package:analysis_server/src/plugin/plugin_locator.dart';
+import 'package:analyzer/file_system/memory_file_system.dart';
+import 'package:test/test.dart';
+import 'package:test_reflective_loader/test_reflective_loader.dart';
+
+main() {
+ defineReflectiveSuite(() {
+ defineReflectiveTests(PluginLocatorTest);
+ });
+}
+
+@reflectiveTest
+class PluginLocatorTest {
+ MemoryResourceProvider resourceProvider;
+ String packageRoot;
+ String pubspecPath;
+ String defaultDirPath;
+ PluginLocator locator;
+
+ void setUp() {
+ resourceProvider = new MemoryResourceProvider();
+ packageRoot = resourceProvider.convertPath('/package');
+ resourceProvider.newFolder(packageRoot);
+ locator = new PluginLocator(resourceProvider);
+ }
+
+ void test_findPlugin_inPubspec_defaultDir() {
+ String dirPath = _createPubspecWithKey();
+ _createDefaultDir();
+ expect(locator.findPlugin(packageRoot), dirPath);
+ }
+
+ void test_findPlugin_inPubspec_noDefaultDir() {
+ String dirPath = _createPubspecWithKey();
+ expect(locator.findPlugin(packageRoot), dirPath);
+ }
+
+ void test_findPlugin_noPubspec_defaultDir() {
+ _createDefaultDir();
+ expect(locator.findPlugin(packageRoot), defaultDirPath);
+ }
+
+ void test_findPlugin_noPubspec_noDefaultDir() {
+ expect(locator.findPlugin(packageRoot), isNull);
+ }
+
+ void test_findPlugin_notInPubspec_defaultDir() {
+ _createPubspecWithoutKey();
+ _createDefaultDir();
+ expect(locator.findPlugin(packageRoot), defaultDirPath);
+ }
+
+ void test_findPlugin_notInPubspec_noDefaultDir() {
+ _createPubspecWithoutKey();
+ expect(locator.findPlugin(packageRoot), isNull);
+ }
+
+ void _createDefaultDir() {
+ defaultDirPath = resourceProvider.pathContext.join(packageRoot,
+ PluginLocator.toolsFolderName, PluginLocator.defaultPluginFolderName);
+ resourceProvider.newFolder(defaultDirPath);
+ }
+
+ void _createPubspec(String content) {
+ pubspecPath = resourceProvider.pathContext
+ .join(packageRoot, PluginLocator.pubspecFileName);
+ resourceProvider.newFile(pubspecPath, content);
+ }
+
+ String _createPubspecWithKey() {
+ String nonDefaultPath =
+ resourceProvider.pathContext.join(packageRoot, 'pluginDir');
+ _createPubspec('''
+name: test_project
+${PluginLocator.analysisPluginKey}: $nonDefaultPath
+''');
+ resourceProvider.newFolder(nonDefaultPath);
+ return nonDefaultPath;
+ }
+
+ void _createPubspecWithoutKey() {
+ _createPubspec('''
+name: test_project
+''');
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698