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