Files
sdk/pkg/analysis_server/test/analysis/get_errors_test.dart
T
Paul Berry 128dec84b5 Separate the API's used by ContextManager.
Previously, ContextManager had two API's: one used by analysis server
to tell the ContextManager what to do, and one used by the
ContextManager to make callbacks to analysis server in response to its
requests.  The first API was implemented in the class
AbstractContextManager, which derived from ContextManager, and the
second API was implemented in ServerContextManager, which derived from
AbstractContextManager.

In addition to causing confusion, this made it impossible to provide
an alternate implementation of ContextManager as a plug-in, since the
plug in would have had to re-implement the second API, and that would
have required accessing private implementation details of the
ContextManager.

This CL separates the API's: the first API is specified in
ContextManager and implemented in ContextManagerImpl, and the second
API is specified in ContextManagerCallbacks and implemented in
ServerContextManagerCallbacks.

In the long run I hope to eliminate the ContextManagerCallbacks class
entirely, by having the ContextManager tell its client what to do
using return values rather than callbacks.

R=brianwilkerson@google.com

Review URL: https://codereview.chromium.org//1243893002 .
2015-07-21 10:40:57 -07:00

130 lines
3.4 KiB
Dart

// Copyright (c) 2014, 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.
library test.analysis.get_errors;
import 'dart:async';
import 'package:analysis_server/src/domain_analysis.dart';
import 'package:analysis_server/src/protocol.dart';
import 'package:analyzer/file_system/file_system.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
import 'package:unittest/unittest.dart';
import '../analysis_abstract.dart';
main() {
groupSep = ' | ';
defineReflectiveTests(GetErrorsTest);
}
@reflectiveTest
class GetErrorsTest extends AbstractAnalysisTest {
static const String requestId = 'test-getError';
@override
void setUp() {
super.setUp();
server.handlers = [new AnalysisDomainHandler(server),];
createProject();
}
test_afterAnalysisComplete() {
addTestFile('''
main() {
print(42)
}
''');
return waitForTasksFinished().then((_) {
return _getErrors(testFile).then((List<AnalysisError> errors) {
expect(errors, hasLength(1));
});
});
}
test_fileDoesNotExist() {
String file = '$projectPath/doesNotExist.dart';
return _checkInvalid(file);
}
test_fileWithoutContext() {
String file = '/outside.dart';
addFile(file, '''
main() {
print(42);
}
''');
return _checkInvalid(file);
}
test_hasErrors() {
addTestFile('''
main() {
print(42)
}
''');
return _getErrors(testFile).then((List<AnalysisError> errors) {
expect(errors, hasLength(1));
{
AnalysisError error = errors[0];
expect(error.severity, AnalysisErrorSeverity.ERROR);
expect(error.type, AnalysisErrorType.SYNTACTIC_ERROR);
expect(error.location.file, testFile);
expect(error.location.startLine, 2);
}
});
}
test_noErrors() {
addTestFile('''
main() {
print(42);
}
''');
return _getErrors(testFile).then((List<AnalysisError> errors) {
expect(errors, isEmpty);
});
}
test_removeContextAfterRequest() {
addTestFile('''
main() {
print(42)
}
''');
// handle the request synchronously
Request request = _createGetErrorsRequest();
server.handleRequest(request);
// remove context, causes sending an "invalid file" error
{
Folder projectFolder = resourceProvider.getResource(projectPath);
server.contextManager.callbacks.removeContext(projectFolder, <String>[]);
}
// wait for an error response
return serverChannel.waitForResponse(request).then((Response response) {
expect(response.error, isNotNull);
expect(response.error.code, RequestErrorCode.GET_ERRORS_INVALID_FILE);
});
}
Future _checkInvalid(String file) {
Request request = _createGetErrorsRequest();
return serverChannel.sendRequest(request).then((Response response) {
expect(response.error, isNotNull);
expect(response.error.code, RequestErrorCode.GET_ERRORS_INVALID_FILE);
});
}
Request _createGetErrorsRequest() {
return new AnalysisGetErrorsParams(testFile).toRequest(requestId);
}
Future<List<AnalysisError>> _getErrors(String file) {
Request request = _createGetErrorsRequest();
return serverChannel.sendRequest(request).then((Response response) {
return new AnalysisGetErrorsResult.fromResponse(response).errors;
});
}
}