| Index: pkg/analysis_server/test/computer/error_test.dart
|
| diff --git a/pkg/analysis_server/test/computer/error_test.dart b/pkg/analysis_server/test/computer/error_test.dart
|
| index 35daca9370410321e4caf1a8bf0a03197f92865f..57fa21f0c34793e2d44528d06c38a49c9ff519bc 100644
|
| --- a/pkg/analysis_server/test/computer/error_test.dart
|
| +++ b/pkg/analysis_server/test/computer/error_test.dart
|
| @@ -7,12 +7,11 @@ library test.computer.error;
|
| import 'package:analysis_server/src/computer/element.dart';
|
| import 'package:analysis_server/src/computer/error.dart';
|
| import 'package:analysis_services/constants.dart';
|
| -import 'package:analysis_testing/abstract_single_unit.dart';
|
| +import 'package:analysis_testing/mocks.dart';
|
| import 'package:analysis_testing/reflective_tests.dart';
|
| -import 'package:analyzer/src/generated/element.dart' as engine;
|
| -import 'package:analyzer/src/generated/engine.dart' as engine;
|
| import 'package:analyzer/src/generated/error.dart' as engine;
|
| -import 'package:analyzer/src/generated/utilities_dart.dart' as engine;
|
| +import 'package:analyzer/src/generated/source.dart';
|
| +import 'package:typed_mock/typed_mock.dart';
|
| import 'package:unittest/unittest.dart';
|
|
|
|
|
| @@ -23,36 +22,86 @@ main() {
|
| }
|
|
|
|
|
| -@ReflectiveTestCase()
|
| -class AnalysisErrorTest extends AbstractSingleUnitTest {
|
| - void test_fromEngine() {
|
| - verifyNoTestUnitErrors = false;
|
| - resolveTestUnit('''
|
| -main() {
|
| - print(42)
|
| +class AnalysisErrorMock extends TypedMock implements engine.AnalysisError {
|
| + noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
|
| }
|
| -''');
|
| - engine.AnalysisErrorInfo errors = context.getErrors(testSource);
|
| - engine.AnalysisError engineError = errors.errors[0];
|
| - AnalysisError error =
|
| - new AnalysisError.fromEngine(errors.lineInfo, engineError);
|
| - {
|
| - Location location = error.location;
|
| - expect(location.file, testFile);
|
| - expect(location.offset, 19);
|
| - expect(location.length, 1);
|
| - expect(location.startLine, 2);
|
| - expect(location.startColumn, 11);
|
| - }
|
| - expect(error.message, "Expected to find ';'");
|
| - expect(error.severity, "ERROR");
|
| - expect(error.type, "SYNTACTIC_ERROR");
|
| - expect(
|
| - error.toString(),
|
| - 'AnalysisError(location=Location(file=/test.dart; offset=19; '
|
| - 'length=1; startLine=2; startColumn=11) '
|
| - 'message=Expected to find \';\'; severity=ERROR; '
|
| - 'type=SYNTACTIC_ERROR; correction=null');
|
| +
|
| +
|
| +@ReflectiveTestCase()
|
| +class AnalysisErrorTest {
|
| + Source source = new MockSource();
|
| + LineInfo lineInfo;
|
| + engine.AnalysisError engineError = new AnalysisErrorMock();
|
| +
|
| + void setUp() {
|
| + // prepare Source
|
| + when(source.fullName).thenReturn('foo.dart');
|
| + // prepare LineInfo
|
| + lineInfo = new LineInfo([0, 5, 9, 20]);
|
| + // prepare AnalysisError
|
| + when(engineError.source).thenReturn(source);
|
| + when(
|
| + engineError.errorCode).thenReturn(engine.CompileTimeErrorCode.AMBIGUOUS_EXPORT);
|
| + when(engineError.message).thenReturn('my message');
|
| + when(engineError.offset).thenReturn(10);
|
| + when(engineError.length).thenReturn(20);
|
| + }
|
| +
|
| + void tearDown() {
|
| + source = null;
|
| + engineError = null;
|
| + }
|
| +
|
| + void test_fromEngine_hasCorrection() {
|
| + when(engineError.correction).thenReturn('my correction');
|
| + AnalysisError error = new AnalysisError.fromEngine(lineInfo, engineError);
|
| + expect(error.toJson(), {
|
| + SEVERITY: 'ERROR',
|
| + TYPE: 'COMPILE_TIME_ERROR',
|
| + LOCATION: {
|
| + FILE: 'foo.dart',
|
| + OFFSET: 10,
|
| + LENGTH: 20,
|
| + START_LINE: 3,
|
| + START_COLUMN: 2
|
| + },
|
| + MESSAGE: 'my message',
|
| + CORRECTION: 'my correction'
|
| + });
|
| + }
|
| +
|
| + void test_fromEngine_noCorrection() {
|
| + when(engineError.correction).thenReturn(null);
|
| + AnalysisError error = new AnalysisError.fromEngine(lineInfo, engineError);
|
| + expect(error.toJson(), {
|
| + SEVERITY: 'ERROR',
|
| + TYPE: 'COMPILE_TIME_ERROR',
|
| + LOCATION: {
|
| + FILE: 'foo.dart',
|
| + OFFSET: 10,
|
| + LENGTH: 20,
|
| + START_LINE: 3,
|
| + START_COLUMN: 2
|
| + },
|
| + MESSAGE: 'my message'
|
| + });
|
| + }
|
| +
|
| + void test_fromEngine_noLineInfo() {
|
| + when(engineError.correction).thenReturn(null);
|
| + AnalysisError error = new AnalysisError.fromEngine(null, engineError);
|
| + expect(error.toJson(), {
|
| + SEVERITY: 'ERROR',
|
| + TYPE: 'COMPILE_TIME_ERROR',
|
| + LOCATION: {
|
| + FILE: 'foo.dart',
|
| + OFFSET: 10,
|
| + LENGTH: 20,
|
| + START_LINE: -1,
|
| + START_COLUMN: -1
|
| + },
|
| + MESSAGE: 'my message'
|
| + });
|
| }
|
|
|
| void test_fromJson() {
|
| @@ -66,44 +115,37 @@ main() {
|
| START_LINE: 2,
|
| START_COLUMN: 11
|
| },
|
| - MESSAGE: 'Expected to find \';\''
|
| + MESSAGE: 'Expected to find \';\'',
|
| + CORRECTION: 'my correction'
|
| };
|
| AnalysisError error = AnalysisError.fromJson(json);
|
| {
|
| Location location = error.location;
|
| - expect(location.file, testFile);
|
| + expect(location.file, '/test.dart');
|
| expect(location.offset, 19);
|
| expect(location.length, 1);
|
| expect(location.startLine, 2);
|
| expect(location.startColumn, 11);
|
| }
|
| expect(error.message, "Expected to find ';'");
|
| - expect(error.severity, "ERROR");
|
| - expect(error.type, "SYNTACTIC_ERROR");
|
| + expect(error.severity, 'ERROR');
|
| + expect(error.type, 'SYNTACTIC_ERROR');
|
| + expect(error.correction, "my correction");
|
| }
|
|
|
| - void test_toJson() {
|
| - verifyNoTestUnitErrors = false;
|
| - resolveTestUnit('''
|
| -main() {
|
| - print(42)
|
| -}
|
| -''');
|
| - engine.AnalysisErrorInfo errors = context.getErrors(testSource);
|
| - engine.AnalysisError engineError = errors.errors[0];
|
| - AnalysisError error =
|
| - new AnalysisError.fromEngine(errors.lineInfo, engineError);
|
| - expect(error.toJson(), {
|
| - SEVERITY: 'ERROR',
|
| - TYPE: 'SYNTACTIC_ERROR',
|
| - LOCATION: {
|
| - FILE: '/test.dart',
|
| - OFFSET: 19,
|
| - LENGTH: 1,
|
| - START_LINE: 2,
|
| - START_COLUMN: 11
|
| - },
|
| - MESSAGE: 'Expected to find \';\''
|
| - });
|
| + void test_engineErrorsToJson() {
|
| + var json = engineErrorsToJson(lineInfo, [engineError]);
|
| + expect(json, unorderedEquals([{
|
| + 'severity': 'ERROR',
|
| + 'type': 'COMPILE_TIME_ERROR',
|
| + 'location': {
|
| + 'file': 'foo.dart',
|
| + 'offset': 10,
|
| + 'length': 20,
|
| + 'startLine': 3,
|
| + 'startColumn': 2
|
| + },
|
| + 'message': 'my message'
|
| + }]));
|
| }
|
| }
|
|
|