| 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(); | |
| 18 | 17 |
| 19 setUp(() => stats.init()); | |
| 20 tearDown(() => out.clear()); | 18 tearDown(() => out.clear()); |
| 21 | 19 |
| 22 // Options | 20 // Options |
| 23 var options = new MockCommandLineOptions(); | 21 var options = new MockCommandLineOptions(); |
| 24 when(options.enableTypeChecks).thenReturn(false); | 22 when(options.enableTypeChecks).thenReturn(false); |
| 25 when(options.hintsAreFatal).thenReturn(false); | 23 when(options.hintsAreFatal).thenReturn(false); |
| 26 when(options.machineFormat).thenReturn(false); | 24 when(options.machineFormat).thenReturn(false); |
| 27 | 25 |
| 28 var reporter = new ErrorFormatter(out, options, stats); | 26 var reporter = new ErrorFormatter(out, options); |
| 29 | 27 |
| 30 test('error', () { | 28 test('error', () { |
| 31 var error = mockError(ErrorType.SYNTACTIC_ERROR, ErrorSeverity.ERROR); | 29 var error = mockError(ErrorType.SYNTACTIC_ERROR, ErrorSeverity.ERROR); |
| 32 reporter.formatErrors([error]); | 30 reporter.formatErrors([error]); |
| 33 | 31 |
| 34 expect(out.toString().trim(), | 32 expect( |
| 35 '[error] MSG (/foo/bar/baz.dart, line 3, col 3)'); | 33 out.toString(), |
| 34 '''[error] MSG (/foo/bar/baz.dart, line 3, col 3) |
| 35 1 error found. |
| 36 '''); |
| 36 }); | 37 }); |
| 37 | 38 |
| 38 test('hint', () { | 39 test('hint', () { |
| 39 var error = mockError(ErrorType.HINT, ErrorSeverity.INFO); | 40 var error = mockError(ErrorType.HINT, ErrorSeverity.INFO); |
| 40 reporter.formatErrors([error]); | 41 reporter.formatErrors([error]); |
| 41 | 42 |
| 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); | |
| 50 expect( | 43 expect( |
| 51 out.toString().trim(), | 44 out.toString(), |
| 52 '''[hint] MSG (/foo/bar/baz.dart, line 3, col 3) | 45 '''[hint] MSG (/foo/bar/baz.dart, line 3, col 3) |
| 53 1 hint found.'''); | 46 1 hint found. |
| 47 '''); |
| 54 }); | 48 }); |
| 55 }); | 49 }); |
| 56 } | 50 } |
| 57 | 51 |
| 58 MockAnalysisErrorInfo mockError(ErrorType type, ErrorSeverity severity) { | 52 MockAnalysisErrorInfo mockError(ErrorType type, ErrorSeverity severity) { |
| 59 // ErrorInfo | 53 // ErrorInfo |
| 60 var info = new MockAnalysisErrorInfo(); | 54 var info = new MockAnalysisErrorInfo(); |
| 61 var error = new MockAnalysisError(); | 55 var error = new MockAnalysisError(); |
| 62 var lineInfo = new MockLineInfo(); | 56 var lineInfo = new MockLineInfo(); |
| 63 var location = new MockLineInfo_Location(); | 57 var location = new MockLineInfo_Location(); |
| 64 when(location.columnNumber).thenReturn(3); | 58 when(location.columnNumber).thenReturn(3); |
| 65 when(location.lineNumber).thenReturn(3); | 59 when(location.lineNumber).thenReturn(3); |
| 66 when(lineInfo.getLocation(anyObject)).thenReturn(location); | 60 when(lineInfo.getLocation(anyObject)).thenReturn(location); |
| 67 when(info.lineInfo).thenReturn(lineInfo); | 61 when(info.lineInfo).thenReturn(lineInfo); |
| 68 | 62 |
| 69 // Details | 63 // Details |
| 70 var code = new MockErrorCode(); | 64 var code = new MockErrorCode(); |
| 71 when(code.type).thenReturn(type); | 65 when(code.type).thenReturn(type); |
| 72 when(code.errorSeverity).thenReturn(severity); | 66 when(code.errorSeverity).thenReturn(severity); |
| 73 when(code.name).thenReturn('mock_code'); | 67 when(code.name).thenReturn('mock_code'); |
| 74 when(error.errorCode).thenReturn(code); | 68 when(error.errorCode).thenReturn(code); |
| 75 when(error.message).thenReturn('MSG'); | 69 when(error.message).thenReturn('MSG'); |
| 76 var source = new MockSource(); | 70 var source = new MockSource(); |
| 77 when(source.fullName).thenReturn('/foo/bar/baz.dart'); | 71 when(source.fullName).thenReturn('/foo/bar/baz.dart'); |
| 78 when(error.source).thenReturn(source); | 72 when(error.source).thenReturn(source); |
| 79 when(info.errors).thenReturn([error]); | 73 when(info.errors).thenReturn([error]); |
| 80 | 74 |
| 81 return info; | 75 return info; |
| 82 } | 76 } |
| OLD | NEW |