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

Side by Side Diff: pkg/analyzer_cli/test/reporter_test.dart

Issue 2793813002: Fix an issue with duplicate reported analysis errors. (Closed)
Patch Set: Merge branch 'master' into fix_duplicate_errors Created 3 years, 8 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 | « pkg/analyzer_cli/test/errors_reported_once_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 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/src/generated/engine.dart';
8 import 'package:analyzer_cli/src/ansi.dart' as ansi; 9 import 'package:analyzer_cli/src/ansi.dart' as ansi;
9 import 'package:analyzer_cli/src/error_formatter.dart'; 10 import 'package:analyzer_cli/src/error_formatter.dart';
10 import 'package:test/test.dart' hide ErrorFormatter; 11 import 'package:test/test.dart' hide ErrorFormatter;
11 import 'package:typed_mock/typed_mock.dart'; 12 import 'package:typed_mock/typed_mock.dart';
12 13
13 import 'mocks.dart'; 14 import 'mocks.dart';
14 15
15 main() { 16 main() {
16 group('reporter', () { 17 group('reporter', () {
17 var out = new StringBuffer(); 18 StringBuffer out;
18 var stats = new AnalysisStats(); 19 AnalysisStats stats;
20 MockCommandLineOptions options;
21 ErrorFormatter reporter;
19 22
20 setUp(() { 23 setUp(() {
21 ansi.runningTests = true; 24 ansi.runningTests = true;
22 stats.init(); 25
26 out = new StringBuffer();
27 stats = new AnalysisStats();
28
29 options = new MockCommandLineOptions();
30 when(options.enableTypeChecks).thenReturn(false);
31 when(options.hintsAreFatal).thenReturn(false);
32 when(options.machineFormat).thenReturn(false);
33 when(options.verbose).thenReturn(false);
34 when(options.color).thenReturn(false);
35
36 reporter = new HumanErrorFormatter(out, options, stats);
23 }); 37 });
24 38
25 tearDown(() { 39 tearDown(() {
26 out.clear();
27 ansi.runningTests = false; 40 ansi.runningTests = false;
28 }); 41 });
29 42
30 // Options
31 var options = new MockCommandLineOptions();
32 when(options.enableTypeChecks).thenReturn(false);
33 when(options.hintsAreFatal).thenReturn(false);
34 when(options.machineFormat).thenReturn(false);
35 when(options.verbose).thenReturn(false);
36 when(options.color).thenReturn(false);
37
38 var reporter = new ErrorFormatter(out, options, stats);
39
40 test('error', () { 43 test('error', () {
41 var error = mockError(ErrorType.SYNTACTIC_ERROR, ErrorSeverity.ERROR); 44 AnalysisErrorInfo error =
45 mockError(ErrorType.SYNTACTIC_ERROR, ErrorSeverity.ERROR);
42 reporter.formatErrors([error]); 46 reporter.formatErrors([error]);
47 reporter.flush();
43 48
44 expect(out.toString().trim(), 49 expect(out.toString().trim(),
45 'error • MSG at /foo/bar/baz.dart:3:3 • mock_code'); 50 'error • MSG at /foo/bar/baz.dart:3:3 • mock_code');
46 }); 51 });
47 52
48 test('hint', () { 53 test('hint', () {
49 var error = mockError(ErrorType.HINT, ErrorSeverity.INFO); 54 AnalysisErrorInfo error = mockError(ErrorType.HINT, ErrorSeverity.INFO);
50 reporter.formatErrors([error]); 55 reporter.formatErrors([error]);
56 reporter.flush();
51 57
52 expect(out.toString().trim(), 58 expect(out.toString().trim(),
53 'hint • MSG at /foo/bar/baz.dart:3:3 • mock_code'); 59 'hint • MSG at /foo/bar/baz.dart:3:3 • mock_code');
54 }); 60 });
55 61
56 test('stats', () { 62 test('stats', () {
57 var error = mockError(ErrorType.HINT, ErrorSeverity.INFO); 63 AnalysisErrorInfo error = mockError(ErrorType.HINT, ErrorSeverity.INFO);
58 reporter.formatErrors([error]); 64 reporter.formatErrors([error]);
65 reporter.flush();
59 stats.print(out); 66 stats.print(out);
60 expect( 67 expect(
61 out.toString().trim(), 68 out.toString().trim(),
62 'hint • MSG at /foo/bar/baz.dart:3:3 • mock_code\n' 69 'hint • MSG at /foo/bar/baz.dart:3:3 • mock_code\n'
63 '1 hint found.'); 70 '1 hint found.');
64 }); 71 });
65 }); 72 });
66 } 73 }
67 74
68 MockAnalysisErrorInfo mockError(ErrorType type, ErrorSeverity severity) { 75 MockAnalysisErrorInfo mockError(ErrorType type, ErrorSeverity severity) {
69 // ErrorInfo 76 // ErrorInfo
70 var info = new MockAnalysisErrorInfo(); 77 var info = new MockAnalysisErrorInfo();
71 var error = new MockAnalysisError(); 78 var error = new MockAnalysisError();
72 var lineInfo = new MockLineInfo(); 79 var lineInfo = new MockLineInfo();
73 var location = new MockLineInfo_Location(); 80 var location = new MockLineInfo_Location();
74 when(location.columnNumber).thenReturn(3); 81 when(location.columnNumber).thenReturn(3);
75 when(location.lineNumber).thenReturn(3); 82 when(location.lineNumber).thenReturn(3);
76 when(lineInfo.getLocation(anyObject)).thenReturn(location); 83 when(lineInfo.getLocation(anyObject)).thenReturn(location);
77 when(info.lineInfo).thenReturn(lineInfo); 84 when(info.lineInfo).thenReturn(lineInfo);
78 85
79 // Details 86 // Details
80 var code = new MockErrorCode(); 87 var code = new MockErrorCode();
81 when(code.type).thenReturn(type); 88 when(code.type).thenReturn(type);
82 when(code.errorSeverity).thenReturn(severity); 89 when(code.errorSeverity).thenReturn(severity);
83 when(code.name).thenReturn('mock_code'); 90 when(code.name).thenReturn('mock_code');
84 when(error.errorCode).thenReturn(code); 91 when(error.errorCode).thenReturn(code);
85 when(error.message).thenReturn('MSG'); 92 when(error.message).thenReturn('MSG');
93 when(error.offset).thenReturn(20);
86 var source = new MockSource(); 94 var source = new MockSource();
87 when(source.fullName).thenReturn('/foo/bar/baz.dart'); 95 when(source.fullName).thenReturn('/foo/bar/baz.dart');
88 when(error.source).thenReturn(source); 96 when(error.source).thenReturn(source);
89 when(info.errors).thenReturn([error]); 97 when(info.errors).thenReturn([error]);
90 98
91 return info; 99 return info;
92 } 100 }
OLDNEW
« no previous file with comments | « pkg/analyzer_cli/test/errors_reported_once_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698