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

Side by Side Diff: pkg/analysis_server/test/context_manager_test.dart

Issue 2350143004: More clean-up in server (Closed)
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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 test.context.directory.manager; 5 library test.context.directory.manager;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import 'dart:io' as io; 8 import 'dart:io' as io;
9 9
10 import 'package:analysis_server/src/context_manager.dart'; 10 import 'package:analysis_server/src/context_manager.dart';
11 import 'package:analyzer/error/error.dart'; 11 import 'package:analyzer/error/error.dart';
12 import 'package:analyzer/file_system/file_system.dart'; 12 import 'package:analyzer/file_system/file_system.dart';
13 import 'package:analyzer/file_system/memory_file_system.dart'; 13 import 'package:analyzer/file_system/memory_file_system.dart';
14 import 'package:analyzer/instrumentation/instrumentation.dart'; 14 import 'package:analyzer/instrumentation/instrumentation.dart';
15 import 'package:analyzer/source/error_processor.dart'; 15 import 'package:analyzer/source/error_processor.dart';
16 import 'package:analyzer/src/context/builder.dart'; 16 import 'package:analyzer/src/context/builder.dart';
17 import 'package:analyzer/src/dart/sdk/sdk.dart';
18 import 'package:analyzer/src/error/codes.dart'; 17 import 'package:analyzer/src/error/codes.dart';
19 import 'package:analyzer/src/generated/engine.dart'; 18 import 'package:analyzer/src/generated/engine.dart';
20 import 'package:analyzer/src/generated/sdk.dart'; 19 import 'package:analyzer/src/generated/sdk.dart';
21 import 'package:analyzer/src/generated/source.dart'; 20 import 'package:analyzer/src/generated/source.dart';
22 import 'package:analyzer/src/generated/source_io.dart'; 21 import 'package:analyzer/src/generated/source_io.dart';
23 import 'package:analyzer/src/services/lint.dart'; 22 import 'package:analyzer/src/services/lint.dart';
24 import 'package:analyzer/src/task/options.dart' 23 import 'package:analyzer/src/task/options.dart'
25 show CONFIGURED_ERROR_PROCESSORS; 24 show CONFIGURED_ERROR_PROCESSORS;
26 import 'package:analyzer/src/util/glob.dart'; 25 import 'package:analyzer/src/util/glob.dart';
27 import 'package:linter/src/plugin/linter_plugin.dart'; 26 import 'package:linter/src/plugin/linter_plugin.dart';
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 expect(exampleSources, hasLength(1)); 462 expect(exampleSources, hasLength(1));
464 expect(exampleSources.first.uri.toString(), 463 expect(exampleSources.first.uri.toString(),
465 'file:///my/proj/example/example.dart'); 464 'file:///my/proj/example/example.dart');
466 } 465 }
467 466
468 void test_setRoots_addFolderWithNestedPubspec() { 467 void test_setRoots_addFolderWithNestedPubspec() {
469 String examplePath = newFolder([projPath, ContextManagerTest.EXAMPLE_NAME]); 468 String examplePath = newFolder([projPath, ContextManagerTest.EXAMPLE_NAME]);
470 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]); 469 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]);
471 470
472 newFile([projPath, ContextManagerImpl.PUBSPEC_NAME]); 471 newFile([projPath, ContextManagerImpl.PUBSPEC_NAME]);
472 newFile([projPath, ContextManagerImpl.PACKAGE_SPEC_NAME], 'proj:lib/');
473 newFile([libPath, 'main.dart']); 473 newFile([libPath, 'main.dart']);
474 newFile([examplePath, ContextManagerImpl.PUBSPEC_NAME]); 474 newFile([examplePath, ContextManagerImpl.PUBSPEC_NAME]);
475 newFile([examplePath, 'example.dart']); 475 newFile([examplePath, 'example.dart']);
476 476
477 packageMapProvider.packageMap['proj'] = <Folder>[
478 resourceProvider.getResource(libPath)
479 ];
480
481 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 477 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
482 478
483 expect(callbacks.currentContextPaths, hasLength(2)); 479 expect(callbacks.currentContextPaths, hasLength(2));
484 480
485 expect(callbacks.currentContextPaths, contains(projPath)); 481 expect(callbacks.currentContextPaths, contains(projPath));
486 Set<Source> projSources = callbacks.currentContextSources[projPath]; 482 Set<Source> projSources = callbacks.currentContextSources[projPath];
487 expect(projSources, hasLength(1)); 483 expect(projSources, hasLength(1));
488 expect(projSources.first.uri.toString(), 'package:proj/main.dart'); 484 expect(projSources.first.uri.toString(), 'package:proj/main.dart');
489 485
490 expect(callbacks.currentContextPaths, contains(examplePath)); 486 expect(callbacks.currentContextPaths, contains(examplePath));
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 callbacks.assertContextPaths([projPath]); 557 callbacks.assertContextPaths([projPath]);
562 } 558 }
563 559
564 void test_setRoots_addFolderWithPubspecAndLib() { 560 void test_setRoots_addFolderWithPubspecAndLib() {
565 String binPath = newFolder([projPath, ContextManagerTest.BIN_NAME]); 561 String binPath = newFolder([projPath, ContextManagerTest.BIN_NAME]);
566 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]); 562 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]);
567 String srcPath = newFolder([libPath, ContextManagerTest.SRC_NAME]); 563 String srcPath = newFolder([libPath, ContextManagerTest.SRC_NAME]);
568 String testPath = newFolder([projPath, ContextManagerTest.TEST_NAME]); 564 String testPath = newFolder([projPath, ContextManagerTest.TEST_NAME]);
569 565
570 newFile([projPath, ContextManagerImpl.PUBSPEC_NAME]); 566 newFile([projPath, ContextManagerImpl.PUBSPEC_NAME]);
567 newFile([projPath, ContextManagerImpl.PACKAGE_SPEC_NAME], 'proj:lib/');
571 String appPath = newFile([binPath, 'app.dart']); 568 String appPath = newFile([binPath, 'app.dart']);
572 newFile([libPath, 'main.dart']); 569 newFile([libPath, 'main.dart']);
573 newFile([srcPath, 'internal.dart']); 570 newFile([srcPath, 'internal.dart']);
574 String testFilePath = newFile([testPath, 'main_test.dart']); 571 String testFilePath = newFile([testPath, 'main_test.dart']);
575 572
576 packageMapProvider.packageMap['proj'] = <Folder>[
577 resourceProvider.getResource(libPath)
578 ];
579
580 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 573 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
581 Set<Source> sources = callbacks.currentContextSources[projPath]; 574 Set<Source> sources = callbacks.currentContextSources[projPath];
582 575
583 expect(callbacks.currentContextPaths, hasLength(1)); 576 expect(callbacks.currentContextPaths, hasLength(1));
584 expect(callbacks.currentContextPaths, contains(projPath)); 577 expect(callbacks.currentContextPaths, contains(projPath));
585 expect(sources, hasLength(4)); 578 expect(sources, hasLength(4));
586 List<String> uris = 579 List<String> uris =
587 sources.map((Source source) => source.uri.toString()).toList(); 580 sources.map((Source source) => source.uri.toString()).toList();
588 expect(uris, contains('file://$appPath')); 581 expect(uris, contains('file://$appPath'));
589 expect(uris, contains('package:proj/main.dart')); 582 expect(uris, contains('package:proj/main.dart'));
(...skipping 25 matching lines...) Expand all
615 // verify files 608 // verify files
616 callbacks.assertContextFiles(root, [rootFile]); 609 callbacks.assertContextFiles(root, [rootFile]);
617 callbacks.assertContextFiles(subProjectA, [subProjectA_file]); 610 callbacks.assertContextFiles(subProjectA, [subProjectA_file]);
618 callbacks.assertContextFiles(subProjectB, [subProjectB_file]); 611 callbacks.assertContextFiles(subProjectB, [subProjectB_file]);
619 } 612 }
620 613
621 void test_setRoots_addFolderWithPubspecFolders() { 614 void test_setRoots_addFolderWithPubspecFolders() {
622 // prepare paths 615 // prepare paths
623 String root = '/root'; 616 String root = '/root';
624 String rootFile = '$root/root.dart'; 617 String rootFile = '$root/root.dart';
625 String subProjectA = '$root/sub/aaa'; 618 String projectA = '$root/sub/aaa';
626 String subProjectB = '$root/sub/sub2/bbb'; 619 String projectALib = '$root/sub/aaa/lib';
627 String subProjectA_file = '$subProjectA/bin/a.dart'; 620 String subProjectA_file = '$projectA/bin/a.dart';
628 String subProjectB_file = '$subProjectB/bin/b.dart'; 621 String projectB = '$root/sub/sub2/bbb';
622 String projectBLib = '$root/sub/sub2/bbb/lib';
623 String subProjectB_file = '$projectB/bin/b.dart';
629 // create files 624 // create files
630 resourceProvider.newFile('$subProjectA/pubspec.yaml', 'pubspec'); 625 newFile([projectA, ContextManagerImpl.PUBSPEC_NAME]);
631 resourceProvider.newFile('$subProjectB/pubspec.yaml', 'pubspec'); 626 newFile([projectA, ContextManagerImpl.PACKAGE_SPEC_NAME], 'foo:lib/');
627 newFile([projectB, ContextManagerImpl.PUBSPEC_NAME]);
628 newFile([projectB, ContextManagerImpl.PACKAGE_SPEC_NAME], 'bar:lib/');
632 resourceProvider.newFile(rootFile, 'library root;'); 629 resourceProvider.newFile(rootFile, 'library root;');
633 resourceProvider.newFile(subProjectA_file, 'library a;'); 630 resourceProvider.newFile(subProjectA_file, 'library a;');
634 resourceProvider.newFile(subProjectB_file, 'library b;'); 631 resourceProvider.newFile(subProjectB_file, 'library b;');
635 // configure package maps
636 packageMapProvider.packageMaps = {
637 subProjectA: {
638 'foo': [resourceProvider.newFolder('/package/foo')]
639 },
640 subProjectB: {
641 'bar': [resourceProvider.newFolder('/package/bar')]
642 },
643 };
644 // set roots 632 // set roots
645 manager.setRoots(<String>[root], <String>[], <String, String>{}); 633 manager.setRoots(<String>[root], <String>[], <String, String>{});
646 callbacks.assertContextPaths([root, subProjectA, subProjectB]); 634 callbacks.assertContextPaths([root, projectA, projectB]);
647 // verify files 635 // verify files
648 callbacks.assertContextFiles(root, [rootFile]); 636 callbacks.assertContextFiles(root, [rootFile]);
649 callbacks.assertContextFiles(subProjectA, [subProjectA_file]); 637 callbacks.assertContextFiles(projectA, [subProjectA_file]);
650 callbacks.assertContextFiles(subProjectB, [subProjectB_file]); 638 callbacks.assertContextFiles(projectB, [subProjectB_file]);
651 // verify package maps 639 // verify package maps
652 expect(_packageMap(root), isNull); 640 expect(_packageMap(root), isEmpty);
653 expect(_packageMap(subProjectA), 641 expect(
654 equals(packageMapProvider.packageMaps[subProjectA])); 642 _packageMap(projectA),
655 expect(_packageMap(subProjectB), 643 equals({
656 equals(packageMapProvider.packageMaps[subProjectB])); 644 'foo': [resourceProvider.getFolder(projectALib)]
645 }));
646 expect(
647 _packageMap(projectB),
648 equals({
649 'bar': [resourceProvider.getFolder(projectBLib)]
650 }));
657 } 651 }
658 652
659 void test_setRoots_addPackageRoot() { 653 void test_setRoots_addPackageRoot() {
660 String packagePathFoo = '/package1/foo'; 654 String packagePathFoo = '/package1/foo';
661 String packageRootPath = '/package2/foo'; 655 String packageRootPath = '/package2/foo';
656 newFile([projPath, ContextManagerImpl.PACKAGE_SPEC_NAME],
657 'foo:file:///package1/foo');
662 Folder packageFolder = resourceProvider.newFolder(packagePathFoo); 658 Folder packageFolder = resourceProvider.newFolder(packagePathFoo);
663 packageMapProvider.packageMap = {
664 'foo': [packageFolder]
665 };
666 List<String> includedPaths = <String>[projPath]; 659 List<String> includedPaths = <String>[projPath];
667 List<String> excludedPaths = <String>[]; 660 List<String> excludedPaths = <String>[];
668 manager.setRoots(includedPaths, excludedPaths, <String, String>{}); 661 manager.setRoots(includedPaths, excludedPaths, <String, String>{});
669 expect(_currentPackageMap, equals(packageMapProvider.packageMap)); 662 expect(
663 _currentPackageMap,
664 equals({
665 'foo': [packageFolder]
666 }));
670 manager.setRoots(includedPaths, excludedPaths, 667 manager.setRoots(includedPaths, excludedPaths,
671 <String, String>{projPath: packageRootPath}); 668 <String, String>{projPath: packageRootPath});
672 _checkPackageRoot(projPath, equals(packageRootPath)); 669 _checkPackageRoot(projPath, equals(packageRootPath));
673 } 670 }
674 671
675 void test_setRoots_changePackageRoot() { 672 void test_setRoots_changePackageRoot() {
676 String packageRootPath1 = '/package1'; 673 String packageRootPath1 = '/package1';
677 String packageRootPath2 = '/package2'; 674 String packageRootPath2 = '/package2';
678 List<String> includedPaths = <String>[projPath]; 675 List<String> includedPaths = <String>[projPath];
679 List<String> excludedPaths = <String>[]; 676 List<String> excludedPaths = <String>[];
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
905 902
906 void test_setRoots_newFolderWithPackageRoot() { 903 void test_setRoots_newFolderWithPackageRoot() {
907 String packageRootPath = '/package'; 904 String packageRootPath = '/package';
908 manager.setRoots(<String>[projPath], <String>[], 905 manager.setRoots(<String>[projPath], <String>[],
909 <String, String>{projPath: packageRootPath}); 906 <String, String>{projPath: packageRootPath});
910 _checkPackageRoot(projPath, equals(packageRootPath)); 907 _checkPackageRoot(projPath, equals(packageRootPath));
911 } 908 }
912 909
913 void test_setRoots_newlyAddedFoldersGetProperPackageMap() { 910 void test_setRoots_newlyAddedFoldersGetProperPackageMap() {
914 String packagePath = '/package/foo'; 911 String packagePath = '/package/foo';
912 newFile([projPath, ContextManagerImpl.PACKAGE_SPEC_NAME],
913 'foo:file:///package/foo');
915 Folder packageFolder = resourceProvider.newFolder(packagePath); 914 Folder packageFolder = resourceProvider.newFolder(packagePath);
916 packageMapProvider.packageMap = {
917 'foo': [packageFolder]
918 };
919 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 915 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
920 expect(_currentPackageMap, equals(packageMapProvider.packageMap)); 916 expect(
917 _currentPackageMap,
918 equals({
919 'foo': [packageFolder]
920 }));
921 } 921 }
922 922
923 void test_setRoots_noContext_excludedFolder() { 923 void test_setRoots_noContext_excludedFolder() {
924 // prepare paths 924 // prepare paths
925 String project = '/project'; 925 String project = '/project';
926 String excludedFolder = '$project/excluded'; 926 String excludedFolder = '$project/excluded';
927 String excludedPubspec = '$excludedFolder/pubspec.yaml'; 927 String excludedPubspec = '$excludedFolder/pubspec.yaml';
928 // create files 928 // create files
929 resourceProvider.newFile(excludedPubspec, 'name: ignore-me'); 929 resourceProvider.newFile(excludedPubspec, 'name: ignore-me');
930 // set "/project", and exclude "/project/excluded" 930 // set "/project", and exclude "/project/excluded"
(...skipping 16 matching lines...) Expand all
947 String pubspecPath = posix.join(projPath, 'packages', 'pubspec.yaml'); 947 String pubspecPath = posix.join(projPath, 'packages', 'pubspec.yaml');
948 resourceProvider.newFile(pubspecPath, 'name: test'); 948 resourceProvider.newFile(pubspecPath, 'name: test');
949 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 949 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
950 // verify 950 // verify
951 expect(callbacks.currentContextPaths, hasLength(1)); 951 expect(callbacks.currentContextPaths, hasLength(1));
952 expect(callbacks.currentContextPaths, contains(projPath)); 952 expect(callbacks.currentContextPaths, contains(projPath));
953 expect(callbacks.currentContextFilePaths[projPath], hasLength(0)); 953 expect(callbacks.currentContextFilePaths[projPath], hasLength(0));
954 } 954 }
955 955
956 void test_setRoots_packageResolver() { 956 void test_setRoots_packageResolver() {
957 Uri uri = Uri.parse('package:foo/foo.dart'); 957 String filePath = posix.join(projPath, 'lib', 'foo.dart');
958 Source source = new TestSource(); 958 newFile([projPath, ContextManagerImpl.PACKAGE_SPEC_NAME], 'foo:lib/');
959 packageResolver = new TestUriResolver({uri: source});
960 String filePath = posix.join(projPath, 'foo.dart');
961 resourceProvider.newFile(filePath, 'contents'); 959 resourceProvider.newFile(filePath, 'contents');
962 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 960 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
963 961
964 List<AnalysisContext> contextsInAnalysisRoot = 962 List<AnalysisContext> contextsInAnalysisRoot =
965 manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath)); 963 manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath));
966 expect(contextsInAnalysisRoot, hasLength(1)); 964 expect(contextsInAnalysisRoot, hasLength(1));
967 AnalysisContext context = contextsInAnalysisRoot[0]; 965 AnalysisContext context = contextsInAnalysisRoot[0];
968 expect(context, isNotNull); 966 expect(context, isNotNull);
969 Source result = context.sourceFactory.forUri2(uri); 967 Source result = context.sourceFactory.forUri('package:foo/foo.dart');
970 expect(result, same(source)); 968 expect(result.fullName, filePath);
971 } 969 }
972 970
973 void test_setRoots_pathContainsDotFile() { 971 void test_setRoots_pathContainsDotFile() {
974 // If the path to a file (relative to the context root) contains a folder 972 // If the path to a file (relative to the context root) contains a folder
975 // whose name begins with '.', then the file is ignored. 973 // whose name begins with '.', then the file is ignored.
976 String project = '/project'; 974 String project = '/project';
977 String fileA = '$project/foo.dart'; 975 String fileA = '$project/foo.dart';
978 String fileB = '$project/.pub/bar.dart'; 976 String fileB = '$project/.pub/bar.dart';
979 resourceProvider.newFile(fileA, ''); 977 resourceProvider.newFile(fileA, '');
980 resourceProvider.newFile(fileB, ''); 978 resourceProvider.newFile(fileB, '');
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
1089 manager.setRoots(<String>[projectA], <String>[], <String, String>{}); 1087 manager.setRoots(<String>[projectA], <String>[], <String, String>{});
1090 callbacks.assertContextPaths([projectA, subProjectA]); 1088 callbacks.assertContextPaths([projectA, subProjectA]);
1091 callbacks.assertContextFiles(projectA, [projectA_file]); 1089 callbacks.assertContextFiles(projectA, [projectA_file]);
1092 callbacks.assertContextFiles(subProjectA, [subProjectA_file]); 1090 callbacks.assertContextFiles(subProjectA, [subProjectA_file]);
1093 } 1091 }
1094 1092
1095 void test_setRoots_removePackageRoot() { 1093 void test_setRoots_removePackageRoot() {
1096 String packagePathFoo = '/package1/foo'; 1094 String packagePathFoo = '/package1/foo';
1097 String packageRootPath = '/package2/foo'; 1095 String packageRootPath = '/package2/foo';
1098 Folder packageFolder = resourceProvider.newFolder(packagePathFoo); 1096 Folder packageFolder = resourceProvider.newFolder(packagePathFoo);
1099 packageMapProvider.packageMap = { 1097 newFile([projPath, ContextManagerImpl.PACKAGE_SPEC_NAME],
1100 'foo': [packageFolder] 1098 'foo:file:///package1/foo');
1101 };
1102 List<String> includedPaths = <String>[projPath]; 1099 List<String> includedPaths = <String>[projPath];
1103 List<String> excludedPaths = <String>[]; 1100 List<String> excludedPaths = <String>[];
1104 manager.setRoots(includedPaths, excludedPaths, 1101 manager.setRoots(includedPaths, excludedPaths,
1105 <String, String>{projPath: packageRootPath}); 1102 <String, String>{projPath: packageRootPath});
1106 _checkPackageRoot(projPath, equals(packageRootPath)); 1103 _checkPackageRoot(projPath, equals(packageRootPath));
1107 manager.setRoots(includedPaths, excludedPaths, <String, String>{}); 1104 manager.setRoots(includedPaths, excludedPaths, <String, String>{});
1108 expect(_currentPackageMap, equals(packageMapProvider.packageMap)); 1105 expect(
1106 _currentPackageMap,
1107 equals({
1108 'foo': [packageFolder]
1109 }));
1109 } 1110 }
1110 1111
1111 void test_setRoots_rootPathContainsDotFile() { 1112 void test_setRoots_rootPathContainsDotFile() {
1112 // If the path to the context root itself contains a folder whose name 1113 // If the path to the context root itself contains a folder whose name
1113 // begins with '.', then that is not sufficient to cause any files in the 1114 // begins with '.', then that is not sufficient to cause any files in the
1114 // context to be ignored. 1115 // context to be ignored.
1115 String project = '/.pub/project'; 1116 String project = '/.pub/project';
1116 String fileA = '$project/foo.dart'; 1117 String fileA = '$project/foo.dart';
1117 resourceProvider.newFile(fileA, ''); 1118 resourceProvider.newFile(fileA, '');
1118 manager.setRoots(<String>[project], <String>[], <String, String>{}); 1119 manager.setRoots(<String>[project], <String>[], <String, String>{});
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after
1607 expect(filePaths, contains(filePath)); 1608 expect(filePaths, contains(filePath));
1608 expect(filePaths[filePath], equals(callbacks.now)); 1609 expect(filePaths[filePath], equals(callbacks.now));
1609 // update the file 1610 // update the file
1610 callbacks.now++; 1611 callbacks.now++;
1611 resourceProvider.modifyFile(filePath, 'new contents'); 1612 resourceProvider.modifyFile(filePath, 'new contents');
1612 return pumpEventQueue().then((_) { 1613 return pumpEventQueue().then((_) {
1613 return expect(filePaths[filePath], equals(callbacks.now)); 1614 return expect(filePaths[filePath], equals(callbacks.now));
1614 }); 1615 });
1615 } 1616 }
1616 1617
1617 test_watch_modifyPackageMapDependency() { 1618 test_watch_modifyPackageMapDependency_fail() async {
1618 // create a dependency file 1619 // create a dependency file
1619 String dependencyPath = posix.join(projPath, 'dep'); 1620 String dependencyPath = posix.join(projPath, 'dep');
1620 resourceProvider.newFile(dependencyPath, 'contents'); 1621 resourceProvider.newFile(dependencyPath, 'contents');
1621 packageMapProvider.dependencies.add(dependencyPath);
1622 // create a Dart file
1623 String dartFilePath = posix.join(projPath, 'main.dart');
1624 resourceProvider.newFile(dartFilePath, 'contents');
1625 // the created context has the expected empty package map
1626 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
1627 expect(_currentPackageMap, isEmpty);
1628 // configure package map
1629 String packagePath = '/package/foo';
1630 resourceProvider.newFolder(packagePath);
1631 packageMapProvider.packageMap = {
1632 'foo': [resourceProvider.newFolder(projPath)]
1633 };
1634 // Changing a .dart file in the project shouldn't cause a new
1635 // package map to be picked up.
1636 resourceProvider.modifyFile(dartFilePath, 'new contents');
1637 return pumpEventQueue().then((_) {
1638 expect(_currentPackageMap, isEmpty);
1639 // However, changing the package map dependency should.
1640 resourceProvider.modifyFile(dependencyPath, 'new contents');
1641 return pumpEventQueue().then((_) {
1642 expect(_currentPackageMap, equals(packageMapProvider.packageMap));
1643 });
1644 });
1645 }
1646
1647 test_watch_modifyPackageMapDependency_fail() {
1648 // create a dependency file
1649 String dependencyPath = posix.join(projPath, 'dep');
1650 resourceProvider.newFile(dependencyPath, 'contents');
1651 packageMapProvider.dependencies.add(dependencyPath); 1622 packageMapProvider.dependencies.add(dependencyPath);
1652 // create a Dart file 1623 // create a Dart file
1653 String dartFilePath = posix.join(projPath, 'main.dart'); 1624 String dartFilePath = posix.join(projPath, 'main.dart');
1654 resourceProvider.newFile(dartFilePath, 'contents'); 1625 resourceProvider.newFile(dartFilePath, 'contents');
1655 // the created context has the expected empty package map 1626 // the created context has the expected empty package map
1656 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 1627 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
1657 expect(_currentPackageMap, isEmpty); 1628 expect(_currentPackageMap, isEmpty);
1658 // Change the package map dependency so that the packageMapProvider is 1629 // Change the package map dependency so that the packageMapProvider is
1659 // re-run, and arrange for it to return null from computePackageMap(). 1630 // re-run, and arrange for it to return null from computePackageMap().
1660 packageMapProvider.packageMap = null; 1631 packageMapProvider.packageMap = null;
1661 resourceProvider.modifyFile(dependencyPath, 'new contents'); 1632 resourceProvider.modifyFile(dependencyPath, 'new contents');
1662 return pumpEventQueue().then((_) { 1633 await pumpEventQueue();
1663 // The package map should have been changed to null. 1634 // The package map should have been changed to null.
1664 expect(_currentPackageMap, isNull); 1635 expect(_currentPackageMap, isEmpty);
1665 });
1666 } 1636 }
1667 1637
1668 test_watch_modifyPackagespec() { 1638 test_watch_modifyPackagespec() {
1669 String packagesPath = '$projPath/.packages'; 1639 String packagesPath = '$projPath/.packages';
1670 String filePath = '$projPath/bin/main.dart'; 1640 String filePath = '$projPath/bin/main.dart';
1671 1641
1672 resourceProvider.newFile(packagesPath, ''); 1642 resourceProvider.newFile(packagesPath, '');
1673 resourceProvider.newFile(filePath, 'library main;'); 1643 resourceProvider.newFile(filePath, 'library main;');
1674 1644
1675 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 1645 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
(...skipping 965 matching lines...) Expand 10 before | Expand all | Expand 10 after
2641 List<String> lastFlushedFiles; 2611 List<String> lastFlushedFiles;
2642 2612
2643 TestContextManagerCallbacks(this.resourceProvider); 2613 TestContextManagerCallbacks(this.resourceProvider);
2644 2614
2645 /** 2615 /**
2646 * Iterable of the paths to contexts that currently exist. 2616 * Iterable of the paths to contexts that currently exist.
2647 */ 2617 */
2648 Iterable<String> get currentContextPaths => currentContextTimestamps.keys; 2618 Iterable<String> get currentContextPaths => currentContextTimestamps.keys;
2649 2619
2650 @override 2620 @override
2651 AnalysisContext addContext( 2621 AnalysisContext addContext(Folder folder, AnalysisOptions options) {
2652 Folder folder, AnalysisOptions options, FolderDisposition disposition) {
2653 String path = folder.path; 2622 String path = folder.path;
2654 expect(currentContextPaths, isNot(contains(path))); 2623 expect(currentContextPaths, isNot(contains(path)));
2655 currentContextTimestamps[path] = now; 2624 currentContextTimestamps[path] = now;
2656 currentContextFilePaths[path] = <String, int>{}; 2625 currentContextFilePaths[path] = <String, int>{};
2657 currentContextSources[path] = new HashSet<Source>(); 2626 currentContextSources[path] = new HashSet<Source>();
2658 currentContext = AnalysisEngine.instance.createAnalysisContext(); 2627
2659 List<UriResolver> resolvers = []; 2628 ContextBuilder builder = createContextBuilder(folder, options);
2660 if (currentContext is InternalAnalysisContext) { 2629 currentContext = builder.buildContext(folder.path);
2661 EmbedderYamlLocator embedderYamlLocator =
2662 disposition.getEmbedderLocator(resourceProvider);
2663 EmbedderSdk sdk =
2664 new EmbedderSdk(resourceProvider, embedderYamlLocator.embedderYamls);
2665 if (sdk.libraryMap.size() > 0) {
2666 // We have some embedder dart: uri mappings, add the resolver
2667 // to the list.
2668 resolvers.add(new DartUriResolver(sdk));
2669 }
2670 }
2671 resolvers.addAll(disposition.createPackageUriResolvers(resourceProvider));
2672 resolvers.add(new ResourceUriResolver(resourceProvider));
2673 currentContext.analysisOptions = options;
2674 currentContext.sourceFactory =
2675 new SourceFactory(resolvers, disposition.packages);
2676 return currentContext; 2630 return currentContext;
2677 } 2631 }
2678 2632
2679 @override 2633 @override
2680 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet) { 2634 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet) {
2681 Map<String, int> filePaths = currentContextFilePaths[contextFolder.path]; 2635 Map<String, int> filePaths = currentContextFilePaths[contextFolder.path];
2682 Set<Source> sources = currentContextSources[contextFolder.path]; 2636 Set<Source> sources = currentContextSources[contextFolder.path];
2683 2637
2684 for (Source source in changeSet.addedSources) { 2638 for (Source source in changeSet.addedSources) {
2685 expect(filePaths, isNot(contains(source.fullName))); 2639 expect(filePaths, isNot(contains(source.fullName)));
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
2766 class TestUriResolver extends UriResolver { 2720 class TestUriResolver extends UriResolver {
2767 Map<Uri, Source> uriMap; 2721 Map<Uri, Source> uriMap;
2768 2722
2769 TestUriResolver(this.uriMap); 2723 TestUriResolver(this.uriMap);
2770 2724
2771 @override 2725 @override
2772 Source resolveAbsolute(Uri uri, [Uri actualUri]) { 2726 Source resolveAbsolute(Uri uri, [Uri actualUri]) {
2773 return uriMap[uri]; 2727 return uriMap[uri];
2774 } 2728 }
2775 } 2729 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698