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

Side by Side Diff: pkg/analyzer/test/src/summary/pub_summary_test.dart

Issue 2232403002: Use existing unlinked bundles even for packages outside of the pub cache. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 4 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/lib/src/summary/pub_summary.dart ('k') | no next file » | 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) 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 import 'package:analyzer/dart/element/element.dart'; 5 import 'package:analyzer/dart/element/element.dart';
6 import 'package:analyzer/file_system/file_system.dart'; 6 import 'package:analyzer/file_system/file_system.dart';
7 import 'package:analyzer/source/package_map_resolver.dart'; 7 import 'package:analyzer/source/package_map_resolver.dart';
8 import 'package:analyzer/src/generated/sdk.dart'; 8 import 'package:analyzer/src/generated/sdk.dart';
9 import 'package:analyzer/src/generated/source.dart'; 9 import 'package:analyzer/src/generated/source.dart';
10 import 'package:analyzer/src/summary/format.dart';
10 import 'package:analyzer/src/summary/idl.dart'; 11 import 'package:analyzer/src/summary/idl.dart';
11 import 'package:analyzer/src/summary/pub_summary.dart'; 12 import 'package:analyzer/src/summary/pub_summary.dart';
12 import 'package:analyzer/src/summary/summarize_elements.dart'; 13 import 'package:analyzer/src/summary/summarize_elements.dart';
14 import 'package:analyzer/src/util/fast_uri.dart';
13 import 'package:path/path.dart' as pathos; 15 import 'package:path/path.dart' as pathos;
14 import 'package:unittest/unittest.dart' hide ERROR; 16 import 'package:unittest/unittest.dart' hide ERROR;
15 17
16 import '../../reflective_tests.dart'; 18 import '../../reflective_tests.dart';
17 import '../../utils.dart'; 19 import '../../utils.dart';
18 import '../context/abstract_context.dart'; 20 import '../context/abstract_context.dart';
19 21
20 main() { 22 main() {
21 initializeTestEnvironment(); 23 initializeTestEnvironment();
22 runReflectiveTests(PubSummaryManagerTest); 24 runReflectiveTests(PubSummaryManagerTest);
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 } 686 }
685 } 687 }
686 688
687 // The files must be created. 689 // The files must be created.
688 _assertFileExists(libFolderA.parent, PubSummaryManager.UNLINKED_NAME); 690 _assertFileExists(libFolderA.parent, PubSummaryManager.UNLINKED_NAME);
689 _assertFileExists(libFolderA.parent, PubSummaryManager.UNLINKED_SPEC_NAME); 691 _assertFileExists(libFolderA.parent, PubSummaryManager.UNLINKED_SPEC_NAME);
690 _assertFileExists(libFolderB.parent, PubSummaryManager.UNLINKED_NAME); 692 _assertFileExists(libFolderB.parent, PubSummaryManager.UNLINKED_NAME);
691 _assertFileExists(libFolderB.parent, PubSummaryManager.UNLINKED_SPEC_NAME); 693 _assertFileExists(libFolderB.parent, PubSummaryManager.UNLINKED_SPEC_NAME);
692 } 694 }
693 695
696 test_getUnlinkedBundles_notPubCache_dontCreate() async {
697 String aaaPath = '/Users/user/projects/aaa';
698 // Create package files.
699 resourceProvider.newFile(
700 '$aaaPath/lib/a.dart',
701 '''
702 class A {}
703 ''');
704 resourceProvider.newFile(
705 '$CACHE/bbb/lib/b.dart',
706 '''
707 class B {}
708 ''');
709
710 // Configure packages resolution.
711 Folder libFolderA = resourceProvider.getFolder('$aaaPath/lib');
712 Folder libFolderB = resourceProvider.newFolder('$CACHE/bbb/lib');
713 context.sourceFactory = new SourceFactory(<UriResolver>[
714 sdkResolver,
715 resourceResolver,
716 new PackageMapUriResolver(resourceProvider, {
717 'aaa': [libFolderA],
718 'bbb': [libFolderB],
719 })
720 ]);
721
722 // No unlinked bundles initially.
723 {
724 Map<PubPackage, PackageBundle> bundles =
725 manager.getUnlinkedBundles(context);
726 expect(bundles, isEmpty);
727 }
728
729 // Wait for unlinked bundles to be computed.
730 await manager.onUnlinkedComplete;
731 Map<PubPackage, PackageBundle> bundles =
732 manager.getUnlinkedBundles(context);
733 // We have just one bundle - for 'bbb'.
734 expect(bundles, hasLength(1));
735 // We computed the unlinked bundle for 'bbb'.
736 {
737 PackageBundle bundle = _getBundleByPackageName(bundles, 'bbb');
738 expect(bundle.linkedLibraryUris, isEmpty);
739 expect(bundle.unlinkedUnitUris, ['package:bbb/b.dart']);
740 expect(bundle.unlinkedUnits, hasLength(1));
741 expect(bundle.unlinkedUnits[0].classes.map((c) => c.name), ['B']);
742 }
743
744 // The files must be created.
745 _assertFileExists(libFolderB.parent, PubSummaryManager.UNLINKED_NAME);
746 _assertFileExists(libFolderB.parent, PubSummaryManager.UNLINKED_SPEC_NAME);
747 }
748
749 test_getUnlinkedBundles_notPubCache_useExisting() async {
750 String aaaPath = '/Users/user/projects/aaa';
751 // Create package files.
752 {
753 File file = resourceProvider.newFile(
754 '$aaaPath/lib/a.dart',
755 '''
756 class A {}
757 ''');
758 PackageBundleAssembler assembler = new PackageBundleAssembler()
759 ..addUnlinkedUnit(
760 file.createSource(FastUri.parse('package:aaa/a.dart')),
761 new UnlinkedUnitBuilder());
762 resourceProvider.newFileWithBytes(
763 '$aaaPath/${PubSummaryManager.UNLINKED_SPEC_NAME}',
764 assembler.assemble().toBuffer());
765 }
766 resourceProvider.newFile(
767 '$CACHE/bbb/lib/b.dart',
768 '''
769 class B {}
770 ''');
771
772 // Configure packages resolution.
773 Folder libFolderA = resourceProvider.getFolder('$aaaPath/lib');
774 Folder libFolderB = resourceProvider.newFolder('$CACHE/bbb/lib');
775 context.sourceFactory = new SourceFactory(<UriResolver>[
776 sdkResolver,
777 resourceResolver,
778 new PackageMapUriResolver(resourceProvider, {
779 'aaa': [libFolderA],
780 'bbb': [libFolderB],
781 })
782 ]);
783
784 // Request already available unlinked bundles.
785 {
786 Map<PubPackage, PackageBundle> bundles =
787 manager.getUnlinkedBundles(context);
788 expect(bundles, hasLength(1));
789 // We get the unlinked bundle for 'aaa' because it already exists.
790 {
791 PackageBundle bundle = _getBundleByPackageName(bundles, 'aaa');
792 expect(bundle, isNotNull);
793 }
794 }
795
796 // Wait for unlinked bundles to be computed.
797 await manager.onUnlinkedComplete;
798 Map<PubPackage, PackageBundle> bundles =
799 manager.getUnlinkedBundles(context);
800 expect(bundles, hasLength(2));
801 // We still have the unlinked bundle for 'aaa'.
802 {
803 PackageBundle bundle = _getBundleByPackageName(bundles, 'aaa');
804 expect(bundle, isNotNull);
805 }
806 // We computed the unlinked bundle for 'bbb'.
807 {
808 PackageBundle bundle = _getBundleByPackageName(bundles, 'bbb');
809 expect(bundle.linkedLibraryUris, isEmpty);
810 expect(bundle.unlinkedUnitUris, ['package:bbb/b.dart']);
811 expect(bundle.unlinkedUnits, hasLength(1));
812 expect(bundle.unlinkedUnits[0].classes.map((c) => c.name), ['B']);
813 }
814
815 // The files must be created.
816 _assertFileExists(libFolderB.parent, PubSummaryManager.UNLINKED_NAME);
817 _assertFileExists(libFolderB.parent, PubSummaryManager.UNLINKED_SPEC_NAME);
818 }
819
694 test_getUnlinkedBundles_nullPackageMap() async { 820 test_getUnlinkedBundles_nullPackageMap() async {
695 context.sourceFactory = 821 context.sourceFactory =
696 new SourceFactory(<UriResolver>[sdkResolver, resourceResolver]); 822 new SourceFactory(<UriResolver>[sdkResolver, resourceResolver]);
697 Map<PubPackage, PackageBundle> bundles = 823 Map<PubPackage, PackageBundle> bundles =
698 manager.getUnlinkedBundles(context); 824 manager.getUnlinkedBundles(context);
699 expect(bundles, isEmpty); 825 expect(bundles, isEmpty);
700 } 826 }
701 827
702 test_isPathInPubCache_posix() { 828 test_isPathInPubCache_posix() {
703 expect( 829 expect(
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 }); 909 });
784 } 910 }
785 911
786 static PackageBundle _getBundleByPackageName( 912 static PackageBundle _getBundleByPackageName(
787 Map<PubPackage, PackageBundle> bundles, String name) { 913 Map<PubPackage, PackageBundle> bundles, String name) {
788 PubPackage package = 914 PubPackage package =
789 bundles.keys.singleWhere((package) => package.name == name); 915 bundles.keys.singleWhere((package) => package.name == name);
790 return bundles[package]; 916 return bundles[package];
791 } 917 }
792 } 918 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/pub_summary.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698