Skip to content

Commit f878dcc

Browse files
committed
Add unit tests for [Entrypoint.packageFiles] in pub.
BUG=7391 [email protected] Review URL: https://codereview.chromium.org//15213002 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@22807 260f80e4-7a28-3924-810f-c04153c831b5
1 parent ef48eb9 commit f878dcc

File tree

2 files changed

+231
-4
lines changed

2 files changed

+231
-4
lines changed

sdk/lib/_internal/pub/lib/src/entrypoint.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,18 +238,21 @@ class Entrypoint {
238238
if (dirExists(path.join(root.dir, '.git')) && gitInstalled) {
239239
// List all files that aren't gitignored, including those not checked
240240
// in to Git.
241-
return git.run(["ls-files", "--cached", "--others",
242-
"--exclude-standard", beneath]).then((files) {
241+
return git.run(
242+
["ls-files", "--cached", "--others", "--exclude-standard", beneath],
243+
workingDir: root.dir).then((files) {
243244
// Git always prints files relative to the project root, but we want
244245
// them relative to the working directory.
245246
return files.map((file) => path.join(root.dir, file));
246247
});
247248
}
248249

249-
// Skip directories and broken symlinks.
250-
return listDir(beneath, recursive: true).where(fileExists);
250+
return listDir(beneath, recursive: true);
251251
}).then((files) {
252252
return files.where((file) {
253+
// Skip directories and broken symlinks.
254+
if (!fileExists(file)) return false;
255+
253256
var relative = path.relative(file, from: beneath);
254257
if (_BLACKLISTED_FILES.contains(path.basename(relative))) return false;
255258
return !path.split(relative).any(_BLACKLISTED_DIRS.contains);
Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
// Copyright (c) 2012, 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+
library lock_file_test;
6+
7+
import 'dart:io';
8+
9+
import 'package:pathos/path.dart' as path;
10+
import 'package:scheduled_test/scheduled_test.dart';
11+
12+
import '../lib/src/entrypoint.dart';
13+
import '../lib/src/io.dart';
14+
import '../lib/src/system_cache.dart';
15+
import 'descriptor.dart' as d;
16+
import 'test_pub.dart';
17+
18+
var root;
19+
var entrypoint;
20+
21+
main() {
22+
initConfig();
23+
24+
group('not in a git repo', () {
25+
setUp(() {
26+
d.appDir([]).create();
27+
scheduleEntrypoint();
28+
});
29+
30+
31+
integration('lists files recursively', () {
32+
d.dir(appPath, [
33+
d.file('file1.txt', 'contents'),
34+
d.file('file2.txt', 'contents'),
35+
d.dir('subdir', [
36+
d.file('subfile1.txt', 'subcontents'),
37+
d.file('subfile2.txt', 'subcontents')
38+
])
39+
]).create();
40+
41+
schedule(() {
42+
expect(entrypoint.packageFiles(), completion(unorderedEquals([
43+
path.join(root, 'pubspec.yaml'),
44+
path.join(root, 'file1.txt'),
45+
path.join(root, 'file2.txt'),
46+
path.join(root, 'subdir', 'subfile1.txt'),
47+
path.join(root, 'subdir', 'subfile2.txt')
48+
])));
49+
});
50+
});
51+
52+
commonTests();
53+
});
54+
55+
group('with git', () {
56+
setUp(() {
57+
ensureGit();
58+
d.git(appPath, [d.appPubspec([])]).create();
59+
scheduleEntrypoint();
60+
});
61+
62+
integration("includes files that are or aren't checked in", () {
63+
d.dir(appPath, [
64+
d.file('file1.txt', 'contents'),
65+
d.file('file2.txt', 'contents'),
66+
d.dir('subdir', [
67+
d.file('subfile1.txt', 'subcontents'),
68+
d.file('subfile2.txt', 'subcontents')
69+
])
70+
]).create();
71+
72+
schedule(() {
73+
expect(entrypoint.packageFiles(), completion(unorderedEquals([
74+
path.join(root, 'pubspec.yaml'),
75+
path.join(root, 'file1.txt'),
76+
path.join(root, 'file2.txt'),
77+
path.join(root, 'subdir', 'subfile1.txt'),
78+
path.join(root, 'subdir', 'subfile2.txt')
79+
])));
80+
});
81+
});
82+
83+
integration("ignores files that are gitignored", () {
84+
d.dir(appPath, [
85+
d.file('.gitignore', '*.txt'),
86+
d.file('file1.txt', 'contents'),
87+
d.file('file2.text', 'contents'),
88+
d.dir('subdir', [
89+
d.file('subfile1.txt', 'subcontents'),
90+
d.file('subfile2.text', 'subcontents')
91+
])
92+
]).create();
93+
94+
schedule(() {
95+
expect(entrypoint.packageFiles(), completion(unorderedEquals([
96+
path.join(root, 'pubspec.yaml'),
97+
path.join(root, '.gitignore'),
98+
path.join(root, 'file2.text'),
99+
path.join(root, 'subdir', 'subfile2.text')
100+
])));
101+
});
102+
});
103+
104+
commonTests();
105+
});
106+
}
107+
108+
void scheduleEntrypoint() {
109+
schedule(() {
110+
root = path.join(sandboxDir, appPath);
111+
entrypoint = new Entrypoint(root, new SystemCache.withSources(root));
112+
}, 'initializing entrypoint');
113+
114+
currentSchedule.onComplete.schedule(() {
115+
entrypoint = null;
116+
}, 'nulling entrypoint');
117+
}
118+
119+
void commonTests() {
120+
integration('ignores broken symlinks', () {
121+
// Windows requires us to symlink to a directory that actually exists.
122+
d.dir(appPath, [d.dir('target')]).create();
123+
scheduleSymlink(path.join(appPath, 'target'), path.join(appPath, 'link'));
124+
schedule(() => deleteEntry(path.join(sandboxDir, appPath, 'target')));
125+
126+
schedule(() {
127+
expect(entrypoint.packageFiles(),
128+
completion(equals([path.join(root, 'pubspec.yaml')])));
129+
});
130+
});
131+
132+
integration('ignores pubspec.lock files', () {
133+
d.dir(appPath, [
134+
d.file('pubspec.lock'),
135+
d.dir('subdir', [d.file('pubspec.lock')])
136+
]).create();
137+
138+
schedule(() {
139+
expect(entrypoint.packageFiles(),
140+
completion(equals([path.join(root, 'pubspec.yaml')])));
141+
});
142+
});
143+
144+
integration('ignores packages directories', () {
145+
d.dir(appPath, [
146+
d.dir('packages', [d.file('file.txt', 'contents')]),
147+
d.dir('subdir', [
148+
d.dir('packages', [d.file('subfile.txt', 'subcontents')]),
149+
])
150+
]).create();
151+
152+
schedule(() {
153+
expect(entrypoint.packageFiles(),
154+
completion(equals([path.join(root, 'pubspec.yaml')])));
155+
});
156+
});
157+
158+
integration('allows pubspec.lock directories', () {
159+
d.dir(appPath, [
160+
d.dir('pubspec.lock', [
161+
d.file('file.txt', 'contents'),
162+
])
163+
]).create();
164+
165+
schedule(() {
166+
expect(entrypoint.packageFiles(), completion(unorderedEquals([
167+
path.join(root, 'pubspec.yaml'),
168+
path.join(root, 'pubspec.lock', 'file.txt')
169+
])));
170+
});
171+
});
172+
173+
group('and "beneath"', () {
174+
integration('only lists files beneath the given root', () {
175+
d.dir(appPath, [
176+
d.file('file1.txt', 'contents'),
177+
d.file('file2.txt', 'contents'),
178+
d.dir('subdir', [
179+
d.file('subfile1.txt', 'subcontents'),
180+
d.file('subfile2.txt', 'subcontents'),
181+
d.dir('subsubdir', [
182+
d.file('subsubfile1.txt', 'subsubcontents'),
183+
d.file('subsubfile2.txt', 'subsubcontents'),
184+
])
185+
])
186+
]).create();
187+
188+
schedule(() {
189+
expect(entrypoint.packageFiles(beneath: path.join(root, 'subdir')),
190+
completion(unorderedEquals([
191+
path.join(root, 'subdir', 'subfile1.txt'),
192+
path.join(root, 'subdir', 'subfile2.txt'),
193+
path.join(root, 'subdir', 'subsubdir', 'subsubfile1.txt'),
194+
path.join(root, 'subdir', 'subsubdir', 'subsubfile2.txt')
195+
])));
196+
});
197+
});
198+
199+
integration("doesn't care if the root is blacklisted", () {
200+
d.dir(appPath, [
201+
d.file('file1.txt', 'contents'),
202+
d.file('file2.txt', 'contents'),
203+
d.dir('packages', [
204+
d.file('subfile1.txt', 'subcontents'),
205+
d.file('subfile2.txt', 'subcontents'),
206+
d.dir('subsubdir', [
207+
d.file('subsubfile1.txt', 'subsubcontents'),
208+
d.file('subsubfile2.txt', 'subsubcontents')
209+
])
210+
])
211+
]).create();
212+
213+
schedule(() {
214+
expect(entrypoint.packageFiles(beneath: path.join(root, 'packages')),
215+
completion(unorderedEquals([
216+
path.join(root, 'packages', 'subfile1.txt'),
217+
path.join(root, 'packages', 'subfile2.txt'),
218+
path.join(root, 'packages', 'subsubdir', 'subsubfile1.txt'),
219+
path.join(root, 'packages', 'subsubdir', 'subsubfile2.txt')
220+
])));
221+
});
222+
});
223+
});
224+
}

0 commit comments

Comments
 (0)