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