| Index: pkg/analyzer_plugin/test/plugin/plugin_test.dart
|
| diff --git a/pkg/analyzer_plugin/test/plugin/plugin_test.dart b/pkg/analyzer_plugin/test/plugin/plugin_test.dart
|
| index 193e3cff337987e874a788a89fbe8f14a777c4ee..c26eb82d900f5e6dbbc543daa3dacffc308d7624 100644
|
| --- a/pkg/analyzer_plugin/test/plugin/plugin_test.dart
|
| +++ b/pkg/analyzer_plugin/test/plugin/plugin_test.dart
|
| @@ -2,54 +2,28 @@
|
| // 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 'dart:async';
|
| -
|
| import 'package:analyzer/file_system/file_system.dart';
|
| import 'package:analyzer/file_system/memory_file_system.dart';
|
| import 'package:analyzer/src/dart/analysis/driver.dart';
|
| -import 'package:analyzer_plugin/plugin/plugin.dart';
|
| +import 'package:analyzer_plugin/protocol/protocol.dart';
|
| import 'package:analyzer_plugin/protocol/protocol_common.dart';
|
| import 'package:analyzer_plugin/protocol/protocol_generated.dart';
|
| import 'package:path/src/context.dart';
|
| import 'package:test/test.dart';
|
| import 'package:test_reflective_loader/test_reflective_loader.dart';
|
|
|
| +import 'mocks.dart';
|
| +
|
| void main() {
|
| defineReflectiveTests(ServerPluginTest);
|
| }
|
|
|
| -class MockAnalysisDriver extends AnalysisDriverGeneric {
|
| - /**
|
| - * The files that have been added to this driver.
|
| - */
|
| - List<String> addedFiles = <String>[];
|
| -
|
| - @override
|
| - bool get hasFilesToAnalyze => false;
|
| -
|
| - @override
|
| - set priorityFiles(List<String> priorityPaths) {}
|
| -
|
| - @override
|
| - AnalysisDriverPriority get workPriority => AnalysisDriverPriority.nothing;
|
| -
|
| - @override
|
| - void addFile(String path) {
|
| - addedFiles.add(path);
|
| - }
|
| -
|
| - @override
|
| - void dispose() {}
|
| -
|
| - @override
|
| - Future<Null> performWork() => new Future.value(null);
|
| -}
|
| -
|
| @reflectiveTest
|
| class ServerPluginTest {
|
| MemoryResourceProvider resourceProvider = new MemoryResourceProvider();
|
|
|
| - TestServerPlugin plugin;
|
| + MockChannel channel;
|
| + _TestServerPlugin plugin;
|
|
|
| String packagePath1;
|
| String filePath1;
|
| @@ -72,7 +46,9 @@ class ServerPluginTest {
|
| resourceProvider.newFile(filePath2, '');
|
| contextRoot2 = new ContextRoot(packagePath2, <String>[]);
|
|
|
| - plugin = new TestServerPlugin(resourceProvider);
|
| + channel = new MockChannel();
|
| + plugin = new _TestServerPlugin(resourceProvider);
|
| + plugin.start(channel);
|
| }
|
|
|
| test_contextRootContaining_insideRoot() async {
|
| @@ -136,7 +112,7 @@ class ServerPluginTest {
|
| var result = await plugin.handleAnalysisSetContextRoots(
|
| new AnalysisSetContextRootsParams([contextRoot1]));
|
| expect(result, isNotNull);
|
| - AnalysisDriverGeneric driver = plugin.driverMap[contextRoot1];
|
| + AnalysisDriverGeneric driver = _getDriver(contextRoot1);
|
| expect(driver, isNotNull);
|
| expect((driver as MockAnalysisDriver).addedFiles, hasLength(1));
|
| }
|
| @@ -164,7 +140,7 @@ class ServerPluginTest {
|
| [AnalysisService.OUTLINE]);
|
| }
|
|
|
| - test_handleAnalysisUpdateContent() async {
|
| + test_handleAnalysisUpdateContent_addChangeRemove() async {
|
| await plugin.handleAnalysisSetContextRoots(
|
| new AnalysisSetContextRootsParams([contextRoot1]));
|
| var addResult = await plugin.handleAnalysisUpdateContent(
|
| @@ -183,6 +159,36 @@ class ServerPluginTest {
|
| expect(removeResult, isNotNull);
|
| }
|
|
|
| + test_handleAnalysisUpdateContent_changeNoAdd() async {
|
| + await plugin.handleAnalysisSetContextRoots(
|
| + new AnalysisSetContextRootsParams([contextRoot1]));
|
| + try {
|
| + await plugin.handleAnalysisUpdateContent(new AnalysisUpdateContentParams({
|
| + filePath1:
|
| + new ChangeContentOverlay([new SourceEdit(7, 0, ' extends Object')])
|
| + }));
|
| + fail('Expected RequestFailure');
|
| + } on RequestFailure {
|
| + // Expected
|
| + }
|
| + }
|
| +
|
| + test_handleAnalysisUpdateContent_invalidChange() async {
|
| + await plugin.handleAnalysisSetContextRoots(
|
| + new AnalysisSetContextRootsParams([contextRoot1]));
|
| + await plugin.handleAnalysisUpdateContent(new AnalysisUpdateContentParams(
|
| + {filePath1: new AddContentOverlay('class C {}')}));
|
| + try {
|
| + await plugin.handleAnalysisUpdateContent(new AnalysisUpdateContentParams({
|
| + filePath1:
|
| + new ChangeContentOverlay([new SourceEdit(20, 5, 'class D {}')])
|
| + }));
|
| + fail('Expected RequestFailure');
|
| + } on RequestFailure {
|
| + // Expected
|
| + }
|
| + }
|
| +
|
| test_handleCompletionGetSuggestions() async {
|
| await plugin.handleAnalysisSetContextRoots(
|
| new AnalysisSetContextRootsParams([contextRoot1]));
|
| @@ -252,44 +258,177 @@ class ServerPluginTest {
|
| fail('Not yet implemented.');
|
| }
|
|
|
| - @failingTest
|
| void test_onDone() {
|
| - fail('Not yet implemented.');
|
| + channel.sendDone();
|
| }
|
|
|
| - @failingTest
|
| void test_onError() {
|
| - fail('Not yet implemented.');
|
| + channel.sendError(new ArgumentError(), new StackTrace.fromString(''));
|
| }
|
|
|
| - @failingTest
|
| - void test_start() {
|
| - fail('Not yet implemented.');
|
| + test_onRequest_analysisGetNavigation() async {
|
| + var result =
|
| + await channel.sendRequest(new AnalysisGetNavigationParams('', 1, 2));
|
| + expect(result, isNotNull);
|
| }
|
| -}
|
|
|
| -/**
|
| - * A concrete implementation of a server plugin that is suitable for testing.
|
| - */
|
| -class TestServerPlugin extends ServerPlugin {
|
| - Map<String, List<AnalysisService>> latestSubscriptions;
|
| + test_onRequest_analysisHandleWatchEvents() async {
|
| + var result =
|
| + await channel.sendRequest(new AnalysisHandleWatchEventsParams([]));
|
| + expect(result, isNotNull);
|
| + }
|
|
|
| - TestServerPlugin(ResourceProvider resourceProvider) : super(resourceProvider);
|
| + test_onRequest_analysisReanalyze_all() async {
|
| + await channel
|
| + .sendRequest(new AnalysisSetContextRootsParams([contextRoot1]));
|
| + var result = await channel.sendRequest(new AnalysisReanalyzeParams());
|
| + expect(result, isNotNull);
|
| + }
|
|
|
| - @override
|
| - List<String> get fileGlobsToAnalyze => <String>['*.dart'];
|
| + test_onRequest_analysisReanalyze_subset() async {
|
| + await channel
|
| + .sendRequest(new AnalysisSetContextRootsParams([contextRoot1]));
|
| + await channel
|
| + .sendRequest(new AnalysisSetContextRootsParams([contextRoot2]));
|
| + var result = await channel
|
| + .sendRequest(new AnalysisReanalyzeParams(roots: [packagePath2]));
|
| + expect(result, isNotNull);
|
| + }
|
|
|
| - @override
|
| - String get name => 'Test Plugin';
|
| + test_onRequest_analysisSetContextBuilderOptions() async {
|
| + var result = await channel.sendRequest(
|
| + new AnalysisSetContextBuilderOptionsParams(
|
| + new ContextBuilderOptions()));
|
| + expect(result, isNotNull);
|
| + }
|
|
|
| - @override
|
| - String get version => '0.1.0';
|
| + test_onRequest_analysisSetContextRoots() async {
|
| + var result = await channel
|
| + .sendRequest(new AnalysisSetContextRootsParams([contextRoot1]));
|
| + expect(result, isNotNull);
|
| + AnalysisDriverGeneric driver = _getDriver(contextRoot1);
|
| + expect(driver, isNotNull);
|
| + expect((driver as MockAnalysisDriver).addedFiles, hasLength(1));
|
| + }
|
|
|
| - @override
|
| - AnalysisDriverGeneric createAnalysisDriver(ContextRoot contextRoot) {
|
| - return new MockAnalysisDriver();
|
| + test_onRequest_analysisSetPriorityFiles() async {
|
| + await channel
|
| + .sendRequest(new AnalysisSetContextRootsParams([contextRoot1]));
|
| +
|
| + var result = await channel
|
| + .sendRequest(new AnalysisSetPriorityFilesParams([filePath1]));
|
| + expect(result, isNotNull);
|
| }
|
|
|
| + test_onRequest_analysisSetSubscriptions() async {
|
| + await channel
|
| + .sendRequest(new AnalysisSetContextRootsParams([contextRoot1]));
|
| + expect(plugin.subscriptionManager.servicesForFile(filePath1), isEmpty);
|
| +
|
| + var result = await channel.sendRequest(new AnalysisSetSubscriptionsParams({
|
| + AnalysisService.OUTLINE: [filePath1]
|
| + }));
|
| + expect(result, isNotNull);
|
| + expect(plugin.subscriptionManager.servicesForFile(filePath1),
|
| + [AnalysisService.OUTLINE]);
|
| + }
|
| +
|
| + test_onRequest_analysisUpdateContent_addChangeRemove() async {
|
| + await channel
|
| + .sendRequest(new AnalysisSetContextRootsParams([contextRoot1]));
|
| + var addResult = await channel.sendRequest(new AnalysisUpdateContentParams(
|
| + {filePath1: new AddContentOverlay('class C {}')}));
|
| + expect(addResult, isNotNull);
|
| + var changeResult =
|
| + await channel.sendRequest(new AnalysisUpdateContentParams({
|
| + filePath1:
|
| + new ChangeContentOverlay([new SourceEdit(7, 0, ' extends Object')])
|
| + }));
|
| + expect(changeResult, isNotNull);
|
| + var removeResult = await channel.sendRequest(
|
| + new AnalysisUpdateContentParams(
|
| + {filePath1: new RemoveContentOverlay()}));
|
| + expect(removeResult, isNotNull);
|
| + }
|
| +
|
| + test_onRequest_completionGetSuggestions() async {
|
| + await channel
|
| + .sendRequest(new AnalysisSetContextRootsParams([contextRoot1]));
|
| +
|
| + var result = await channel
|
| + .sendRequest(new CompletionGetSuggestionsParams(filePath1, 12));
|
| + expect(result, isNotNull);
|
| + }
|
| +
|
| + test_onRequest_editGetAssists() async {
|
| + await channel
|
| + .sendRequest(new AnalysisSetContextRootsParams([contextRoot1]));
|
| +
|
| + var result =
|
| + await channel.sendRequest(new EditGetAssistsParams(filePath1, 10, 0));
|
| + expect(result, isNotNull);
|
| + }
|
| +
|
| + test_onRequest_editGetAvailableRefactorings() async {
|
| + await channel
|
| + .sendRequest(new AnalysisSetContextRootsParams([contextRoot1]));
|
| +
|
| + var result = await channel
|
| + .sendRequest(new EditGetAvailableRefactoringsParams(filePath1, 10, 0));
|
| + expect(result, isNotNull);
|
| + }
|
| +
|
| + test_onRequest_editGetFixes() async {
|
| + await channel
|
| + .sendRequest(new AnalysisSetContextRootsParams([contextRoot1]));
|
| +
|
| + var result =
|
| + await channel.sendRequest(new EditGetFixesParams(filePath1, 13));
|
| + expect(result, isNotNull);
|
| + }
|
| +
|
| + test_onRequest_editGetRefactoring() async {
|
| + await channel
|
| + .sendRequest(new AnalysisSetContextRootsParams([contextRoot1]));
|
| +
|
| + var result = await channel.sendRequest(new EditGetRefactoringParams(
|
| + RefactoringKind.RENAME, filePath1, 7, 0, false));
|
| + expect(result, isNotNull);
|
| + }
|
| +
|
| + test_onRequest_pluginShutdown() async {
|
| + var result = await channel.sendRequest(new PluginShutdownParams());
|
| + expect(result, isNotNull);
|
| + }
|
| +
|
| + test_onRequest_pluginVersionCheck() async {
|
| + var response = (await channel.sendRequest(
|
| + new PluginVersionCheckParams('byteStorePath', 'sdkPath', '0.1.0')));
|
| + PluginVersionCheckResult result =
|
| + new PluginVersionCheckResult.fromResponse(response);
|
| + expect(result, isNotNull);
|
| + expect(result.interestingFiles, ['*.dart']);
|
| + expect(result.isCompatible, isTrue);
|
| + expect(result.name, 'Test Plugin');
|
| + expect(result.version, '0.1.0');
|
| + }
|
| +
|
| + AnalysisDriverGeneric _getDriver(ContextRoot targetRoot) {
|
| + for (ContextRoot root in plugin.driverMap.keys) {
|
| + if (root.root == targetRoot.root) {
|
| + return plugin.driverMap[root];
|
| + }
|
| + }
|
| + return null;
|
| + }
|
| +}
|
| +
|
| +class _TestServerPlugin extends MockServerPlugin {
|
| + Map<String, List<AnalysisService>> latestSubscriptions;
|
| +
|
| + _TestServerPlugin(ResourceProvider resourceProvider)
|
| + : super(resourceProvider);
|
| +
|
| @override
|
| void sendNotificationsForSubscriptions(
|
| Map<String, List<AnalysisService>> subscriptions) {
|
|
|