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

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

Issue 2775633002: Use ansi color in the dartanalyzer cli output. (Closed)
Patch Set: make tests more robust 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/driver_test.dart ('k') | pkg/analyzer_cli/test/super_mixin_test.dart » ('j') | 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_cli/src/ansi.dart' as ansi;
8 import 'package:analyzer_cli/src/error_formatter.dart'; 9 import 'package:analyzer_cli/src/error_formatter.dart';
9 import 'package:test/test.dart' hide ErrorFormatter; 10 import 'package:test/test.dart' hide ErrorFormatter;
10 import 'package:typed_mock/typed_mock.dart'; 11 import 'package:typed_mock/typed_mock.dart';
11 12
12 import 'mocks.dart'; 13 import 'mocks.dart';
13 14
14 main() { 15 main() {
15 group('reporter', () { 16 group('reporter', () {
16 var out = new StringBuffer(); 17 var out = new StringBuffer();
17 var stats = new AnalysisStats(); 18 var stats = new AnalysisStats();
18 19
19 setUp(() => stats.init()); 20 setUp(() {
20 tearDown(() => out.clear()); 21 ansi.runningTests = true;
22 stats.init();
23 });
24
25 tearDown(() {
26 out.clear();
27 ansi.runningTests = false;
28 });
21 29
22 // Options 30 // Options
23 var options = new MockCommandLineOptions(); 31 var options = new MockCommandLineOptions();
24 when(options.enableTypeChecks).thenReturn(false); 32 when(options.enableTypeChecks).thenReturn(false);
25 when(options.hintsAreFatal).thenReturn(false); 33 when(options.hintsAreFatal).thenReturn(false);
26 when(options.machineFormat).thenReturn(false); 34 when(options.machineFormat).thenReturn(false);
27 when(options.verbose).thenReturn(false); 35 when(options.verbose).thenReturn(false);
28 36
29 var reporter = new ErrorFormatter(out, options, stats); 37 var reporter = new ErrorFormatter(out, options, stats);
30 38
31 test('error', () { 39 test('error', () {
32 var error = mockError(ErrorType.SYNTACTIC_ERROR, ErrorSeverity.ERROR); 40 var error = mockError(ErrorType.SYNTACTIC_ERROR, ErrorSeverity.ERROR);
33 reporter.formatErrors([error]); 41 reporter.formatErrors([error]);
34 42
35 expect(out.toString().trim(), 43 expect(out.toString().trim(),
36 '[error] MSG at /foo/bar/baz.dart:3:3 (mock_code).'); 44 'error MSG at /foo/bar/baz.dart:3:3 mock_code');
37 }); 45 });
38 46
39 test('hint', () { 47 test('hint', () {
40 var error = mockError(ErrorType.HINT, ErrorSeverity.INFO); 48 var error = mockError(ErrorType.HINT, ErrorSeverity.INFO);
41 reporter.formatErrors([error]); 49 reporter.formatErrors([error]);
42 50
43 expect(out.toString().trim(), 51 expect(out.toString().trim(),
44 '[hint] MSG at /foo/bar/baz.dart:3:3 (mock_code).'); 52 'hint MSG at /foo/bar/baz.dart:3:3 mock_code');
45 }); 53 });
46 54
47 test('stats', () { 55 test('stats', () {
48 var error = mockError(ErrorType.HINT, ErrorSeverity.INFO); 56 var error = mockError(ErrorType.HINT, ErrorSeverity.INFO);
49 reporter.formatErrors([error]); 57 reporter.formatErrors([error]);
50 stats.print(out); 58 stats.print(out);
51 expect( 59 expect(
52 out.toString().trim(), 60 out.toString().trim(),
53 '[hint] MSG at /foo/bar/baz.dart:3:3 (mock_code).\n' 61 'hint MSG at /foo/bar/baz.dart:3:3 mock_code\n'
54 '1 hint found.'); 62 '1 hint found.');
55 }); 63 });
56 }); 64 });
57 } 65 }
58 66
59 MockAnalysisErrorInfo mockError(ErrorType type, ErrorSeverity severity) { 67 MockAnalysisErrorInfo mockError(ErrorType type, ErrorSeverity severity) {
60 // ErrorInfo 68 // ErrorInfo
61 var info = new MockAnalysisErrorInfo(); 69 var info = new MockAnalysisErrorInfo();
62 var error = new MockAnalysisError(); 70 var error = new MockAnalysisError();
63 var lineInfo = new MockLineInfo(); 71 var lineInfo = new MockLineInfo();
(...skipping 10 matching lines...) Expand all
74 when(code.name).thenReturn('mock_code'); 82 when(code.name).thenReturn('mock_code');
75 when(error.errorCode).thenReturn(code); 83 when(error.errorCode).thenReturn(code);
76 when(error.message).thenReturn('MSG'); 84 when(error.message).thenReturn('MSG');
77 var source = new MockSource(); 85 var source = new MockSource();
78 when(source.fullName).thenReturn('/foo/bar/baz.dart'); 86 when(source.fullName).thenReturn('/foo/bar/baz.dart');
79 when(error.source).thenReturn(source); 87 when(error.source).thenReturn(source);
80 when(info.errors).thenReturn([error]); 88 when(info.errors).thenReturn([error]);
81 89
82 return info; 90 return info;
83 } 91 }
OLDNEW
« no previous file with comments | « pkg/analyzer_cli/test/driver_test.dart ('k') | pkg/analyzer_cli/test/super_mixin_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698