| 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 d4df03b34dba4edca51998c29914b7561f701820..f9ee43c93f31b64520b751b0bda2f16fae9ab959 100644
|
| --- a/pkg/analysis_server/test/domain_analysis_test.dart
|
| +++ b/pkg/analysis_server/test/domain_analysis_test.dart
|
| @@ -6,19 +6,30 @@ library test.domain.analysis;
|
|
|
| import 'dart:async';
|
|
|
| -import 'package:analyzer/file_system/memory_file_system.dart';
|
| import 'package:analysis_server/src/analysis_server.dart';
|
| import 'package:analysis_server/src/computer/element.dart';
|
| import 'package:analysis_server/src/constants.dart';
|
| import 'package:analysis_server/src/domain_analysis.dart';
|
| import 'package:analysis_server/src/protocol.dart';
|
| +import 'package:analysis_testing/mock_sdk.dart';
|
| +import 'package:analysis_testing/reflective_tests.dart';
|
| +import 'package:analyzer/file_system/memory_file_system.dart';
|
| import 'package:analyzer/src/generated/engine.dart';
|
| import 'package:path/path.dart';
|
| import 'package:unittest/unittest.dart';
|
|
|
| -import 'mocks.dart';
|
| import 'analysis_abstract.dart';
|
| -import 'reflective_tests.dart';
|
| +import 'mocks.dart';
|
| +
|
| +
|
| +AnalysisError jsonToAnalysisError(Map<String, Object> json) {
|
| + Map<String, Object> jsonLocation = json[LOCATION];
|
| + Location location = new Location(jsonLocation[FILE], _getSafeInt(jsonLocation,
|
| + OFFSET, -1), _getSafeInt(jsonLocation, LENGTH, -1), _getSafeInt(jsonLocation,
|
| + START_LINE, -1), _getSafeInt(jsonLocation, START_COLUMN, -1));
|
| + return new AnalysisError(json[ERROR_CODE], json[SEVERITY], json[TYPE], location,
|
| + json['message'], json['correction']);
|
| +}
|
|
|
|
|
| main() {
|
| @@ -157,31 +168,163 @@ main() {
|
| }
|
|
|
|
|
| -class AnalysisError {
|
| - final String errorCode;
|
| - final String severity;
|
| - final String type;
|
| - final Location location;
|
| - final String message;
|
| - final String correction;
|
| - AnalysisError(this.errorCode, this.severity, this.type, this.location,
|
| - this.message, this.correction);
|
| +testNotificationErrors() {
|
| + AnalysisTestHelper helper;
|
|
|
| - @override
|
| - String toString() {
|
| - return 'AnalysisError(location=$location message=$message); '
|
| - 'errorCode=$errorCode; severity=$separator type=$type';
|
| - }
|
| + setUp(() {
|
| + helper = new AnalysisTestHelper();
|
| + });
|
| +
|
| + test('ParserErrorCode', () {
|
| + helper.createSingleFileProject('library lib');
|
| + return helper.waitForOperationsFinished().then((_) {
|
| + List<AnalysisError> errors = helper.getTestErrors();
|
| + expect(errors, hasLength(1));
|
| + AnalysisError error = errors[0];
|
| + expect(error.location.file, '/project/bin/test.dart');
|
| + expect(error.location.offset, isPositive);
|
| + expect(error.location.length, isNonNegative);
|
| + expect(error.errorCode, 'ParserErrorCode.EXPECTED_TOKEN');
|
| + expect(error.severity, 'ERROR');
|
| + expect(error.type, 'SYNTACTIC_ERROR');
|
| + expect(error.message, isNotNull);
|
| + });
|
| + });
|
| +
|
| + test('StaticWarningCode', () {
|
| + helper.createSingleFileProject(['main() {', ' print(unknown);', '}']);
|
| + return helper.waitForOperationsFinished().then((_) {
|
| + List<AnalysisError> errors = helper.getTestErrors();
|
| + expect(errors, hasLength(1));
|
| + AnalysisError error = errors[0];
|
| + expect(error.errorCode, 'StaticWarningCode.UNDEFINED_IDENTIFIER');
|
| + });
|
| + });
|
| }
|
|
|
|
|
| -AnalysisError jsonToAnalysisError(Map<String, Object> json) {
|
| - Map<String, Object> jsonLocation = json[LOCATION];
|
| - Location location = new Location(jsonLocation[FILE], _getSafeInt(jsonLocation,
|
| - OFFSET, -1), _getSafeInt(jsonLocation, LENGTH, -1), _getSafeInt(jsonLocation,
|
| - START_LINE, -1), _getSafeInt(jsonLocation, START_COLUMN, -1));
|
| - return new AnalysisError(json[ERROR_CODE], json[SEVERITY], json[TYPE], location,
|
| - json['message'], json['correction']);
|
| +testUpdateContent() {
|
| + test('full content', () {
|
| + AnalysisTestHelper helper = new AnalysisTestHelper();
|
| + helper.createSingleFileProject('// empty');
|
| + return helper.waitForOperationsFinished().then((_) {
|
| + // no errors initially
|
| + List<AnalysisError> errors = helper.getTestErrors();
|
| + expect(errors, isEmpty);
|
| + // update code
|
| + helper.sendContentChange({
|
| + CONTENT: 'library lib'
|
| + });
|
| + // wait, there is an error
|
| + return helper.waitForOperationsFinished().then((_) {
|
| + List<AnalysisError> errors = helper.getTestErrors();
|
| + expect(errors, hasLength(1));
|
| + });
|
| + });
|
| + });
|
| +
|
| + test('incremental', () {
|
| + AnalysisTestHelper helper = new AnalysisTestHelper();
|
| + helper.createSingleFileProject('library A;');
|
| + return helper.waitForOperationsFinished().then((_) {
|
| + // no errors initially
|
| + List<AnalysisError> errors = helper.getTestErrors();
|
| + expect(errors, isEmpty);
|
| + // update code
|
| + helper.sendContentChange({
|
| + CONTENT: 'library lib',
|
| + OFFSET: 'library '.length,
|
| + OLD_LENGTH: 'A;'.length,
|
| + NEW_LENGTH: 'lib'.length,
|
| + });
|
| + // wait, there is an error
|
| + return helper.waitForOperationsFinished().then((_) {
|
| + List<AnalysisError> errors = helper.getTestErrors();
|
| + expect(errors, hasLength(1));
|
| + });
|
| + });
|
| + });
|
| +
|
| + test('change on disk, normal', () {
|
| + AnalysisTestHelper helper = new AnalysisTestHelper();
|
| + helper.createSingleFileProject('library A;');
|
| + return helper.waitForOperationsFinished().then((_) {
|
| + // There should be no errors
|
| + expect(helper.getTestErrors(), hasLength(0));
|
| + // Change file on disk, adding a syntax error.
|
| + helper.resourceProvider.modifyFile(helper.testFile, 'library lib');
|
| + // There should be errors now.
|
| + return pumpEventQueue().then((_) {
|
| + return helper.waitForOperationsFinished().then((_) {
|
| + expect(helper.getTestErrors(), hasLength(1));
|
| + });
|
| + });
|
| + });
|
| + });
|
| +
|
| + test('change on disk, during override', () {
|
| + AnalysisTestHelper helper = new AnalysisTestHelper();
|
| + helper.createSingleFileProject('library A;');
|
| + return helper.waitForOperationsFinished().then((_) {
|
| + // update code
|
| + helper.sendContentChange({
|
| + CONTENT: 'library B;'
|
| + });
|
| + // There should be no errors
|
| + return helper.waitForOperationsFinished().then((_) {
|
| + expect(helper.getTestErrors(), hasLength(0));
|
| + // Change file on disk, adding a syntax error.
|
| + helper.resourceProvider.modifyFile(helper.testFile, 'library lib');
|
| + // There should still be no errors (file should not have been reread).
|
| + return helper.waitForOperationsFinished().then((_) {
|
| + expect(helper.getTestErrors(), hasLength(0));
|
| + // Send a content change with a null content param--file should be
|
| + // reread from disk.
|
| + helper.sendContentChange({
|
| + CONTENT: null
|
| + });
|
| + // There should be errors now.
|
| + return helper.waitForOperationsFinished().then((_) {
|
| + expect(helper.getTestErrors(), hasLength(1));
|
| + });
|
| + });
|
| + });
|
| + });
|
| + });
|
| +}
|
| +
|
| +
|
| +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.waitForOperationsFinished().then((_) {
|
| + var highlights = helper.getHighlights(helper.testFile);
|
| + expect(highlights, isNot(isEmpty));
|
| + });
|
| + });
|
| +
|
| + test('after analysis', () {
|
| + AnalysisTestHelper helper = new AnalysisTestHelper();
|
| + // create project
|
| + helper.createSingleFileProject('int V = 42;');
|
| + // wait, no regions initially
|
| + return helper.waitForOperationsFinished().then((_) {
|
| + var highlights = helper.getHighlights(helper.testFile);
|
| + expect(highlights, isEmpty);
|
| + // subscribe
|
| + helper.addAnalysisSubscriptionHighlights(helper.testFile);
|
| + // wait, has regions
|
| + return helper.waitForOperationsFinished().then((_) {
|
| + var highlights = helper.getHighlights(helper.testFile);
|
| + expect(highlights, isNot(isEmpty));
|
| + });
|
| + });
|
| + });
|
| }
|
|
|
|
|
| @@ -194,79 +337,184 @@ int _getSafeInt(Map<String, Object> json, String key, int defaultValue) {
|
| }
|
|
|
|
|
| -/**
|
| - * A helper to test 'analysis.*' requests.
|
| - */
|
| -class AnalysisTestHelper {
|
| - MockServerChannel serverChannel;
|
| - MemoryResourceProvider resourceProvider;
|
| - AnalysisServer server;
|
| - AnalysisDomainHandler handler;
|
| -
|
| - Map<String, List<String>> analysisSubscriptions = {};
|
| -
|
| +@ReflectiveTestCase()
|
| +class AnalysisDomainTest extends AbstractAnalysisTest {
|
| Map<String, List<AnalysisError>> filesErrors = {};
|
| - Map<String, List<Map<String, Object>>> filesHighlights = {};
|
| - Map<String, List<Map<String, Object>>> filesNavigation = {};
|
| -
|
| - String testFile = '/project/bin/test.dart';
|
| - String testCode;
|
| -
|
| - AnalysisTestHelper() {
|
| - serverChannel = new MockServerChannel();
|
| - resourceProvider = new MemoryResourceProvider();
|
| - server = new AnalysisServer(serverChannel, resourceProvider,
|
| - new MockPackageMapProvider(), null);
|
| - server.defaultSdk = new MockSdk();
|
| - handler = new AnalysisDomainHandler(server);
|
| - // listen for notifications
|
| - Stream<Notification> notificationStream =
|
| - serverChannel.notificationController.stream;
|
| - notificationStream.listen((Notification notification) {
|
| - if (notification.event == ANALYSIS_ERRORS) {
|
| - String file = notification.getParameter(FILE);
|
| - List<Map<String, Object>> errorMaps = notification.getParameter(ERRORS);
|
| - filesErrors[file] = errorMaps.map(jsonToAnalysisError).toList();
|
| - }
|
| - if (notification.event == ANALYSIS_HIGHLIGHTS) {
|
| - String file = notification.getParameter(FILE);
|
| - filesHighlights[file] = notification.getParameter(REGIONS);
|
| - }
|
| - if (notification.event == ANALYSIS_NAVIGATION) {
|
| - String file = notification.getParameter(FILE);
|
| - filesNavigation[file] = notification.getParameter(REGIONS);
|
| - }
|
| - });
|
| - }
|
| -
|
| - void addAnalysisSubscriptionHighlights(String file) {
|
| - addAnalysisSubscription(AnalysisService.HIGHLIGHTS, file);
|
| - }
|
|
|
| - void addAnalysisSubscriptionNavigation(String file) {
|
| - addAnalysisSubscription(AnalysisService.NAVIGATION, file);
|
| + void processNotification(Notification notification) {
|
| + if (notification.event == ANALYSIS_ERRORS) {
|
| + String file = notification.getParameter(FILE);
|
| + List<Map<String, Object>> errorMaps = notification.getParameter(ERRORS);
|
| + filesErrors[file] = errorMaps.map(jsonToAnalysisError).toList();
|
| + }
|
| }
|
|
|
| - void addAnalysisSubscription(AnalysisService service, String file) {
|
| - // add file to subscription
|
| - var files = analysisSubscriptions[service.name];
|
| - if (files == null) {
|
| - files = <String>[];
|
| - analysisSubscriptions[service.name] = files;
|
| - }
|
| - files.add(file);
|
| - // set subscriptions
|
| - Request request = new Request('0', ANALYSIS_SET_SUBSCRIPTIONS);
|
| - request.setParameter(SUBSCRIPTIONS, analysisSubscriptions);
|
| + test_packageMapDependencies() {
|
| + // Prepare a source file that has errors because it refers to an unknown
|
| + // package.
|
| + String pkgFile = '/packages/pkgA/libA.dart';
|
| + resourceProvider.newFile(pkgFile, '''
|
| +library lib_a;
|
| +class A {}
|
| +''');
|
| + addTestFile('''
|
| +import 'package:pkgA/libA.dart';
|
| +f(A a) {
|
| +}
|
| +''');
|
| + String pkgDependency = posix.join(projectPath, 'package_dep');
|
| + resourceProvider.newFile(pkgDependency, 'contents');
|
| + packageMapProvider.dependencies.add(pkgDependency);
|
| + // Create project and wait for analysis
|
| + createProject();
|
| + return waitForTasksFinished().then((_) {
|
| + expect(filesErrors[testFile], isNot(isEmpty));
|
| + // Add the package to the package map and tickle the package dependency.
|
| + packageMapProvider.packageMap = {
|
| + 'pkgA': [resourceProvider.getResource('/packages/pkgA')]
|
| + };
|
| + resourceProvider.modifyFile(pkgDependency, 'new contents');
|
| + // Let the server time to notice the file has changed, then let
|
| + // analysis omplete. There should now be no error.
|
| + return pumpEventQueue().then((_) => waitForTasksFinished()).then((_) {
|
| + expect(filesErrors[testFile], isEmpty);
|
| + });
|
| + });
|
| + }
|
| +
|
| + test_setRoots_packages() {
|
| + // prepare package
|
| + String pkgFile = '/packages/pkgA/libA.dart';
|
| + resourceProvider.newFile(pkgFile, '''
|
| +library lib_a;
|
| +class A {}
|
| +''');
|
| + packageMapProvider.packageMap['pkgA'] = [resourceProvider.getResource(
|
| + '/packages/pkgA')];
|
| + addTestFile('''
|
| +import 'package:pkgA/libA.dart';
|
| +main(A a) {
|
| +}
|
| +''');
|
| + // create project and wait for analysis
|
| + createProject();
|
| + return waitForTasksFinished().then((_) {
|
| + // if 'package:pkgA/libA.dart' was resolved, then there are no errors
|
| + expect(filesErrors[testFile], isEmpty);
|
| + // packages file also was resolved
|
| + expect(filesErrors[pkgFile], isEmpty);
|
| + });
|
| + }
|
| +}
|
| +
|
| +class AnalysisError {
|
| + final String errorCode;
|
| + final String severity;
|
| + final String type;
|
| + final Location location;
|
| + final String message;
|
| + final String correction;
|
| + AnalysisError(this.errorCode, this.severity, this.type, this.location,
|
| + this.message, this.correction);
|
| +
|
| + @override
|
| + String toString() {
|
| + return 'AnalysisError(location=$location message=$message); '
|
| + 'errorCode=$errorCode; severity=$separator type=$type';
|
| + }
|
| +}
|
| +
|
| +
|
| +/**
|
| + * A helper to test 'analysis.*' requests.
|
| + */
|
| +class AnalysisTestHelper {
|
| + MockServerChannel serverChannel;
|
| + MemoryResourceProvider resourceProvider;
|
| + AnalysisServer server;
|
| + AnalysisDomainHandler handler;
|
| +
|
| + Map<String, List<String>> analysisSubscriptions = {};
|
| +
|
| + Map<String, List<AnalysisError>> filesErrors = {};
|
| + Map<String, List<Map<String, Object>>> filesHighlights = {};
|
| + Map<String, List<Map<String, Object>>> filesNavigation = {};
|
| +
|
| + String testFile = '/project/bin/test.dart';
|
| + String testCode;
|
| +
|
| + AnalysisTestHelper() {
|
| + serverChannel = new MockServerChannel();
|
| + resourceProvider = new MemoryResourceProvider();
|
| + server = new AnalysisServer(serverChannel, resourceProvider,
|
| + new MockPackageMapProvider(), null);
|
| + server.defaultSdk = new MockSdk();
|
| + handler = new AnalysisDomainHandler(server);
|
| + // listen for notifications
|
| + Stream<Notification> notificationStream =
|
| + serverChannel.notificationController.stream;
|
| + notificationStream.listen((Notification notification) {
|
| + if (notification.event == ANALYSIS_ERRORS) {
|
| + String file = notification.getParameter(FILE);
|
| + List<Map<String, Object>> errorMaps = notification.getParameter(ERRORS);
|
| + filesErrors[file] = errorMaps.map(jsonToAnalysisError).toList();
|
| + }
|
| + if (notification.event == ANALYSIS_HIGHLIGHTS) {
|
| + String file = notification.getParameter(FILE);
|
| + filesHighlights[file] = notification.getParameter(REGIONS);
|
| + }
|
| + if (notification.event == ANALYSIS_NAVIGATION) {
|
| + String file = notification.getParameter(FILE);
|
| + filesNavigation[file] = notification.getParameter(REGIONS);
|
| + }
|
| + });
|
| + }
|
| +
|
| + void addAnalysisSubscription(AnalysisService service, String file) {
|
| + // add file to subscription
|
| + var files = analysisSubscriptions[service.name];
|
| + if (files == null) {
|
| + files = <String>[];
|
| + analysisSubscriptions[service.name] = files;
|
| + }
|
| + files.add(file);
|
| + // set subscriptions
|
| + Request request = new Request('0', ANALYSIS_SET_SUBSCRIPTIONS);
|
| + request.setParameter(SUBSCRIPTIONS, analysisSubscriptions);
|
| handleSuccessfulRequest(request);
|
| }
|
|
|
| + void addAnalysisSubscriptionHighlights(String file) {
|
| + addAnalysisSubscription(AnalysisService.HIGHLIGHTS, file);
|
| + }
|
| +
|
| + void addAnalysisSubscriptionNavigation(String file) {
|
| + addAnalysisSubscription(AnalysisService.NAVIGATION, file);
|
| + }
|
| +
|
| /**
|
| - * Returns a [Future] that completes when this this helper finished all its
|
| - * scheduled tasks.
|
| + * Creates an empty project `/project`.
|
| */
|
| - Future waitForOperationsFinished() {
|
| - return waitForServerOperationsPerformed(server);
|
| + void createEmptyProject() {
|
| + resourceProvider.newFolder('/project');
|
| + Request request = new Request('0', ANALYSIS_SET_ANALYSIS_ROOTS);
|
| + request.setParameter(INCLUDED, ['/project']);
|
| + request.setParameter(EXCLUDED, []);
|
| + handleSuccessfulRequest(request);
|
| + }
|
| +
|
| + /**
|
| + * Creates a project with a single Dart file `/project/bin/test.dart` with
|
| + * the given [code].
|
| + */
|
| + void createSingleFileProject(code) {
|
| + this.testCode = _getCodeString(code);
|
| + resourceProvider.newFolder('/project');
|
| + resourceProvider.newFile(testFile, testCode);
|
| + Request request = new Request('0', ANALYSIS_SET_ANALYSIS_ROOTS);
|
| + request.setParameter(INCLUDED, ['/project']);
|
| + request.setParameter(EXCLUDED, []);
|
| + handleSuccessfulRequest(request);
|
| }
|
|
|
| /**
|
| @@ -340,27 +588,21 @@ class AnalysisTestHelper {
|
| }
|
|
|
| /**
|
| - * Creates an empty project `/project`.
|
| + * Validates that the given [request] is handled successfully.
|
| */
|
| - void createEmptyProject() {
|
| - resourceProvider.newFolder('/project');
|
| - Request request = new Request('0', ANALYSIS_SET_ANALYSIS_ROOTS);
|
| - request.setParameter(INCLUDED, ['/project']);
|
| - request.setParameter(EXCLUDED, []);
|
| - handleSuccessfulRequest(request);
|
| + void handleSuccessfulRequest(Request request) {
|
| + Response response = handler.handleRequest(request);
|
| + expect(response, isResponseSuccess('0'));
|
| }
|
|
|
| /**
|
| - * Creates a project with a single Dart file `/project/bin/test.dart` with
|
| - * the given [code].
|
| + * Send an `updateContent` request for [testFile].
|
| */
|
| - void createSingleFileProject(code) {
|
| - this.testCode = _getCodeString(code);
|
| - resourceProvider.newFolder('/project');
|
| - resourceProvider.newFile(testFile, testCode);
|
| - Request request = new Request('0', ANALYSIS_SET_ANALYSIS_ROOTS);
|
| - request.setParameter(INCLUDED, ['/project']);
|
| - request.setParameter(EXCLUDED, []);
|
| + void sendContentChange(Map contentChange) {
|
| + Request request = new Request('0', ANALYSIS_UPDATE_CONTENT);
|
| + request.setParameter('files', {
|
| + testFile: contentChange
|
| + });
|
| handleSuccessfulRequest(request);
|
| }
|
|
|
| @@ -370,14 +612,6 @@ class AnalysisTestHelper {
|
| }
|
|
|
| /**
|
| - * Validates that the given [request] is handled successfully.
|
| - */
|
| - void handleSuccessfulRequest(Request request) {
|
| - Response response = handler.handleRequest(request);
|
| - expect(response, isResponseSuccess('0'));
|
| - }
|
| -
|
| - /**
|
| * Stops the associated server.
|
| */
|
| void stopServer() {
|
| @@ -385,14 +619,11 @@ class AnalysisTestHelper {
|
| }
|
|
|
| /**
|
| - * Send an `updateContent` request for [testFile].
|
| + * Returns a [Future] that completes when this this helper finished all its
|
| + * scheduled tasks.
|
| */
|
| - void sendContentChange(Map contentChange) {
|
| - Request request = new Request('0', ANALYSIS_UPDATE_CONTENT);
|
| - request.setParameter('files', {
|
| - testFile: contentChange
|
| - });
|
| - handleSuccessfulRequest(request);
|
| + Future waitForOperationsFinished() {
|
| + return waitForServerOperationsPerformed(server);
|
| }
|
|
|
| static String _getCodeString(code) {
|
| @@ -402,233 +633,3 @@ class AnalysisTestHelper {
|
| return code as String;
|
| }
|
| }
|
| -
|
| -
|
| -testNotificationErrors() {
|
| - AnalysisTestHelper helper;
|
| -
|
| - setUp(() {
|
| - helper = new AnalysisTestHelper();
|
| - });
|
| -
|
| - test('ParserErrorCode', () {
|
| - helper.createSingleFileProject('library lib');
|
| - return helper.waitForOperationsFinished().then((_) {
|
| - List<AnalysisError> errors = helper.getTestErrors();
|
| - expect(errors, hasLength(1));
|
| - AnalysisError error = errors[0];
|
| - expect(error.location.file, '/project/bin/test.dart');
|
| - expect(error.location.offset, isPositive);
|
| - expect(error.location.length, isNonNegative);
|
| - expect(error.errorCode, 'ParserErrorCode.EXPECTED_TOKEN');
|
| - expect(error.severity, 'ERROR');
|
| - expect(error.type, 'SYNTACTIC_ERROR');
|
| - expect(error.message, isNotNull);
|
| - });
|
| - });
|
| -
|
| - test('StaticWarningCode', () {
|
| - helper.createSingleFileProject(['main() {', ' print(unknown);', '}']);
|
| - return helper.waitForOperationsFinished().then((_) {
|
| - List<AnalysisError> errors = helper.getTestErrors();
|
| - expect(errors, hasLength(1));
|
| - AnalysisError error = errors[0];
|
| - expect(error.errorCode, 'StaticWarningCode.UNDEFINED_IDENTIFIER');
|
| - });
|
| - });
|
| -}
|
| -
|
| -
|
| -testUpdateContent() {
|
| - test('full content', () {
|
| - AnalysisTestHelper helper = new AnalysisTestHelper();
|
| - helper.createSingleFileProject('// empty');
|
| - return helper.waitForOperationsFinished().then((_) {
|
| - // no errors initially
|
| - List<AnalysisError> errors = helper.getTestErrors();
|
| - expect(errors, isEmpty);
|
| - // update code
|
| - helper.sendContentChange({
|
| - CONTENT: 'library lib'
|
| - });
|
| - // wait, there is an error
|
| - return helper.waitForOperationsFinished().then((_) {
|
| - List<AnalysisError> errors = helper.getTestErrors();
|
| - expect(errors, hasLength(1));
|
| - });
|
| - });
|
| - });
|
| -
|
| - test('incremental', () {
|
| - AnalysisTestHelper helper = new AnalysisTestHelper();
|
| - helper.createSingleFileProject('library A;');
|
| - return helper.waitForOperationsFinished().then((_) {
|
| - // no errors initially
|
| - List<AnalysisError> errors = helper.getTestErrors();
|
| - expect(errors, isEmpty);
|
| - // update code
|
| - helper.sendContentChange({
|
| - CONTENT: 'library lib',
|
| - OFFSET: 'library '.length,
|
| - OLD_LENGTH: 'A;'.length,
|
| - NEW_LENGTH: 'lib'.length,
|
| - });
|
| - // wait, there is an error
|
| - return helper.waitForOperationsFinished().then((_) {
|
| - List<AnalysisError> errors = helper.getTestErrors();
|
| - expect(errors, hasLength(1));
|
| - });
|
| - });
|
| - });
|
| -
|
| - test('change on disk, normal', () {
|
| - AnalysisTestHelper helper = new AnalysisTestHelper();
|
| - helper.createSingleFileProject('library A;');
|
| - return helper.waitForOperationsFinished().then((_) {
|
| - // There should be no errors
|
| - expect(helper.getTestErrors(), hasLength(0));
|
| - // Change file on disk, adding a syntax error.
|
| - helper.resourceProvider.modifyFile(helper.testFile, 'library lib');
|
| - // There should be errors now.
|
| - return pumpEventQueue().then((_) {
|
| - return helper.waitForOperationsFinished().then((_) {
|
| - expect(helper.getTestErrors(), hasLength(1));
|
| - });
|
| - });
|
| - });
|
| - });
|
| -
|
| - test('change on disk, during override', () {
|
| - AnalysisTestHelper helper = new AnalysisTestHelper();
|
| - helper.createSingleFileProject('library A;');
|
| - return helper.waitForOperationsFinished().then((_) {
|
| - // update code
|
| - helper.sendContentChange({
|
| - CONTENT: 'library B;'
|
| - });
|
| - // There should be no errors
|
| - return helper.waitForOperationsFinished().then((_) {
|
| - expect(helper.getTestErrors(), hasLength(0));
|
| - // Change file on disk, adding a syntax error.
|
| - helper.resourceProvider.modifyFile(helper.testFile, 'library lib');
|
| - // There should still be no errors (file should not have been reread).
|
| - return helper.waitForOperationsFinished().then((_) {
|
| - expect(helper.getTestErrors(), hasLength(0));
|
| - // Send a content change with a null content param--file should be
|
| - // reread from disk.
|
| - helper.sendContentChange({
|
| - CONTENT: null
|
| - });
|
| - // There should be errors now.
|
| - return helper.waitForOperationsFinished().then((_) {
|
| - expect(helper.getTestErrors(), hasLength(1));
|
| - });
|
| - });
|
| - });
|
| - });
|
| - });
|
| -}
|
| -
|
| -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.waitForOperationsFinished().then((_) {
|
| - var highlights = helper.getHighlights(helper.testFile);
|
| - expect(highlights, isNot(isEmpty));
|
| - });
|
| - });
|
| -
|
| - test('after analysis', () {
|
| - AnalysisTestHelper helper = new AnalysisTestHelper();
|
| - // create project
|
| - helper.createSingleFileProject('int V = 42;');
|
| - // wait, no regions initially
|
| - return helper.waitForOperationsFinished().then((_) {
|
| - var highlights = helper.getHighlights(helper.testFile);
|
| - expect(highlights, isEmpty);
|
| - // subscribe
|
| - helper.addAnalysisSubscriptionHighlights(helper.testFile);
|
| - // wait, has regions
|
| - return helper.waitForOperationsFinished().then((_) {
|
| - var highlights = helper.getHighlights(helper.testFile);
|
| - expect(highlights, isNot(isEmpty));
|
| - });
|
| - });
|
| - });
|
| -}
|
| -
|
| -
|
| -@ReflectiveTestCase()
|
| -class AnalysisDomainTest extends AbstractAnalysisTest {
|
| - Map<String, List<AnalysisError>> filesErrors = {};
|
| -
|
| - void processNotification(Notification notification) {
|
| - if (notification.event == ANALYSIS_ERRORS) {
|
| - String file = notification.getParameter(FILE);
|
| - List<Map<String, Object>> errorMaps = notification.getParameter(ERRORS);
|
| - filesErrors[file] = errorMaps.map(jsonToAnalysisError).toList();
|
| - }
|
| - }
|
| -
|
| - test_setRoots_packages() {
|
| - // prepare package
|
| - String pkgFile = '/packages/pkgA/libA.dart';
|
| - resourceProvider.newFile(pkgFile, '''
|
| -library lib_a;
|
| -class A {}
|
| -''');
|
| - packageMapProvider.packageMap['pkgA'] = [resourceProvider.getResource(
|
| - '/packages/pkgA')];
|
| - addTestFile('''
|
| -import 'package:pkgA/libA.dart';
|
| -main(A a) {
|
| -}
|
| -''');
|
| - // create project and wait for analysis
|
| - createProject();
|
| - return waitForTasksFinished().then((_) {
|
| - // if 'package:pkgA/libA.dart' was resolved, then there are no errors
|
| - expect(filesErrors[testFile], isEmpty);
|
| - // packages file also was resolved
|
| - expect(filesErrors[pkgFile], isEmpty);
|
| - });
|
| - }
|
| -
|
| - test_packageMapDependencies() {
|
| - // Prepare a source file that has errors because it refers to an unknown
|
| - // package.
|
| - String pkgFile = '/packages/pkgA/libA.dart';
|
| - resourceProvider.newFile(pkgFile, '''
|
| -library lib_a;
|
| -class A {}
|
| -''');
|
| - addTestFile('''
|
| -import 'package:pkgA/libA.dart';
|
| -f(A a) {
|
| -}
|
| -''');
|
| - String pkgDependency = posix.join(projectPath, 'package_dep');
|
| - resourceProvider.newFile(pkgDependency, 'contents');
|
| - packageMapProvider.dependencies.add(pkgDependency);
|
| - // Create project and wait for analysis
|
| - createProject();
|
| - return waitForTasksFinished().then((_) {
|
| - expect(filesErrors[testFile], isNot(isEmpty));
|
| - // Add the package to the package map and tickle the package dependency.
|
| - packageMapProvider.packageMap = {
|
| - 'pkgA': [resourceProvider.getResource('/packages/pkgA')]
|
| - };
|
| - resourceProvider.modifyFile(pkgDependency, 'new contents');
|
| - // Let the server time to notice the file has changed, then let
|
| - // analysis omplete. There should now be no error.
|
| - return pumpEventQueue().then((_) => waitForTasksFinished()).then((_) {
|
| - expect(filesErrors[testFile], isEmpty);
|
| - });
|
| - });
|
| - }
|
| -}
|
|
|