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