| OLD | NEW |
| 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 'dart:io' as io; | 7 import 'dart:io' as io; |
| 8 | 8 |
| 9 import 'package:analyzer/file_system/file_system.dart'; | 9 import 'package:analyzer/file_system/file_system.dart'; |
| 10 import 'package:analyzer/file_system/memory_file_system.dart'; | 10 import 'package:analyzer/file_system/memory_file_system.dart'; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 | 91 |
| 92 @override | 92 @override |
| 93 void setUp() { | 93 void setUp() { |
| 94 resourceProvider = PhysicalResourceProvider.INSTANCE; | 94 resourceProvider = PhysicalResourceProvider.INSTANCE; |
| 95 pathContext = resourceProvider.pathContext; | 95 pathContext = resourceProvider.pathContext; |
| 96 sdkManager = new DartSdkManager('', false, (_) => new MockSdk()); | 96 sdkManager = new DartSdkManager('', false, (_) => new MockSdk()); |
| 97 contentCache = new ContentCache(); | 97 contentCache = new ContentCache(); |
| 98 builder = new ContextBuilder(resourceProvider, sdkManager, contentCache); | 98 builder = new ContextBuilder(resourceProvider, sdkManager, contentCache); |
| 99 } | 99 } |
| 100 | 100 |
| 101 @failingTest |
| 102 void test_buildContext() { |
| 103 fail('Incomplete test'); |
| 104 } |
| 105 |
| 101 void test_createPackageMap_fromPackageDirectory_explicit() { | 106 void test_createPackageMap_fromPackageDirectory_explicit() { |
| 102 withTempDir((io.Directory tempDir) { | 107 withTempDir((io.Directory tempDir) { |
| 103 // Use a package directory that is outside the project directory. | 108 // Use a package directory that is outside the project directory. |
| 104 String rootPath = tempDir.path; | 109 String rootPath = tempDir.path; |
| 105 String projectPath = pathContext.join(rootPath, 'project'); | 110 String projectPath = pathContext.join(rootPath, 'project'); |
| 106 String packageDirPath = pathContext.join(rootPath, 'packages'); | 111 String packageDirPath = pathContext.join(rootPath, 'packages'); |
| 107 String fooName = 'foo'; | 112 String fooName = 'foo'; |
| 108 String fooPath = pathContext.join(packageDirPath, fooName); | 113 String fooPath = pathContext.join(packageDirPath, fooName); |
| 109 String barName = 'bar'; | 114 String barName = 'bar'; |
| 110 String barPath = pathContext.join(packageDirPath, barName); | 115 String barPath = pathContext.join(packageDirPath, barName); |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 expect(packageSource, isNotNull); | 344 expect(packageSource, isNotNull); |
| 340 expect(packageSource.fullName, pathContext.join(packageA, 'a.dart')); | 345 expect(packageSource.fullName, pathContext.join(packageA, 'a.dart')); |
| 341 }); | 346 }); |
| 342 } | 347 } |
| 343 | 348 |
| 344 @failingTest | 349 @failingTest |
| 345 void test_createSourceFactory_provider() { | 350 void test_createSourceFactory_provider() { |
| 346 fail('Incomplete test'); | 351 fail('Incomplete test'); |
| 347 } | 352 } |
| 348 | 353 |
| 354 @failingTest |
| 355 void test_findSdk_embedder_extensions() { |
| 356 // See test_createSourceFactory_noProvider_packages_embedder_extensions |
| 357 fail('Incomplete test'); |
| 358 } |
| 359 |
| 360 @failingTest |
| 361 void test_findSdk_embedder_noExtensions() { |
| 362 // See test_createSourceFactory_noProvider_packages_embedder_noExtensions |
| 363 fail('Incomplete test'); |
| 364 } |
| 365 |
| 366 @failingTest |
| 367 void test_findSdk_noEmbedder_extensions() { |
| 368 // See test_createSourceFactory_noProvider_packages_noEmbedder_extensions |
| 369 fail('Incomplete test'); |
| 370 } |
| 371 |
| 372 @failingTest |
| 373 void test_findSdk_noEmbedder_noExtensions() { |
| 374 // See test_createSourceFactory_noProvider_packages_noEmbedder_noExtensions |
| 375 fail('Incomplete test'); |
| 376 } |
| 377 |
| 349 /** | 378 /** |
| 350 * Execute the [test] function with a temporary [directory]. The test function | 379 * Execute the [test] function with a temporary [directory]. The test function |
| 351 * can perform any disk operations within the directory and the directory (and | 380 * can perform any disk operations within the directory and the directory (and |
| 352 * its content) will be removed after the function returns. | 381 * its content) will be removed after the function returns. |
| 353 */ | 382 */ |
| 354 void withTempDir(test(io.Directory directory)) { | 383 void withTempDir(test(io.Directory directory)) { |
| 355 io.Directory directory = | 384 io.Directory directory = |
| 356 io.Directory.systemTemp.createTempSync('analyzer_'); | 385 io.Directory.systemTemp.createTempSync('analyzer_'); |
| 357 try { | 386 try { |
| 358 test(directory); | 387 test(directory); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 MapPackages packages = new MapPackages({fooName: fooUri, barName: barUri}); | 445 MapPackages packages = new MapPackages({fooName: fooUri, barName: barUri}); |
| 417 Map<String, List<Folder>> result = builder.convertPackagesToMap(packages); | 446 Map<String, List<Folder>> result = builder.convertPackagesToMap(packages); |
| 418 expect(result, isNotNull); | 447 expect(result, isNotNull); |
| 419 expect(result, hasLength(2)); | 448 expect(result, hasLength(2)); |
| 420 expect(result[fooName], hasLength(1)); | 449 expect(result[fooName], hasLength(1)); |
| 421 expect(result[fooName][0].path, fooPath); | 450 expect(result[fooName][0].path, fooPath); |
| 422 expect(result[barName], hasLength(1)); | 451 expect(result[barName], hasLength(1)); |
| 423 expect(result[barName][0].path, barPath); | 452 expect(result[barName][0].path, barPath); |
| 424 } | 453 } |
| 425 | 454 |
| 426 @failingTest | 455 void test_createDefaultOptions_default() { |
| 427 void test_findSdkResolver() { | 456 // Invert a subset of the options to ensure that the default options are |
| 428 fail('Incomplete test'); | 457 // being returned. |
| 458 AnalysisOptionsImpl defaultOptions = new AnalysisOptionsImpl(); |
| 459 defaultOptions.dart2jsHint = !defaultOptions.dart2jsHint; |
| 460 defaultOptions.enableAssertMessage = !defaultOptions.enableAssertMessage; |
| 461 defaultOptions.enableAsync = !defaultOptions.enableAsync; |
| 462 defaultOptions.enableGenericMethods = !defaultOptions.enableGenericMethods; |
| 463 defaultOptions.enableStrictCallChecks = |
| 464 !defaultOptions.enableStrictCallChecks; |
| 465 defaultOptions.enableSuperMixins = !defaultOptions.enableSuperMixins; |
| 466 builder.defaultOptions = defaultOptions; |
| 467 AnalysisOptions options = builder.createDefaultOptions(); |
| 468 _expectEqualOptions(options, defaultOptions); |
| 469 } |
| 470 |
| 471 void test_createDefaultOptions_noDefault() { |
| 472 AnalysisOptions options = builder.createDefaultOptions(); |
| 473 _expectEqualOptions(options, new AnalysisOptionsImpl()); |
| 474 } |
| 475 |
| 476 void test_declareVariables_emptyMap() { |
| 477 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext(); |
| 478 Iterable<String> expected = context.declaredVariables.variableNames; |
| 479 builder.declaredVariables = <String, String>{}; |
| 480 |
| 481 builder.declareVariables(context); |
| 482 expect(context.declaredVariables.variableNames, unorderedEquals(expected)); |
| 483 } |
| 484 |
| 485 void test_declareVariables_nonEmptyMap() { |
| 486 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext(); |
| 487 List<String> expected = context.declaredVariables.variableNames.toList(); |
| 488 expect(expected, isNot(contains('a'))); |
| 489 expect(expected, isNot(contains('b'))); |
| 490 expected.addAll(['a', 'b']); |
| 491 builder.declaredVariables = <String, String>{'a': 'a', 'b': 'b'}; |
| 492 |
| 493 builder.declareVariables(context); |
| 494 expect(context.declaredVariables.variableNames, unorderedEquals(expected)); |
| 495 } |
| 496 |
| 497 void test_declareVariables_null() { |
| 498 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext(); |
| 499 Iterable<String> expected = context.declaredVariables.variableNames; |
| 500 |
| 501 builder.declareVariables(context); |
| 502 expect(context.declaredVariables.variableNames, unorderedEquals(expected)); |
| 503 } |
| 504 |
| 505 void test_findSdk_noPackageMap() { |
| 506 DartSdk sdk = builder.findSdk(null, new AnalysisOptionsImpl()); |
| 507 expect(sdk, isNotNull); |
| 508 } |
| 509 |
| 510 void test_getAnalysisOptions_default_noOverrides() { |
| 511 AnalysisOptionsImpl defaultOptions = new AnalysisOptionsImpl(); |
| 512 defaultOptions.enableGenericMethods = true; |
| 513 builder.defaultOptions = defaultOptions; |
| 514 AnalysisOptionsImpl expected = new AnalysisOptionsImpl(); |
| 515 expected.enableGenericMethods = true; |
| 516 String path = '/some/directory/path'; |
| 517 String filePath = '$path/${AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE}'; |
| 518 resourceProvider.newFile( |
| 519 filePath, |
| 520 ''' |
| 521 linter: |
| 522 rules: |
| 523 - empty_constructor_bodies |
| 524 '''); |
| 525 |
| 526 AnalysisOptions options = builder.getAnalysisOptions(path); |
| 527 _expectEqualOptions(options, expected); |
| 528 } |
| 529 |
| 530 void test_getAnalysisOptions_default_overrides() { |
| 531 AnalysisOptionsImpl defaultOptions = new AnalysisOptionsImpl(); |
| 532 defaultOptions.enableGenericMethods = true; |
| 533 builder.defaultOptions = defaultOptions; |
| 534 AnalysisOptionsImpl expected = new AnalysisOptionsImpl(); |
| 535 expected.enableAsync = true; |
| 536 expected.enableGenericMethods = true; |
| 537 String path = '/some/directory/path'; |
| 538 String filePath = '$path/${AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE}'; |
| 539 resourceProvider.newFile( |
| 540 filePath, |
| 541 ''' |
| 542 analyzer: |
| 543 enableAsync : true |
| 544 '''); |
| 545 |
| 546 AnalysisOptions options = builder.getAnalysisOptions(path); |
| 547 _expectEqualOptions(options, expected); |
| 548 } |
| 549 |
| 550 void test_getAnalysisOptions_noDefault_noOverrides() { |
| 551 String path = '/some/directory/path'; |
| 552 String filePath = '$path/${AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE}'; |
| 553 resourceProvider.newFile( |
| 554 filePath, |
| 555 ''' |
| 556 linter: |
| 557 rules: |
| 558 - empty_constructor_bodies |
| 559 '''); |
| 560 |
| 561 AnalysisOptions options = builder.getAnalysisOptions(path); |
| 562 _expectEqualOptions(options, new AnalysisOptionsImpl()); |
| 563 } |
| 564 |
| 565 void test_getAnalysisOptions_noDefault_overrides() { |
| 566 AnalysisOptionsImpl expected = new AnalysisOptionsImpl(); |
| 567 expected.enableAsync = true; |
| 568 String path = '/some/directory/path'; |
| 569 String filePath = '$path/${AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE}'; |
| 570 resourceProvider.newFile( |
| 571 filePath, |
| 572 ''' |
| 573 analyzer: |
| 574 enableAsync : true |
| 575 '''); |
| 576 |
| 577 AnalysisOptions options = builder.getAnalysisOptions(path); |
| 578 _expectEqualOptions(options, expected); |
| 429 } | 579 } |
| 430 | 580 |
| 431 void test_getOptionsFile_explicit() { | 581 void test_getOptionsFile_explicit() { |
| 432 String path = '/some/directory/path'; | 582 String path = '/some/directory/path'; |
| 433 String filePath = '/options/analysis.yaml'; | 583 String filePath = '/options/analysis.yaml'; |
| 434 resourceProvider.newFile(filePath, ''); | 584 resourceProvider.newFile(filePath, ''); |
| 435 | 585 |
| 436 builder.defaultAnalysisOptionsFilePath = filePath; | 586 builder.defaultAnalysisOptionsFilePath = filePath; |
| 437 File result = builder.getOptionsFile(path); | 587 File result = builder.getOptionsFile(path); |
| 438 expect(result, isNotNull); | 588 expect(result, isNotNull); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 | 624 |
| 475 void test_getOptionsFile_inRoot_old() { | 625 void test_getOptionsFile_inRoot_old() { |
| 476 String path = '/some/directory/path'; | 626 String path = '/some/directory/path'; |
| 477 String filePath = '$path/${AnalysisEngine.ANALYSIS_OPTIONS_FILE}'; | 627 String filePath = '$path/${AnalysisEngine.ANALYSIS_OPTIONS_FILE}'; |
| 478 resourceProvider.newFile(filePath, ''); | 628 resourceProvider.newFile(filePath, ''); |
| 479 | 629 |
| 480 File result = builder.getOptionsFile(path); | 630 File result = builder.getOptionsFile(path); |
| 481 expect(result, isNotNull); | 631 expect(result, isNotNull); |
| 482 expect(result.path, filePath); | 632 expect(result.path, filePath); |
| 483 } | 633 } |
| 634 |
| 635 void _expectEqualOptions( |
| 636 AnalysisOptionsImpl actual, AnalysisOptionsImpl expected) { |
| 637 // TODO(brianwilkerson) Consider moving this to AnalysisOptionsImpl.==. |
| 638 expect(actual.analyzeFunctionBodiesPredicate, |
| 639 same(expected.analyzeFunctionBodiesPredicate)); |
| 640 expect(actual.cacheSize, expected.cacheSize); |
| 641 expect(actual.dart2jsHint, expected.dart2jsHint); |
| 642 expect(actual.enableAssertMessage, expected.enableAssertMessage); |
| 643 expect(actual.enableAsync, expected.enableAsync); |
| 644 expect(actual.enableStrictCallChecks, expected.enableStrictCallChecks); |
| 645 expect(actual.enableGenericMethods, expected.enableGenericMethods); |
| 646 expect(actual.enableSuperMixins, expected.enableSuperMixins); |
| 647 expect(actual.enableTiming, expected.enableTiming); |
| 648 expect(actual.enableTrailingCommas, expected.enableTrailingCommas); |
| 649 expect(actual.generateImplicitErrors, expected.generateImplicitErrors); |
| 650 expect(actual.generateSdkErrors, expected.generateSdkErrors); |
| 651 expect(actual.hint, expected.hint); |
| 652 expect(actual.incremental, expected.incremental); |
| 653 expect(actual.incrementalApi, expected.incrementalApi); |
| 654 expect(actual.incrementalValidation, expected.incrementalValidation); |
| 655 expect(actual.lint, expected.lint); |
| 656 expect(actual.preserveComments, expected.preserveComments); |
| 657 expect(actual.strongMode, expected.strongMode); |
| 658 expect(actual.strongModeHints, expected.strongModeHints); |
| 659 expect(actual.implicitCasts, expected.implicitCasts); |
| 660 expect(actual.implicitDynamic, expected.implicitDynamic); |
| 661 expect(actual.trackCacheDependencies, expected.trackCacheDependencies); |
| 662 expect(actual.finerGrainedInvalidation, expected.finerGrainedInvalidation); |
| 663 } |
| 484 } | 664 } |
| OLD | NEW |