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

Side by Side Diff: pkg/analyzer/test/src/context/builder_test.dart

Issue 2286923002: Convert analysis server over to use ContextBuilder (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 3 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
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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.test.src.context.context_builder_test; 5 library analyzer.test.src.context.context_builder_test;
6 6
7 import 'package:analyzer/file_system/file_system.dart'; 7 import 'package:analyzer/file_system/file_system.dart';
8 import 'package:analyzer/file_system/memory_file_system.dart'; 8 import 'package:analyzer/file_system/memory_file_system.dart';
9 import 'package:analyzer/plugin/options.dart';
9 import 'package:analyzer/source/package_map_resolver.dart'; 10 import 'package:analyzer/source/package_map_resolver.dart';
10 import 'package:analyzer/src/context/builder.dart'; 11 import 'package:analyzer/src/context/builder.dart';
11 import 'package:analyzer/src/context/source.dart'; 12 import 'package:analyzer/src/context/source.dart';
12 import 'package:analyzer/src/generated/engine.dart'; 13 import 'package:analyzer/src/generated/engine.dart';
13 import 'package:analyzer/src/generated/sdk.dart'; 14 import 'package:analyzer/src/generated/sdk.dart';
14 import 'package:analyzer/src/generated/source.dart'; 15 import 'package:analyzer/src/generated/source.dart';
16 import 'package:analyzer/src/plugin/options_plugin.dart';
15 import 'package:package_config/packages.dart'; 17 import 'package:package_config/packages.dart';
16 import 'package:package_config/src/packages_impl.dart'; 18 import 'package:package_config/src/packages_impl.dart';
17 import 'package:path/path.dart' as path; 19 import 'package:path/path.dart' as path;
20 import 'package:plugin/src/plugin_impl.dart';
18 import 'package:unittest/unittest.dart'; 21 import 'package:unittest/unittest.dart';
19 22
20 import '../../embedder_tests.dart'; 23 import '../../embedder_tests.dart';
21 import '../../generated/test_support.dart'; 24 import '../../generated/test_support.dart';
22 import '../../reflective_tests.dart'; 25 import '../../reflective_tests.dart';
23 import '../../utils.dart'; 26 import '../../utils.dart';
24 import 'mock_sdk.dart'; 27 import 'mock_sdk.dart';
25 28
26 main() { 29 main() {
27 initializeTestEnvironment(); 30 initializeTestEnvironment();
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 String path = '/some/directory/path'; 481 String path = '/some/directory/path';
479 String filePath = '$path/${AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE}'; 482 String filePath = '$path/${AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE}';
480 resourceProvider.newFile( 483 resourceProvider.newFile(
481 filePath, 484 filePath,
482 ''' 485 '''
483 linter: 486 linter:
484 rules: 487 rules:
485 - empty_constructor_bodies 488 - empty_constructor_bodies
486 '''); 489 ''');
487 490
488 AnalysisOptions options = builder.getAnalysisOptions(path); 491 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext();
492 AnalysisOptions options = builder.getAnalysisOptions(context, path);
489 _expectEqualOptions(options, expected); 493 _expectEqualOptions(options, expected);
490 } 494 }
491 495
492 void test_getAnalysisOptions_default_overrides() { 496 void test_getAnalysisOptions_default_overrides() {
493 AnalysisOptionsImpl defaultOptions = new AnalysisOptionsImpl(); 497 AnalysisOptionsImpl defaultOptions = new AnalysisOptionsImpl();
494 defaultOptions.enableGenericMethods = true; 498 defaultOptions.enableGenericMethods = true;
495 builder.defaultOptions = defaultOptions; 499 builder.defaultOptions = defaultOptions;
496 AnalysisOptionsImpl expected = new AnalysisOptionsImpl(); 500 AnalysisOptionsImpl expected = new AnalysisOptionsImpl();
497 expected.enableAsync = true; 501 expected.enableAsync = true;
498 expected.enableGenericMethods = true; 502 expected.enableGenericMethods = true;
499 String path = '/some/directory/path'; 503 String path = '/some/directory/path';
500 String filePath = '$path/${AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE}'; 504 String filePath = '$path/${AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE}';
501 resourceProvider.newFile( 505 resourceProvider.newFile(
502 filePath, 506 filePath,
503 ''' 507 '''
504 analyzer: 508 analyzer:
505 enableAsync : true 509 enableAsync : true
506 '''); 510 ''');
507 511
508 AnalysisOptions options = builder.getAnalysisOptions(path); 512 AnalysisEngine engine = AnalysisEngine.instance;
509 _expectEqualOptions(options, expected); 513 OptionsPlugin plugin = engine.optionsPlugin;
514 plugin.registerExtensionPoints((_) {});
515 try {
516 _TestOptionsProcessor processor = new _TestOptionsProcessor();
517 processor.expectedOptions = <String, Object>{
518 'analyzer': {'enableAsync': true}
519 };
520 (plugin.optionsProcessorExtensionPoint as ExtensionPointImpl)
521 .add(processor);
522 AnalysisContext context = engine.createAnalysisContext();
523 AnalysisOptions options = builder.getAnalysisOptions(context, path);
524 _expectEqualOptions(options, expected);
525 } finally {
526 plugin.registerExtensionPoints((_) {});
527 }
528 }
529
530 void test_getAnalysisOptions_invalid() {
531 String path = '/some/directory/path';
532 String filePath = '$path/${AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE}';
533 resourceProvider.newFile(filePath, ';');
534
535 AnalysisEngine engine = AnalysisEngine.instance;
536 OptionsPlugin plugin = engine.optionsPlugin;
537 plugin.registerExtensionPoints((_) {});
538 try {
539 _TestOptionsProcessor processor = new _TestOptionsProcessor();
540 (plugin.optionsProcessorExtensionPoint as ExtensionPointImpl)
541 .add(processor);
542 AnalysisContext context = engine.createAnalysisContext();
543 AnalysisOptions options = builder.getAnalysisOptions(context, path);
544 expect(options, isNotNull);
545 expect(processor.errorCount, 1);
546 } finally {
547 plugin.registerExtensionPoints((_) {});
548 }
510 } 549 }
511 550
512 void test_getAnalysisOptions_noDefault_noOverrides() { 551 void test_getAnalysisOptions_noDefault_noOverrides() {
513 String path = '/some/directory/path'; 552 String path = '/some/directory/path';
514 String filePath = '$path/${AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE}'; 553 String filePath = '$path/${AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE}';
515 resourceProvider.newFile( 554 resourceProvider.newFile(
516 filePath, 555 filePath,
517 ''' 556 '''
518 linter: 557 linter:
519 rules: 558 rules:
520 - empty_constructor_bodies 559 - empty_constructor_bodies
521 '''); 560 ''');
522 561
523 AnalysisOptions options = builder.getAnalysisOptions(path); 562 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext();
563 AnalysisOptions options = builder.getAnalysisOptions(context, path);
524 _expectEqualOptions(options, new AnalysisOptionsImpl()); 564 _expectEqualOptions(options, new AnalysisOptionsImpl());
525 } 565 }
526 566
527 void test_getAnalysisOptions_noDefault_overrides() { 567 void test_getAnalysisOptions_noDefault_overrides() {
528 AnalysisOptionsImpl expected = new AnalysisOptionsImpl(); 568 AnalysisOptionsImpl expected = new AnalysisOptionsImpl();
529 expected.enableAsync = true; 569 expected.enableAsync = true;
530 String path = '/some/directory/path'; 570 String path = '/some/directory/path';
531 String filePath = '$path/${AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE}'; 571 String filePath = '$path/${AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE}';
532 resourceProvider.newFile( 572 resourceProvider.newFile(
533 filePath, 573 filePath,
534 ''' 574 '''
535 analyzer: 575 analyzer:
536 enableAsync : true 576 enableAsync : true
537 '''); 577 ''');
538 578
539 AnalysisOptions options = builder.getAnalysisOptions(path); 579 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext();
580 AnalysisOptions options = builder.getAnalysisOptions(context, path);
540 _expectEqualOptions(options, expected); 581 _expectEqualOptions(options, expected);
541 } 582 }
542 583
543 void test_getOptionsFile_explicit() { 584 void test_getOptionsFile_explicit() {
544 String path = '/some/directory/path'; 585 String path = '/some/directory/path';
545 String filePath = '/options/analysis.yaml'; 586 String filePath = '/options/analysis.yaml';
546 resourceProvider.newFile(filePath, ''); 587 resourceProvider.newFile(filePath, '');
547 588
548 builder.defaultAnalysisOptionsFilePath = filePath; 589 builder.defaultAnalysisOptionsFilePath = filePath;
549 File result = builder.getOptionsFile(path); 590 File result = builder.getOptionsFile(path);
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 expect(locator.embedderYamls, hasLength(0)); 685 expect(locator.embedderYamls, hasLength(0));
645 } 686 }
646 687
647 void test_valid() { 688 void test_valid() {
648 EmbedderYamlLocator locator = new EmbedderYamlLocator({ 689 EmbedderYamlLocator locator = new EmbedderYamlLocator({
649 'fox': [pathTranslator.getResource('/tmp')] 690 'fox': [pathTranslator.getResource('/tmp')]
650 }); 691 });
651 expect(locator.embedderYamls, hasLength(1)); 692 expect(locator.embedderYamls, hasLength(1));
652 } 693 }
653 } 694 }
695
696 class _TestOptionsProcessor implements OptionsProcessor {
697 Map<String, Object> expectedOptions = null;
698
699 int errorCount = 0;
700
701 @override
702 void onError(Exception exception) {
703 errorCount++;
704 }
705
706 @override
707 void optionsProcessed(AnalysisContext context, Map<String, Object> options) {
708 if (expectedOptions == null) {
709 fail('Unexpected invocation of optionsProcessed');
710 }
711 expect(options, hasLength(expectedOptions.length));
712 for (String key in expectedOptions.keys) {
713 expect(options.containsKey(key), isTrue, reason: 'missing key $key');
714 expect(options[key], expectedOptions[key],
715 reason: 'values for key $key do not match');
716 }
717 }
718 }
OLDNEW
« pkg/analysis_server/lib/src/analysis_server.dart ('K') | « pkg/analyzer/lib/src/dart/sdk/sdk.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698