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

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

Issue 2775633002: Use ansi color in the dartanalyzer cli output. (Closed)
Patch Set: make tests more robust Created 3 years, 9 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/lib/src/options.dart ('k') | pkg/analyzer_cli/test/reporter_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.driver; 5 library analyzer_cli.test.driver;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:io'; 8 import 'dart:io';
9 9
10 import 'package:analyzer/error/error.dart'; 10 import 'package:analyzer/error/error.dart';
11 import 'package:analyzer/source/analysis_options_provider.dart'; 11 import 'package:analyzer/source/analysis_options_provider.dart';
12 import 'package:analyzer/source/error_processor.dart'; 12 import 'package:analyzer/source/error_processor.dart';
13 import 'package:analyzer/src/error/codes.dart'; 13 import 'package:analyzer/src/error/codes.dart';
14 import 'package:analyzer/src/generated/engine.dart'; 14 import 'package:analyzer/src/generated/engine.dart';
15 import 'package:analyzer/src/generated/source.dart'; 15 import 'package:analyzer/src/generated/source.dart';
16 import 'package:analyzer/src/services/lint.dart'; 16 import 'package:analyzer/src/services/lint.dart';
17 import 'package:analyzer_cli/src/ansi.dart' as ansi;
17 import 'package:analyzer_cli/src/driver.dart'; 18 import 'package:analyzer_cli/src/driver.dart';
18 import 'package:analyzer_cli/src/options.dart'; 19 import 'package:analyzer_cli/src/options.dart';
19 import 'package:cli_util/cli_util.dart' show getSdkDir; 20 import 'package:cli_util/cli_util.dart' show getSdkDir;
20 import 'package:path/path.dart' as path; 21 import 'package:path/path.dart' as path;
21 import 'package:test/test.dart'; 22 import 'package:test/test.dart';
22 import 'package:yaml/src/yaml_node.dart'; 23 import 'package:yaml/src/yaml_node.dart';
23 24
24 import 'utils.dart'; 25 import 'utils.dart';
25 26
26 main() { 27 main() {
27 StringSink savedOutSink, savedErrorSink; 28 StringSink savedOutSink, savedErrorSink;
28 int savedExitCode; 29 int savedExitCode;
29 ExitHandler savedExitHandler; 30 ExitHandler savedExitHandler;
30 31
31 /// Base setup. 32 /// Base setup.
32 _setUp() { 33 _setUp() {
34 ansi.runningTests = true;
33 savedOutSink = outSink; 35 savedOutSink = outSink;
34 savedErrorSink = errorSink; 36 savedErrorSink = errorSink;
35 savedExitHandler = exitHandler; 37 savedExitHandler = exitHandler;
36 savedExitCode = exitCode; 38 savedExitCode = exitCode;
37 exitHandler = (code) => exitCode = code; 39 exitHandler = (code) => exitCode = code;
38 outSink = new StringBuffer(); 40 outSink = new StringBuffer();
39 errorSink = new StringBuffer(); 41 errorSink = new StringBuffer();
40 } 42 }
41 43
42 /// Base teardown. 44 /// Base teardown.
43 _tearDown() { 45 _tearDown() {
44 outSink = savedOutSink; 46 outSink = savedOutSink;
45 errorSink = savedErrorSink; 47 errorSink = savedErrorSink;
46 exitCode = savedExitCode; 48 exitCode = savedExitCode;
47 exitHandler = savedExitHandler; 49 exitHandler = savedExitHandler;
50 ansi.runningTests = false;
48 } 51 }
49 52
50 setUp(() => _setUp()); 53 setUp(() => _setUp());
51 54
52 tearDown(() => _tearDown()); 55 tearDown(() => _tearDown());
53 56
54 group('Driver', () { 57 group('Driver', () {
55 group('options', () { 58 group('options', () {
56 test('todos', () async { 59 test('todos', () async {
57 await drive('data/file_with_todo.dart'); 60 await drive('data/file_with_todo.dart');
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 /// Lints should be enabled. 172 /// Lints should be enabled.
170 expect(driver.context.analysisOptions.lint, isTrue); 173 expect(driver.context.analysisOptions.lint, isTrue);
171 174
172 /// The analysis options file only specifies 'camel_case_types'. 175 /// The analysis options file only specifies 'camel_case_types'.
173 var lintNames = getLints(driver.context).map((r) => r.name); 176 var lintNames = getLints(driver.context).map((r) => r.name);
174 expect(lintNames, orderedEquals(['camel_case_types'])); 177 expect(lintNames, orderedEquals(['camel_case_types']));
175 }); 178 });
176 179
177 test('generates lints', () async { 180 test('generates lints', () async {
178 await runLinter(); 181 await runLinter();
179 expect(outSink.toString(), 182 expect(_bulletToDash(outSink),
180 contains('[lint] Name types using UpperCamelCase')); 183 contains('lint - Name types using UpperCamelCase'));
181 }); 184 });
182 }); 185 });
183 186
184 group('default lints - $designator', () { 187 group('default lints - $designator', () {
185 // Shared lint command. 188 // Shared lint command.
186 Future<Null> runLinter() async { 189 Future<Null> runLinter() async {
187 return await drive('data/linter_project/test_file.dart', 190 return await drive('data/linter_project/test_file.dart',
188 options: 'data/linter_project/$optionsFileName', 191 options: 'data/linter_project/$optionsFileName',
189 args: ['--lints']); 192 args: ['--lints']);
190 } 193 }
191 194
192 test('gets default lints', () async { 195 test('gets default lints', () async {
193 await runLinter(); 196 await runLinter();
194 197
195 /// Lints should be enabled. 198 /// Lints should be enabled.
196 expect(driver.context.analysisOptions.lint, isTrue); 199 expect(driver.context.analysisOptions.lint, isTrue);
197 200
198 /// Default list should include camel_case_types. 201 /// Default list should include camel_case_types.
199 var lintNames = getLints(driver.context).map((r) => r.name); 202 var lintNames = getLints(driver.context).map((r) => r.name);
200 expect(lintNames, contains('camel_case_types')); 203 expect(lintNames, contains('camel_case_types'));
201 }); 204 });
202 205
203 test('generates lints', () async { 206 test('generates lints', () async {
204 await runLinter(); 207 await runLinter();
205 expect(outSink.toString(), 208 expect(_bulletToDash(outSink),
206 contains('[lint] Name types using UpperCamelCase')); 209 contains('lint - Name types using UpperCamelCase'));
207 }); 210 });
208 }); 211 });
209 212
210 group('no `--lints` flag (none in options) - $designator', () { 213 group('no `--lints` flag (none in options) - $designator', () {
211 // Shared lint command. 214 // Shared lint command.
212 Future<Null> runLinter() async { 215 Future<Null> runLinter() async {
213 return await drive('data/no_lints_project/test_file.dart', 216 return await drive('data/no_lints_project/test_file.dart',
214 options: 'data/no_lints_project/$optionsFileName'); 217 options: 'data/no_lints_project/$optionsFileName');
215 } 218 }
216 219
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 ]); 283 ]);
281 expect(processorFor(unused_local_variable).severity, isNull); 284 expect(processorFor(unused_local_variable).severity, isNull);
282 285
283 // missing_return: error 286 // missing_return: error
284 var missing_return = new AnalysisError( 287 var missing_return = new AnalysisError(
285 new TestSource(), 0, 1, HintCode.MISSING_RETURN, [ 288 new TestSource(), 0, 1, HintCode.MISSING_RETURN, [
286 ['x'] 289 ['x']
287 ]); 290 ]);
288 expect(processorFor(missing_return).severity, ErrorSeverity.ERROR); 291 expect(processorFor(missing_return).severity, ErrorSeverity.ERROR);
289 expect( 292 expect(
290 outSink.toString(), 293 _bulletToDash(outSink),
291 contains( 294 contains(
292 "[error] This function declares a return type of 'int'")); 295 "error - This function declares a return type of 'int'"));
293 expect( 296 expect(
294 outSink.toString(), contains("1 error and 1 warning found.")); 297 outSink.toString(), contains("1 error and 1 warning found."));
295 }); 298 });
296 299
297 test('language', () async { 300 test('language', () async {
298 await doDrive(); 301 await doDrive();
299 expect(driver.context.analysisOptions.enableSuperMixins, isTrue); 302 expect(driver.context.analysisOptions.enableSuperMixins, isTrue);
300 }); 303 });
301 304
302 test('strongMode', () async { 305 test('strongMode', () async {
(...skipping 17 matching lines...) Expand all
320 test('override fatal warning', () async { 323 test('override fatal warning', () async {
321 await doDrive(); 324 await doDrive();
322 // missing_return: error 325 // missing_return: error
323 var undefined_function = new AnalysisError(new TestSource(), 0, 1, 326 var undefined_function = new AnalysisError(new TestSource(), 0, 1,
324 StaticTypeWarningCode.UNDEFINED_FUNCTION, [ 327 StaticTypeWarningCode.UNDEFINED_FUNCTION, [
325 ['x'] 328 ['x']
326 ]); 329 ]);
327 expect(processorFor(undefined_function).severity, 330 expect(processorFor(undefined_function).severity,
328 ErrorSeverity.WARNING); 331 ErrorSeverity.WARNING);
329 // Should not be made fatal by `--fatal-warnings`. 332 // Should not be made fatal by `--fatal-warnings`.
330 expect(outSink.toString(), 333 expect(_bulletToDash(outSink),
331 contains("[warning] The function 'baz' isn't defined")); 334 contains("warning - The function 'baz' isn't defined"));
332 expect( 335 expect(
333 outSink.toString(), contains("1 error and 1 warning found.")); 336 outSink.toString(), contains("1 error and 1 warning found."));
334 }); 337 });
335 }); 338 });
336 } 339 }
337 340
338 createTests('old', AnalysisEngine.ANALYSIS_OPTIONS_FILE); 341 createTests('old', AnalysisEngine.ANALYSIS_OPTIONS_FILE);
339 createTests('new', AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE); 342 createTests('new', AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE);
340 343
341 test('include directive', () async { 344 test('include directive', () async {
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 564
562 ErrorProcessor processorFor(AnalysisError error) => 565 ErrorProcessor processorFor(AnalysisError error) =>
563 processors.firstWhere((p) => p.appliesTo(error)); 566 processors.firstWhere((p) => p.appliesTo(error));
564 567
565 class TestSource implements Source { 568 class TestSource implements Source {
566 TestSource(); 569 TestSource();
567 570
568 @override 571 @override
569 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 572 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
570 } 573 }
574
575 /// Normalize text with bullets.
576 String _bulletToDash(item) => '$item'.replaceAll('•', '-');
OLDNEW
« no previous file with comments | « pkg/analyzer_cli/lib/src/options.dart ('k') | pkg/analyzer_cli/test/reporter_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698