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

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

Issue 2949893002: Add support for running pub for plugins (Closed)
Patch Set: Created 3 years, 6 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
« no previous file with comments | « pkg/analysis_server/lib/src/plugin/plugin_manager.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 2fd7c361855ce5f9c71708753f9a9cd7a8c62ad4..6b748379b1890fc7dd0003e5538f6dd56c736c78 100644
--- a/pkg/analysis_server/test/src/plugin/plugin_manager_test.dart
+++ b/pkg/analysis_server/test/src/plugin/plugin_manager_test.dart
@@ -8,6 +8,7 @@ import 'dart:io' as io;
import 'package:analysis_server/src/plugin/notification_manager.dart';
import 'package:analysis_server/src/plugin/plugin_manager.dart';
import 'package:analyzer/context/context_root.dart';
+import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/file_system/memory_file_system.dart';
import 'package:analyzer/file_system/physical_file_system.dart';
import 'package:analyzer/instrumentation/instrumentation.dart';
@@ -211,6 +212,25 @@ class PluginManagerFromDiskTest extends PluginTestSupport {
pkg1Dir.deleteSync(recursive: true);
}
+ @failingTest
+ test_addPluginToContextRoot_pubspec() async {
+ // We can't successfully run pub until after the analyzer_plugin package has
+ // been published.
+ io.Directory pkg1Dir = io.Directory.systemTemp.createTempSync('pkg1');
+ String pkgPath = pkg1Dir.resolveSymbolicLinksSync();
+ await withPubspecPlugin(test: (String pluginPath) async {
+ ContextRoot contextRoot = new ContextRoot(pkgPath, []);
+ await manager.addPluginToContextRoot(contextRoot, pluginPath);
+ String packagesPath =
+ resourceProvider.pathContext.join(pluginPath, '.packages');
+ File packagesFile = resourceProvider.getFile(packagesPath);
+ bool exists = packagesFile.exists;
+ await manager.stopAll();
+ expect(exists, isTrue, reason: '.packages file was not created');
+ });
+ pkg1Dir.deleteSync(recursive: true);
+ }
+
test_broadcastRequest_many() async {
io.Directory pkg1Dir = io.Directory.systemTemp.createTempSync('pkg1');
String pkgPath = pkg1Dir.resolveSymbolicLinksSync();
@@ -579,6 +599,54 @@ abstract class PluginTestSupport {
}
/**
+ * Create a directory structure representing a plugin on disk, run the given
+ * [test] function, and then remove the directory. The directory will have the
+ * following structure:
+ * ```
+ * pluginDirectory
+ * pubspec.yaml
+ * bin
+ * plugin.dart
+ * ```
+ * The name of the plugin directory will be the [pluginName], if one is
+ * provided (in order to allow more than one plugin to be created by a single
+ * test). The 'plugin.dart' file will contain the given [content], or default
+ * content that implements a minimal plugin if the contents are not given. The
+ * [test] function will be passed the path of the directory that was created.
+ */
+ Future<Null> withPubspecPlugin(
+ {String content,
+ String pluginName,
+ Future<Null> test(String pluginPath)}) async {
+ io.Directory tempDirectory =
+ io.Directory.systemTemp.createTempSync(pluginName ?? 'test_plugin');
+ try {
+ String pluginPath = tempDirectory.resolveSymbolicLinksSync();
+ //
+ // Create a pubspec.yaml file.
+ //
+ io.File pubspecFile = new io.File(path.join(pluginPath, 'pubspec.yaml'));
+ pubspecFile.writeAsStringSync(_getPubspecFileContent());
+ //
+ // Create the 'bin' directory.
+ //
+ String binPath = path.join(pluginPath, 'bin');
+ new io.Directory(binPath).createSync();
+ //
+ // Create the 'plugin.dart' file.
+ //
+ io.File pluginFile = new io.File(path.join(binPath, 'plugin.dart'));
+ pluginFile.writeAsStringSync(content ?? _defaultPluginContent());
+ //
+ // Run the actual test code.
+ //
+ await test(pluginPath);
+ } finally {
+ tempDirectory.deleteSync(recursive: true);
+ }
+ }
+
+ /**
* Convert the [sdkPackageMap] into a plugin-specific map by applying the
* given relative path [delta] to each line.
*/
@@ -653,6 +721,18 @@ class MinimalPlugin extends ServerPlugin {
}
/**
+ * Return the content to be used for the 'pubspec.yaml' file.
+ */
+ String _getPubspecFileContent() {
+ return '''
+name: 'test'
+dependencies:
+ analyzer: any
+ analyzer_plugin: any
+''';
+ }
+
+ /**
* Return the path to the '.packages' file in the root of the SDK checkout.
*/
String _sdkPackagesPath() {
« no previous file with comments | « pkg/analysis_server/lib/src/plugin/plugin_manager.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698