| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library analyzer_cli.test.formatter; | 5 library analyzer_cli.test.formatter; |
| 6 | 6 |
| 7 import 'package:analyzer/analyzer.dart'; | 7 import 'package:analyzer/analyzer.dart'; |
| 8 import 'package:analyzer_cli/src/error_formatter.dart'; | 8 import 'package:analyzer_cli/src/error_formatter.dart'; |
| 9 import 'package:typed_mock/typed_mock.dart'; | 9 import 'package:typed_mock/typed_mock.dart'; |
| 10 import 'package:unittest/unittest.dart' hide ErrorFormatter; | 10 import 'package:unittest/unittest.dart' hide ErrorFormatter; |
| 11 | 11 |
| 12 import 'mocks.dart'; | 12 import 'mocks.dart'; |
| 13 | 13 |
| 14 main() { | 14 main() { |
| 15 group('reporter', () { | 15 group('reporter', () { |
| 16 var out = new StringBuffer(); | 16 var out = new StringBuffer(); |
| 17 var stats = new AnalysisStats(); |
| 17 | 18 |
| 19 setUp(() => stats.init()); |
| 18 tearDown(() => out.clear()); | 20 tearDown(() => out.clear()); |
| 19 | 21 |
| 20 // Options | 22 // Options |
| 21 var options = new MockCommandLineOptions(); | 23 var options = new MockCommandLineOptions(); |
| 22 when(options.enableTypeChecks).thenReturn(false); | 24 when(options.enableTypeChecks).thenReturn(false); |
| 23 when(options.hintsAreFatal).thenReturn(false); | 25 when(options.hintsAreFatal).thenReturn(false); |
| 24 when(options.machineFormat).thenReturn(false); | 26 when(options.machineFormat).thenReturn(false); |
| 25 | 27 |
| 26 var reporter = new ErrorFormatter(out, options); | 28 var reporter = new ErrorFormatter(out, options, stats); |
| 27 | 29 |
| 28 test('error', () { | 30 test('error', () { |
| 29 var error = mockError(ErrorType.SYNTACTIC_ERROR, ErrorSeverity.ERROR); | 31 var error = mockError(ErrorType.SYNTACTIC_ERROR, ErrorSeverity.ERROR); |
| 30 reporter.formatErrors([error]); | 32 reporter.formatErrors([error]); |
| 31 | 33 |
| 32 expect( | 34 expect(out.toString().trim(), |
| 33 out.toString(), | 35 '[error] MSG (/foo/bar/baz.dart, line 3, col 3)'); |
| 34 '''[error] MSG (/foo/bar/baz.dart, line 3, col 3) | |
| 35 1 error found. | |
| 36 '''); | |
| 37 }); | 36 }); |
| 38 | 37 |
| 39 test('hint', () { | 38 test('hint', () { |
| 40 var error = mockError(ErrorType.HINT, ErrorSeverity.INFO); | 39 var error = mockError(ErrorType.HINT, ErrorSeverity.INFO); |
| 41 reporter.formatErrors([error]); | 40 reporter.formatErrors([error]); |
| 42 | 41 |
| 42 expect(out.toString().trim(), |
| 43 '[hint] MSG (/foo/bar/baz.dart, line 3, col 3)'); |
| 44 }); |
| 45 |
| 46 test('stats', () { |
| 47 var error = mockError(ErrorType.HINT, ErrorSeverity.INFO); |
| 48 reporter.formatErrors([error]); |
| 49 stats.print(out); |
| 43 expect( | 50 expect( |
| 44 out.toString(), | 51 out.toString().trim(), |
| 45 '''[hint] MSG (/foo/bar/baz.dart, line 3, col 3) | 52 '''[hint] MSG (/foo/bar/baz.dart, line 3, col 3) |
| 46 1 hint found. | 53 1 hint found.'''); |
| 47 '''); | |
| 48 }); | 54 }); |
| 49 }); | 55 }); |
| 50 } | 56 } |
| 51 | 57 |
| 52 MockAnalysisErrorInfo mockError(ErrorType type, ErrorSeverity severity) { | 58 MockAnalysisErrorInfo mockError(ErrorType type, ErrorSeverity severity) { |
| 53 // ErrorInfo | 59 // ErrorInfo |
| 54 var info = new MockAnalysisErrorInfo(); | 60 var info = new MockAnalysisErrorInfo(); |
| 55 var error = new MockAnalysisError(); | 61 var error = new MockAnalysisError(); |
| 56 var lineInfo = new MockLineInfo(); | 62 var lineInfo = new MockLineInfo(); |
| 57 var location = new MockLineInfo_Location(); | 63 var location = new MockLineInfo_Location(); |
| 58 when(location.columnNumber).thenReturn(3); | 64 when(location.columnNumber).thenReturn(3); |
| 59 when(location.lineNumber).thenReturn(3); | 65 when(location.lineNumber).thenReturn(3); |
| 60 when(lineInfo.getLocation(anyObject)).thenReturn(location); | 66 when(lineInfo.getLocation(anyObject)).thenReturn(location); |
| 61 when(info.lineInfo).thenReturn(lineInfo); | 67 when(info.lineInfo).thenReturn(lineInfo); |
| 62 | 68 |
| 63 // Details | 69 // Details |
| 64 var code = new MockErrorCode(); | 70 var code = new MockErrorCode(); |
| 65 when(code.type).thenReturn(type); | 71 when(code.type).thenReturn(type); |
| 66 when(code.errorSeverity).thenReturn(severity); | 72 when(code.errorSeverity).thenReturn(severity); |
| 67 when(code.name).thenReturn('mock_code'); | 73 when(code.name).thenReturn('mock_code'); |
| 68 when(error.errorCode).thenReturn(code); | 74 when(error.errorCode).thenReturn(code); |
| 69 when(error.message).thenReturn('MSG'); | 75 when(error.message).thenReturn('MSG'); |
| 70 var source = new MockSource(); | 76 var source = new MockSource(); |
| 71 when(source.fullName).thenReturn('/foo/bar/baz.dart'); | 77 when(source.fullName).thenReturn('/foo/bar/baz.dart'); |
| 72 when(error.source).thenReturn(source); | 78 when(error.source).thenReturn(source); |
| 73 when(info.errors).thenReturn([error]); | 79 when(info.errors).thenReturn([error]); |
| 74 | 80 |
| 75 return info; | 81 return info; |
| 76 } | 82 } |
| OLD | NEW |