Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(289)

Side by Side Diff: test/reporter_test.dart

Issue 1382023002: Support for --fatal-hints. (Closed) Base URL: https://github.com/dart-lang/analyzer_cli.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/options_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 @TestOn("vm") 5 @TestOn("vm")
6
7 library analyzer_cli.test.formatter; 6 library analyzer_cli.test.formatter;
8 7
9 import 'package:analyzer/analyzer.dart'; 8 import 'package:analyzer/analyzer.dart';
10 import 'package:analyzer_cli/src/error_formatter.dart'; 9 import 'package:analyzer_cli/src/error_formatter.dart';
11 import 'package:mockito/mockito.dart'; 10 import 'package:mockito/mockito.dart';
12 import 'package:test/test.dart' hide ErrorFormatter; 11 import 'package:test/test.dart' hide ErrorFormatter;
13 12
14 import 'mocks.dart'; 13 import 'mocks.dart';
15 14
16 main() { 15 main() {
17 group('reporter', () { 16 group('reporter', () {
18 var out = new StringBuffer(); 17 var out = new StringBuffer();
19 18
20 tearDown(() => out.clear()); 19 tearDown(() => out.clear());
21 20
22 // Options 21 // Options
23 var options = new MockCommandLineOptions(); 22 var options = new MockCommandLineOptions();
24 when(options.disableHints).thenReturn(true); 23 when(options.disableHints).thenReturn(true);
25 when(options.enableTypeChecks).thenReturn(true); 24 when(options.enableTypeChecks).thenReturn(true);
26 when(options.machineFormat).thenReturn(false); 25 when(options.machineFormat).thenReturn(false);
26 when(options.hintsAreFatal).thenReturn(false);
27 27
28 var reporter = new ErrorFormatter(out, options); 28 var reporter = new ErrorFormatter(out, options);
29 29
30 test('error', () { 30 test('error', () {
31 var error = mockError(ErrorType.SYNTACTIC_ERROR, ErrorSeverity.ERROR); 31 var error = mockError(ErrorType.SYNTACTIC_ERROR, ErrorSeverity.ERROR);
32 reporter.formatErrors([error]); 32 reporter.formatErrors([error]);
33 33
34 expect(out.toString(), equals( 34 expect(out.toString(),
35 '''[error] MSG (/foo/bar/baz.dart, line 3, col 3) 35 equals('''[error] MSG (/foo/bar/baz.dart, line 3, col 3)
36 1 error found. 36 1 error found.
37 ''')); 37 '''));
38 }); 38 });
39 39
40 test('hint', () { 40 test('hint', () {
41 var error = mockError(ErrorType.HINT, ErrorSeverity.INFO); 41 var error = mockError(ErrorType.HINT, ErrorSeverity.INFO);
42 reporter.formatErrors([error]); 42 reporter.formatErrors([error]);
43 43
44 expect(out.toString(), equals( 44 expect(out.toString(),
45 '''[hint] MSG (/foo/bar/baz.dart, line 3, col 3) 45 equals('''[hint] MSG (/foo/bar/baz.dart, line 3, col 3)
46 1 hint found. 46 1 hint found.
47 ''')); 47 '''));
48 }); 48 });
49 }); 49 });
50 } 50 }
51 51
52 MockAnalysisErrorInfo mockError(ErrorType type, ErrorSeverity severity) { 52 MockAnalysisErrorInfo mockError(ErrorType type, ErrorSeverity severity) {
53
54 // ErrorInfo 53 // ErrorInfo
55 var info = new MockAnalysisErrorInfo(); 54 var info = new MockAnalysisErrorInfo();
56 var error = new MockAnalysisError(); 55 var error = new MockAnalysisError();
57 var lineInfo = new MockLineInfo(); 56 var lineInfo = new MockLineInfo();
58 var location = new MockLineInfo_Location(); 57 var location = new MockLineInfo_Location();
59 when(location.columnNumber).thenReturn(3); 58 when(location.columnNumber).thenReturn(3);
60 when(location.lineNumber).thenReturn(3); 59 when(location.lineNumber).thenReturn(3);
61 when(lineInfo.getLocation(any)).thenReturn(location); 60 when(lineInfo.getLocation(any)).thenReturn(location);
62 when(info.lineInfo).thenReturn(lineInfo); 61 when(info.lineInfo).thenReturn(lineInfo);
63 62
64 // Details 63 // Details
65 var code = new MockErrorCode(); 64 var code = new MockErrorCode();
66 when(code.type).thenReturn(type); 65 when(code.type).thenReturn(type);
67 when(code.errorSeverity).thenReturn(severity); 66 when(code.errorSeverity).thenReturn(severity);
68 when(code.name).thenReturn('mock_code'); 67 when(code.name).thenReturn('mock_code');
69 when(error.errorCode).thenReturn(code); 68 when(error.errorCode).thenReturn(code);
70 when(error.message).thenReturn('MSG'); 69 when(error.message).thenReturn('MSG');
71 var source = new MockSource(); 70 var source = new MockSource();
72 when(source.fullName).thenReturn('/foo/bar/baz.dart'); 71 when(source.fullName).thenReturn('/foo/bar/baz.dart');
73 when(error.source).thenReturn(source); 72 when(error.source).thenReturn(source);
74 when(info.errors).thenReturn([error]); 73 when(info.errors).thenReturn([error]);
75 74
76 return info; 75 return info;
77 } 76 }
OLDNEW
« no previous file with comments | « test/options_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698