| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 import 'package:analyzer/file_system/file_system.dart'; |
| 6 import 'package:analyzer/source/package_map_resolver.dart'; |
| 7 import 'package:analyzer/src/generated/source.dart'; |
| 8 import 'package:analyzer/src/summary/idl.dart'; |
| 9 import 'package:analyzer/src/summary/pub_summary.dart'; |
| 10 import 'package:path/path.dart' as pathos; |
| 11 import 'package:unittest/unittest.dart' hide ERROR; |
| 12 |
| 13 import '../../reflective_tests.dart'; |
| 14 import '../../utils.dart'; |
| 15 import '../context/abstract_context.dart'; |
| 16 |
| 17 main() { |
| 18 initializeTestEnvironment(); |
| 19 runReflectiveTests(PubSummaryManagerTest); |
| 20 } |
| 21 |
| 22 @reflectiveTest |
| 23 class PubSummaryManagerTest extends AbstractContextTest { |
| 24 PubSummaryManager manager; |
| 25 |
| 26 void setUp() { |
| 27 super.setUp(); |
| 28 manager = new PubSummaryManager(resourceProvider, sdk); |
| 29 } |
| 30 |
| 31 test_getUnlinkedBundles() async { |
| 32 // Create package files. |
| 33 String cachePath = '/home/.pub-cache/hosted/pub.dartlang.org'; |
| 34 resourceProvider.newFile( |
| 35 '$cachePath/aaa/lib/a.dart', |
| 36 ''' |
| 37 class A {} |
| 38 '''); |
| 39 resourceProvider.newFile( |
| 40 '$cachePath/aaa/lib/src/a2.dart', |
| 41 ''' |
| 42 class A2 {} |
| 43 '''); |
| 44 resourceProvider.newFile( |
| 45 '$cachePath/bbb/lib/b.dart', |
| 46 ''' |
| 47 class B {} |
| 48 '''); |
| 49 |
| 50 // Configure packages resolution. |
| 51 Folder libFolderA = resourceProvider.newFolder('$cachePath/aaa/lib'); |
| 52 Folder libFolderB = resourceProvider.newFolder('$cachePath/bbb/lib'); |
| 53 context.sourceFactory = new SourceFactory(<UriResolver>[ |
| 54 sdkResolver, |
| 55 resourceResolver, |
| 56 new PackageMapUriResolver(resourceProvider, { |
| 57 'aaa': [libFolderA], |
| 58 'bbb': [libFolderB], |
| 59 }) |
| 60 ]); |
| 61 |
| 62 // No unlinked bundles yet. |
| 63 { |
| 64 Map<String, PackageBundle> bundles = manager.getUnlinkedBundles(context); |
| 65 expect(bundles, isEmpty); |
| 66 } |
| 67 |
| 68 // The requested unlinked bundles must be available after the wait. |
| 69 await manager.onUnlinkedComplete; |
| 70 { |
| 71 Map<String, PackageBundle> bundles = manager.getUnlinkedBundles(context); |
| 72 expect(bundles, hasLength(2)); |
| 73 { |
| 74 PackageBundle bundle = bundles['aaa']; |
| 75 expect(bundle.linkedLibraryUris, isEmpty); |
| 76 expect(bundle.unlinkedUnitUris, |
| 77 ['package:aaa/a.dart', 'package:aaa/src/a2.dart']); |
| 78 expect(bundle.unlinkedUnits, hasLength(2)); |
| 79 expect(bundle.unlinkedUnits[0].classes.map((c) => c.name), ['A']); |
| 80 expect(bundle.unlinkedUnits[1].classes.map((c) => c.name), ['A2']); |
| 81 } |
| 82 { |
| 83 PackageBundle bundle = bundles['bbb']; |
| 84 expect(bundle.linkedLibraryUris, isEmpty); |
| 85 expect(bundle.unlinkedUnitUris, ['package:bbb/b.dart']); |
| 86 expect(bundle.unlinkedUnits, hasLength(1)); |
| 87 expect(bundle.unlinkedUnits[0].classes.map((c) => c.name), ['B']); |
| 88 } |
| 89 } |
| 90 |
| 91 // The files must be created. |
| 92 File fileA = libFolderA.parent.getChildAssumingFile('unlinked.ds'); |
| 93 File fileB = libFolderB.parent.getChildAssumingFile('unlinked.ds'); |
| 94 expect(fileA.exists, isTrue); |
| 95 expect(fileB.exists, isTrue); |
| 96 } |
| 97 |
| 98 test_getUnlinkedBundles_nullPackageMap() async { |
| 99 context.sourceFactory = |
| 100 new SourceFactory(<UriResolver>[sdkResolver, resourceResolver]); |
| 101 Map<String, PackageBundle> bundles = manager.getUnlinkedBundles(context); |
| 102 expect(bundles, isEmpty); |
| 103 } |
| 104 |
| 105 test_isPathInPubCache_posix() { |
| 106 expect( |
| 107 PubSummaryManager.isPathInPubCache(pathos.posix, |
| 108 '/home/.pub-cache/hosted/pub.dartlang.org/foo/lib/bar.dart'), |
| 109 isTrue); |
| 110 expect( |
| 111 PubSummaryManager.isPathInPubCache( |
| 112 pathos.posix, '/home/.pub-cache/foo/lib/bar.dart'), |
| 113 isTrue); |
| 114 expect( |
| 115 PubSummaryManager.isPathInPubCache( |
| 116 pathos.posix, '/home/sources/dart/foo/lib/bar.dart'), |
| 117 isFalse); |
| 118 } |
| 119 |
| 120 test_isPathInPubCache_windows() { |
| 121 expect( |
| 122 PubSummaryManager.isPathInPubCache(pathos.windows, |
| 123 r'C:\Users\user\Setters\Pub\Cache\hosted\foo\lib\bar.dart'), |
| 124 isTrue); |
| 125 expect( |
| 126 PubSummaryManager.isPathInPubCache( |
| 127 pathos.windows, r'C:\Users\user\Sources\Dart\foo\lib\bar.dart'), |
| 128 isFalse); |
| 129 } |
| 130 } |
| OLD | NEW |