OLD | NEW |
| (Empty) |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 @TestOn("vm") | |
6 library analyzer_cli.test.formatter; | |
7 | |
8 import 'package:analyzer/analyzer.dart'; | |
9 import 'package:analyzer_cli/src/error_formatter.dart'; | |
10 import 'package:mockito/mockito.dart'; | |
11 import 'package:test/test.dart' hide ErrorFormatter; | |
12 | |
13 import 'mocks.dart'; | |
14 | |
15 main() { | |
16 group('reporter', () { | |
17 var out = new StringBuffer(); | |
18 | |
19 tearDown(() => out.clear()); | |
20 | |
21 // Options | |
22 var options = new MockCommandLineOptions(); | |
23 when(options.disableHints).thenReturn(true); | |
24 when(options.enableTypeChecks).thenReturn(true); | |
25 when(options.machineFormat).thenReturn(false); | |
26 when(options.hintsAreFatal).thenReturn(false); | |
27 | |
28 var reporter = new ErrorFormatter(out, options); | |
29 | |
30 test('error', () { | |
31 var error = mockError(ErrorType.SYNTACTIC_ERROR, ErrorSeverity.ERROR); | |
32 reporter.formatErrors([error]); | |
33 | |
34 expect(out.toString(), | |
35 equals('''[error] MSG (/foo/bar/baz.dart, line 3, col 3) | |
36 1 error found. | |
37 ''')); | |
38 }); | |
39 | |
40 test('hint', () { | |
41 var error = mockError(ErrorType.HINT, ErrorSeverity.INFO); | |
42 reporter.formatErrors([error]); | |
43 | |
44 expect(out.toString(), | |
45 equals('''[hint] MSG (/foo/bar/baz.dart, line 3, col 3) | |
46 1 hint found. | |
47 ''')); | |
48 }); | |
49 }); | |
50 } | |
51 | |
52 MockAnalysisErrorInfo mockError(ErrorType type, ErrorSeverity severity) { | |
53 // ErrorInfo | |
54 var info = new MockAnalysisErrorInfo(); | |
55 var error = new MockAnalysisError(); | |
56 var lineInfo = new MockLineInfo(); | |
57 var location = new MockLineInfo_Location(); | |
58 when(location.columnNumber).thenReturn(3); | |
59 when(location.lineNumber).thenReturn(3); | |
60 when(lineInfo.getLocation(any)).thenReturn(location); | |
61 when(info.lineInfo).thenReturn(lineInfo); | |
62 | |
63 // Details | |
64 var code = new MockErrorCode(); | |
65 when(code.type).thenReturn(type); | |
66 when(code.errorSeverity).thenReturn(severity); | |
67 when(code.name).thenReturn('mock_code'); | |
68 when(error.errorCode).thenReturn(code); | |
69 when(error.message).thenReturn('MSG'); | |
70 var source = new MockSource(); | |
71 when(source.fullName).thenReturn('/foo/bar/baz.dart'); | |
72 when(error.source).thenReturn(source); | |
73 when(info.errors).thenReturn([error]); | |
74 | |
75 return info; | |
76 } | |
OLD | NEW |