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_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 var root; | |
17 var 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.packageFiles(), 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.packageFiles(), 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", () { | |
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.packageFiles(), 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 | |
102 commonTests(); | |
103 }); | |
104 } | |
105 | |
106 void scheduleEntrypoint() { | |
107 schedule(() { | |
108 root = path.join(sandboxDir, appPath); | |
109 entrypoint = new Entrypoint(root, new SystemCache.withSources(root)); | |
110 }, 'initializing entrypoint'); | |
111 | |
112 currentSchedule.onComplete.schedule(() { | |
113 entrypoint = null; | |
114 }, 'nulling entrypoint'); | |
115 } | |
116 | |
117 void commonTests() { | |
118 integration('ignores broken symlinks', () { | |
119 // Windows requires us to symlink to a directory that actually exists. | |
120 d.dir(appPath, [d.dir('target')]).create(); | |
121 scheduleSymlink(path.join(appPath, 'target'), path.join(appPath, 'link')); | |
122 schedule(() => deleteEntry(path.join(sandboxDir, appPath, 'target'))); | |
123 | |
124 schedule(() { | |
125 expect(entrypoint.packageFiles(), | |
126 equals([path.join(root, 'pubspec.yaml')])); | |
127 }); | |
128 }); | |
129 | |
130 integration('ignores pubspec.lock files', () { | |
131 d.dir(appPath, [ | |
132 d.file('pubspec.lock'), | |
133 d.dir('subdir', [d.file('pubspec.lock')]) | |
134 ]).create(); | |
135 | |
136 schedule(() { | |
137 expect(entrypoint.packageFiles(), | |
138 equals([path.join(root, 'pubspec.yaml')])); | |
139 }); | |
140 }); | |
141 | |
142 integration('ignores packages directories', () { | |
143 d.dir(appPath, [ | |
144 d.dir('packages', [d.file('file.txt', 'contents')]), | |
145 d.dir('subdir', [ | |
146 d.dir('packages', [d.file('subfile.txt', 'subcontents')]), | |
147 ]) | |
148 ]).create(); | |
149 | |
150 schedule(() { | |
151 expect(entrypoint.packageFiles(), | |
152 equals([path.join(root, 'pubspec.yaml')])); | |
153 }); | |
154 }); | |
155 | |
156 integration('allows pubspec.lock directories', () { | |
157 d.dir(appPath, [ | |
158 d.dir('pubspec.lock', [ | |
159 d.file('file.txt', 'contents'), | |
160 ]) | |
161 ]).create(); | |
162 | |
163 schedule(() { | |
164 expect(entrypoint.packageFiles(), unorderedEquals([ | |
165 path.join(root, 'pubspec.yaml'), | |
166 path.join(root, 'pubspec.lock', 'file.txt') | |
167 ])); | |
168 }); | |
169 }); | |
170 | |
171 group('and "beneath"', () { | |
172 integration('only lists files beneath the given root', () { | |
173 d.dir(appPath, [ | |
174 d.file('file1.txt', 'contents'), | |
175 d.file('file2.txt', 'contents'), | |
176 d.dir('subdir', [ | |
177 d.file('subfile1.txt', 'subcontents'), | |
178 d.file('subfile2.txt', 'subcontents'), | |
179 d.dir('subsubdir', [ | |
180 d.file('subsubfile1.txt', 'subsubcontents'), | |
181 d.file('subsubfile2.txt', 'subsubcontents'), | |
182 ]) | |
183 ]) | |
184 ]).create(); | |
185 | |
186 schedule(() { | |
187 expect(entrypoint.packageFiles(beneath: path.join(root, 'subdir')), | |
188 unorderedEquals([ | |
189 path.join(root, 'subdir', 'subfile1.txt'), | |
190 path.join(root, 'subdir', 'subfile2.txt'), | |
191 path.join(root, 'subdir', 'subsubdir', 'subsubfile1.txt'), | |
192 path.join(root, 'subdir', 'subsubdir', 'subsubfile2.txt') | |
193 ])); | |
194 }); | |
195 }); | |
196 | |
197 integration("doesn't care if the root is blacklisted", () { | |
198 d.dir(appPath, [ | |
199 d.file('file1.txt', 'contents'), | |
200 d.file('file2.txt', 'contents'), | |
201 d.dir('packages', [ | |
202 d.file('subfile1.txt', 'subcontents'), | |
203 d.file('subfile2.txt', 'subcontents'), | |
204 d.dir('subsubdir', [ | |
205 d.file('subsubfile1.txt', 'subsubcontents'), | |
206 d.file('subsubfile2.txt', 'subsubcontents') | |
207 ]) | |
208 ]) | |
209 ]).create(); | |
210 | |
211 schedule(() { | |
212 expect(entrypoint.packageFiles(beneath: path.join(root, 'packages')), | |
213 unorderedEquals([ | |
214 path.join(root, 'packages', 'subfile1.txt'), | |
215 path.join(root, 'packages', 'subfile2.txt'), | |
216 path.join(root, 'packages', 'subsubdir', 'subsubfile1.txt'), | |
217 path.join(root, 'packages', 'subsubdir', 'subsubfile2.txt') | |
218 ])); | |
219 }); | |
220 }); | |
221 }); | |
222 } | |
OLD | NEW |