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

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

Issue 2220703002: Initial implementation of pub summary manager. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: tweak 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
OLDNEW
(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:analysis_server/src/pub_summary.dart';
6 import 'package:analyzer/file_system/file_system.dart';
7 import 'package:analyzer/src/util/fast_uri.dart';
8 import 'package:path/path.dart' as pathos;
9 import 'package:test_reflective_loader/test_reflective_loader.dart';
10 import 'package:unittest/unittest.dart' hide ERROR;
11
12 import 'analysis_abstract.dart';
13 import 'mocks.dart';
14 import 'utils.dart';
15
16 main() {
17 initializeTestEnvironment();
18 defineReflectiveTests(PubSummaryManagerTest);
19 }
20
21 @reflectiveTest
22 class PubSummaryManagerTest extends AbstractAnalysisTest {
23 test_getPackageName() {
24 String getPackageName(String uriStr) {
25 return PubSummaryManager.getPackageName(FastUri.parse(uriStr));
26 }
27 expect(getPackageName('package:foo/bar.dart'), 'foo');
28 expect(getPackageName('package:foo/bar/baz.dart'), 'foo');
29 expect(getPackageName('wrong:foo/bar.dart'), isNull);
30 expect(getPackageName('package:foo'), isNull);
31 }
32
33 test_isPathInPubCache_posix() {
34 expect(
35 PubSummaryManager.isPathInPubCache(pathos.posix,
36 '/home/.pub-cache/hosted/pub.dartlang.org/foo/lib/bar.dart'),
37 isTrue);
38 expect(
39 PubSummaryManager.isPathInPubCache(
40 pathos.posix, '/home/.pub-cache/foo/lib/bar.dart'),
41 isTrue);
42 expect(
43 PubSummaryManager.isPathInPubCache(
44 pathos.posix, '/home/sources/dart/foo/lib/bar.dart'),
45 isFalse);
46 }
47
48 test_isPathInPubCache_windows() {
49 expect(
50 PubSummaryManager.isPathInPubCache(pathos.windows,
51 r'C:\Users\user\Setters\Pub\Cache\hosted\foo\lib\bar.dart'),
52 isTrue);
53 expect(
54 PubSummaryManager.isPathInPubCache(
55 pathos.windows, r'C:\Users\user\Sources\Dart\foo\lib\bar.dart'),
56 isFalse);
57 }
58
59 test_onComplete() async {
60 String cachePath = '/home/.pub-cache/hosted/pub.dartlang.org';
61 // Create package files.
62 resourceProvider.newFile(
63 '$cachePath/aaa/lib/a.dart',
64 '''
65 class A {}
66 ''');
67 resourceProvider.newFile(
68 '$cachePath/aaa/lib/src/a2.dart',
69 '''
70 class A2 {}
71 ''');
72 resourceProvider.newFile(
73 '$cachePath/bbb/lib/b.dart',
74 '''
75 class B {}
76 ''');
77 // Configure package map.
78 Folder libFolderA = resourceProvider.newFolder('$cachePath/aaa/lib');
79 Folder libFolderB = resourceProvider.newFolder('$cachePath/bbb/lib');
80 packageMapProvider.packageMap = {
81 'aaa': [libFolderA],
82 'bbb': [libFolderB],
83 };
84
85 // Analyze a file that uses these two packages.
86 addTestFile('''
87 import 'package:aaa/a.dart';
88 import 'package:bbb/b.dart';
89 main() {
90 new A();
91 new B();
92 }
93 ''');
94 createProject();
95 await pumpEventQueue();
96 await server.pubSummaryManager.onComplete;
97 // The summary files must be ready.
98 File fileA = libFolderA.parent.getChildAssumingFile('summary_spec.full.ds');
99 File fileB = libFolderB.parent.getChildAssumingFile('summary_spec.full.ds');
100 expect(fileA.exists, isTrue);
101 expect(fileB.exists, isTrue);
102 }
103 }
OLDNEW
« pkg/analysis_server/lib/src/pub_summary.dart ('K') | « pkg/analysis_server/lib/src/pub_summary.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698