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