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

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

Issue 2559523005: Remove the AnalysisOptionsProcessor (Closed)
Patch Set: Created 4 years 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
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:io'; 7 import 'dart:io';
8 8
9 import 'package:analyzer/error/error.dart'; 9 import 'package:analyzer/error/error.dart';
10 import 'package:analyzer/plugin/options.dart';
11 import 'package:analyzer/source/analysis_options_provider.dart'; 10 import 'package:analyzer/source/analysis_options_provider.dart';
12 import 'package:analyzer/source/error_processor.dart'; 11 import 'package:analyzer/source/error_processor.dart';
13 import 'package:analyzer/src/error/codes.dart'; 12 import 'package:analyzer/src/error/codes.dart';
14 import 'package:analyzer/src/generated/engine.dart'; 13 import 'package:analyzer/src/generated/engine.dart';
15 import 'package:analyzer/src/generated/source.dart'; 14 import 'package:analyzer/src/generated/source.dart';
16 import 'package:analyzer/src/services/lint.dart'; 15 import 'package:analyzer/src/services/lint.dart';
17 import 'package:analyzer_cli/src/driver.dart'; 16 import 'package:analyzer_cli/src/driver.dart';
18 import 'package:analyzer_cli/src/options.dart'; 17 import 'package:analyzer_cli/src/options.dart';
19 import 'package:path/path.dart' as path; 18 import 'package:path/path.dart' as path;
20 import 'package:plugin/plugin.dart';
21 import 'package:test/test.dart'; 19 import 'package:test/test.dart';
22 import 'package:yaml/src/yaml_node.dart'; 20 import 'package:yaml/src/yaml_node.dart';
23 21
24 import 'utils.dart'; 22 import 'utils.dart';
25 23
26 main() { 24 main() {
27 StringSink savedOutSink, savedErrorSink; 25 StringSink savedOutSink, savedErrorSink;
28 int savedExitCode; 26 int savedExitCode;
29 ExitHandler savedExitHandler; 27 ExitHandler savedExitHandler;
30 28
(...skipping 15 matching lines...) Expand all
46 exitCode = savedExitCode; 44 exitCode = savedExitCode;
47 exitHandler = savedExitHandler; 45 exitHandler = savedExitHandler;
48 } 46 }
49 47
50 setUp(() => _setUp()); 48 setUp(() => _setUp());
51 49
52 tearDown(() => _tearDown()); 50 tearDown(() => _tearDown());
53 51
54 group('Driver', () { 52 group('Driver', () {
55 group('options', () { 53 group('options', () {
56 test('custom processor', () {
57 Driver driver = new Driver();
58 TestProcessor processor = new TestProcessor();
59 driver.userDefinedPlugins = [new TestPlugin(processor)];
60 driver.start([
61 '--options',
62 path.join(testDirectory, 'data/test_options.yaml'),
63 path.join(testDirectory, 'data/test_file.dart')
64 ]);
65 expect(processor.options['test_plugin'], isNotNull);
66 expect(processor.exception, isNull);
67 });
68 test('todos', () { 54 test('todos', () {
69 drive('data/file_with_todo.dart'); 55 drive('data/file_with_todo.dart');
70 expect(outSink.toString().contains('[info]'), isFalse); 56 expect(outSink.toString().contains('[info]'), isFalse);
71 }); 57 });
72 }); 58 });
73 59
74 group('exit codes', () { 60 group('exit codes', () {
75 test('fatal hints', () { 61 test('fatal hints', () {
76 drive('data/file_with_hint.dart', args: ['--fatal-hints']); 62 drive('data/file_with_hint.dart', args: ['--fatal-hints']);
77 expect(exitCode, 3); 63 expect(exitCode, 3);
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 throw new Exception('Could not find an SDK directory containing summaries.' 500 throw new Exception('Could not find an SDK directory containing summaries.'
515 ' Tried: ${triedDirectories.toList()}'); 501 ' Tried: ${triedDirectories.toList()}');
516 } 502 }
517 503
518 Map<String, YamlNode> parseOptions(String src) => 504 Map<String, YamlNode> parseOptions(String src) =>
519 new AnalysisOptionsProvider().getOptionsFromString(src); 505 new AnalysisOptionsProvider().getOptionsFromString(src);
520 506
521 ErrorProcessor processorFor(AnalysisError error) => 507 ErrorProcessor processorFor(AnalysisError error) =>
522 processors.firstWhere((p) => p.appliesTo(error)); 508 processors.firstWhere((p) => p.appliesTo(error));
523 509
524 class TestPlugin extends Plugin {
525 TestProcessor processor;
526 TestPlugin(this.processor);
527
528 @override
529 String get uniqueIdentifier => 'test_plugin.core';
530
531 @override
532 void registerExtensionPoints(RegisterExtensionPoint register) {
533 // None
534 }
535
536 @override
537 void registerExtensions(RegisterExtension register) {
538 register(OPTIONS_PROCESSOR_EXTENSION_POINT_ID, processor);
539 }
540 }
541
542 class TestProcessor extends OptionsProcessor {
543 Map<String, Object> options;
544 Exception exception;
545
546 @override
547 void onError(Exception exception) {
548 this.exception = exception;
549 }
550
551 @override
552 void optionsProcessed(AnalysisContext context, Map<String, Object> options) {
553 this.options = options;
554 }
555 }
556
557 class TestSource implements Source { 510 class TestSource implements Source {
558 TestSource(); 511 TestSource();
559 512
560 @override 513 @override
561 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 514 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
562 } 515 }
OLDNEW
« no previous file with comments | « pkg/analyzer_cli/test/boot_loader_test.dart ('k') | pkg/analyzer_cli/test/plugin_manager_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698