| Index: pkg/analysis_server/test/domain_analysis_test.dart
|
| diff --git a/pkg/analysis_server/test/domain_analysis_test.dart b/pkg/analysis_server/test/domain_analysis_test.dart
|
| index d13a5a02442997884a18621d9aacab87c1207d68..a41e086a25d9098d89d1d3999a4c03e875aad4ee 100644
|
| --- a/pkg/analysis_server/test/domain_analysis_test.dart
|
| +++ b/pkg/analysis_server/test/domain_analysis_test.dart
|
| @@ -24,6 +24,7 @@ main() {
|
| groupSep = ' | ';
|
|
|
| runReflectiveTests(AnalysisDomainTest);
|
| + runReflectiveTests(SetSubscriptionsTest);
|
|
|
| MockServerChannel serverChannel;
|
| MemoryResourceProvider resourceProvider;
|
| @@ -40,7 +41,6 @@ main() {
|
| });
|
|
|
| group('updateContent', testUpdateContent);
|
| - group('setSubscriptions', test_setSubscriptions);
|
|
|
| group('AnalysisDomainHandler', () {
|
| group('setAnalysisRoots', () {
|
| @@ -144,69 +144,6 @@ main() {
|
| });
|
| }
|
|
|
| -void test_setSubscriptions() {
|
| - test('before analysis', () {
|
| - AnalysisTestHelper helper = new AnalysisTestHelper();
|
| - // subscribe
|
| - helper.addAnalysisSubscriptionHighlights(helper.testFile);
|
| - // create project
|
| - helper.createSingleFileProject('int V = 42;');
|
| - // wait, there are highlight regions
|
| - helper.onAnalysisComplete.then((_) {
|
| - var highlights = helper.getHighlights(helper.testFile);
|
| - expect(highlights, isNotEmpty);
|
| - });
|
| - });
|
| -
|
| - test('after analysis', () {
|
| - AnalysisTestHelper helper = new AnalysisTestHelper();
|
| - // create project
|
| - helper.createSingleFileProject('int V = 42;');
|
| - // wait, no regions initially
|
| - return helper.onAnalysisComplete.then((_) {
|
| - var highlights = helper.getHighlights(helper.testFile);
|
| - expect(highlights, isEmpty);
|
| - // subscribe
|
| - helper.addAnalysisSubscriptionHighlights(helper.testFile);
|
| - // wait, has regions
|
| - return helper.onAnalysisComplete.then((_) {
|
| - var highlights = helper.getHighlights(helper.testFile);
|
| - expect(highlights, isNotEmpty);
|
| - });
|
| - });
|
| - });
|
| -
|
| - test('after analysis, no such file', () {
|
| - AnalysisTestHelper helper = new AnalysisTestHelper();
|
| - helper.createSingleFileProject('int V = 42;');
|
| - return helper.onAnalysisComplete.then((_) {
|
| - String noFile = '/no-such-file.dart';
|
| - helper.addAnalysisSubscriptionHighlights(noFile);
|
| - return helper.onAnalysisComplete.then((_) {
|
| - var highlights = helper.getHighlights(noFile);
|
| - expect(highlights, isEmpty);
|
| - });
|
| - });
|
| - });
|
| -
|
| - test('after analysis, SDK file', () {
|
| - AnalysisTestHelper helper = new AnalysisTestHelper();
|
| - helper.createSingleFileProject('''
|
| -main() {
|
| - print(42);
|
| -}
|
| -''');
|
| - return helper.onAnalysisComplete.then((_) {
|
| - String file = '/lib/core/core.dart';
|
| - helper.addAnalysisSubscriptionNavigation(file);
|
| - return helper.onAnalysisComplete.then((_) {
|
| - var navigationRegions = helper.getNavigation(file);
|
| - expect(navigationRegions, isNotEmpty);
|
| - });
|
| - });
|
| - });
|
| -}
|
| -
|
| testUpdateContent() {
|
| test('bad type', () {
|
| AnalysisTestHelper helper = new AnalysisTestHelper();
|
| @@ -607,3 +544,130 @@ class AnalysisTestHelper {
|
| return code as String;
|
| }
|
| }
|
| +
|
| +@reflectiveTest
|
| +class SetSubscriptionsTest extends AbstractAnalysisTest {
|
| + Map<String, List<HighlightRegion>> filesHighlights = {};
|
| +
|
| + void processNotification(Notification notification) {
|
| + if (notification.event == ANALYSIS_HIGHLIGHTS) {
|
| + var params = new AnalysisHighlightsParams.fromNotification(notification);
|
| + filesHighlights[params.file] = params.regions;
|
| + }
|
| + }
|
| +
|
| + test_afterAnalysis() async {
|
| + addTestFile('int V = 42;');
|
| + createProject();
|
| + // wait for analysis, no results initially
|
| + await waitForTasksFinished();
|
| + expect(filesHighlights[testFile], isNull);
|
| + // subscribe
|
| + addAnalysisSubscription(AnalysisService.HIGHLIGHTS, testFile);
|
| + await server.onAnalysisComplete;
|
| + // there are results
|
| + expect(filesHighlights[testFile], isNotEmpty);
|
| + }
|
| +
|
| + test_afterAnalysis_noSuchFile() async {
|
| + String file = '/no-such-file.dart';
|
| + addTestFile('// no matter');
|
| + createProject();
|
| + // wait for analysis, no results initially
|
| + await waitForTasksFinished();
|
| + expect(filesHighlights[testFile], isNull);
|
| + // subscribe
|
| + addAnalysisSubscription(AnalysisService.HIGHLIGHTS, file);
|
| + await server.onAnalysisComplete;
|
| + // there are results
|
| + expect(filesHighlights[file], isNull);
|
| + }
|
| +
|
| + test_afterAnalysis_packageFile_external() async {
|
| + String pkgFile = '/packages/pkgA/lib/libA.dart';
|
| + resourceProvider.newFile(pkgFile, '''
|
| +library lib_a;
|
| +class A {}
|
| +''');
|
| + packageMapProvider.packageMap = {
|
| + 'pkgA': [(resourceProvider.newFolder('/packages/pkgA/lib'))]
|
| + };
|
| + //
|
| + addTestFile('''
|
| +import 'package:pkgA/libA.dart';
|
| +main() {
|
| + new A();
|
| +}
|
| +''');
|
| + createProject();
|
| + // wait for analysis, no results initially
|
| + await waitForTasksFinished();
|
| + expect(filesHighlights[pkgFile], isNull);
|
| + // subscribe
|
| + addAnalysisSubscription(AnalysisService.HIGHLIGHTS, pkgFile);
|
| + await server.onAnalysisComplete;
|
| + // there are results
|
| + expect(filesHighlights[pkgFile], isNotEmpty);
|
| + }
|
| +
|
| + test_afterAnalysis_packageFile_inRoot() async {
|
| + String pkgA = '/pkgA';
|
| + String pkgB = '/pkgA';
|
| + String pkgFileA = '$pkgA/lib/libA.dart';
|
| + String pkgFileB = '$pkgA/lib/libB.dart';
|
| + resourceProvider.newFile(pkgFileA, '''
|
| +library lib_a;
|
| +class A {}
|
| +''');
|
| + resourceProvider.newFile(pkgFileB, '''
|
| +import 'package:pkgA/libA.dart';
|
| +main() {
|
| + new A();
|
| +}
|
| +''');
|
| + packageMapProvider.packageMap = {
|
| + 'pkgA': [
|
| + resourceProvider.newFolder('$pkgA/lib'),
|
| + resourceProvider.newFolder('$pkgB/lib')
|
| + ]
|
| + };
|
| + // add 'pkgA' and 'pkgB' as projects
|
| + {
|
| + resourceProvider.newFolder(projectPath);
|
| + handleSuccessfulRequest(
|
| + new AnalysisSetAnalysisRootsParams([pkgA, pkgB], []).toRequest('0'));
|
| + }
|
| + // wait for analysis, no results initially
|
| + await waitForTasksFinished();
|
| + expect(filesHighlights[pkgFileA], isNull);
|
| + // subscribe
|
| + addAnalysisSubscription(AnalysisService.HIGHLIGHTS, pkgFileA);
|
| + await server.onAnalysisComplete;
|
| + // there are results
|
| + expect(filesHighlights[pkgFileA], isNotEmpty);
|
| + }
|
| +
|
| + test_afterAnalysis_sdkFile() async {
|
| + String file = '/lib/core/core.dart';
|
| + addTestFile('// no matter');
|
| + createProject();
|
| + // wait for analysis, no results initially
|
| + await waitForTasksFinished();
|
| + expect(filesHighlights[file], isNull);
|
| + // subscribe
|
| + addAnalysisSubscription(AnalysisService.HIGHLIGHTS, file);
|
| + await server.onAnalysisComplete;
|
| + // there are results
|
| + expect(filesHighlights[file], isNotEmpty);
|
| + }
|
| +
|
| + test_beforeAnalysis() async {
|
| + addTestFile('int V = 42;');
|
| + createProject();
|
| + // subscribe
|
| + addAnalysisSubscription(AnalysisService.HIGHLIGHTS, testFile);
|
| + // wait for analysis
|
| + await waitForTasksFinished();
|
| + expect(filesHighlights[testFile], isNotEmpty);
|
| + }
|
| +}
|
|
|