OLD | NEW |
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 io_test; | 1 library io_test; |
6 | |
7 import 'dart:async'; | 2 import 'dart:async'; |
8 import 'dart:io'; | 3 import 'dart:io'; |
9 | |
10 import 'package:path/path.dart' as path; | 4 import 'package:path/path.dart' as path; |
11 import 'package:unittest/unittest.dart'; | 5 import 'package:unittest/unittest.dart'; |
12 | |
13 import '../lib/src/io.dart'; | 6 import '../lib/src/io.dart'; |
14 import 'test_pub.dart'; | 7 import 'test_pub.dart'; |
15 | |
16 main() { | 8 main() { |
17 initConfig(); | 9 initConfig(); |
18 | |
19 group('listDir', () { | 10 group('listDir', () { |
20 test('ignores hidden files by default', () { | 11 test('ignores hidden files by default', () { |
21 expect(withTempDir((temp) { | 12 expect(withTempDir((temp) { |
22 writeTextFile(path.join(temp, 'file1.txt'), ''); | 13 writeTextFile(path.join(temp, 'file1.txt'), ''); |
23 writeTextFile(path.join(temp, 'file2.txt'), ''); | 14 writeTextFile(path.join(temp, 'file2.txt'), ''); |
24 writeTextFile(path.join(temp, '.file3.txt'), ''); | 15 writeTextFile(path.join(temp, '.file3.txt'), ''); |
25 createDir(path.join(temp, '.subdir')); | 16 createDir(path.join(temp, '.subdir')); |
26 writeTextFile(path.join(temp, '.subdir', 'file3.txt'), ''); | 17 writeTextFile(path.join(temp, '.subdir', 'file3.txt'), ''); |
27 | 18 expect( |
28 expect(listDir(temp, recursive: true), unorderedEquals([ | 19 listDir(temp, recursive: true), |
29 path.join(temp, 'file1.txt'), | 20 unorderedEquals([path.join(temp, 'file1.txt'), path.join(temp, 'file
2.txt')])); |
30 path.join(temp, 'file2.txt') | |
31 ])); | |
32 }), completes); | 21 }), completes); |
33 }); | 22 }); |
34 | |
35 test('includes hidden files when told to', () { | 23 test('includes hidden files when told to', () { |
36 expect(withTempDir((temp) { | 24 expect(withTempDir((temp) { |
37 writeTextFile(path.join(temp, 'file1.txt'), ''); | 25 writeTextFile(path.join(temp, 'file1.txt'), ''); |
38 writeTextFile(path.join(temp, 'file2.txt'), ''); | 26 writeTextFile(path.join(temp, 'file2.txt'), ''); |
39 writeTextFile(path.join(temp, '.file3.txt'), ''); | 27 writeTextFile(path.join(temp, '.file3.txt'), ''); |
40 createDir(path.join(temp, '.subdir')); | 28 createDir(path.join(temp, '.subdir')); |
41 writeTextFile(path.join(temp, '.subdir', 'file3.txt'), ''); | 29 writeTextFile(path.join(temp, '.subdir', 'file3.txt'), ''); |
42 | 30 expect( |
43 expect(listDir(temp, recursive: true, includeHidden: true), | 31 listDir(temp, recursive: true, includeHidden: true), |
44 unorderedEquals([ | 32 unorderedEquals( |
45 path.join(temp, 'file1.txt'), | 33 [ |
46 path.join(temp, 'file2.txt'), | 34 path.join(temp, 'file1.txt'), |
47 path.join(temp, '.file3.txt'), | 35 path.join(temp, 'file2.txt'), |
48 path.join(temp, '.subdir'), | 36 path.join(temp, '.file3.txt'), |
49 path.join(temp, '.subdir', 'file3.txt') | 37 path.join(temp, '.subdir'), |
50 ])); | 38 path.join(temp, '.subdir', 'file3.txt')])); |
51 }), completes); | 39 }), completes); |
52 }); | 40 }); |
53 | |
54 test("doesn't ignore hidden files above the directory being listed", () { | 41 test("doesn't ignore hidden files above the directory being listed", () { |
55 expect(withTempDir((temp) { | 42 expect(withTempDir((temp) { |
56 var dir = path.join(temp, '.foo', 'bar'); | 43 var dir = path.join(temp, '.foo', 'bar'); |
57 ensureDir(dir); | 44 ensureDir(dir); |
58 writeTextFile(path.join(dir, 'file1.txt'), ''); | 45 writeTextFile(path.join(dir, 'file1.txt'), ''); |
59 writeTextFile(path.join(dir, 'file2.txt'), ''); | 46 writeTextFile(path.join(dir, 'file2.txt'), ''); |
60 writeTextFile(path.join(dir, 'file3.txt'), ''); | 47 writeTextFile(path.join(dir, 'file3.txt'), ''); |
61 | 48 expect( |
62 expect(listDir(dir, recursive: true), unorderedEquals([ | 49 listDir(dir, recursive: true), |
63 path.join(dir, 'file1.txt'), | 50 unorderedEquals( |
64 path.join(dir, 'file2.txt'), | 51 [ |
65 path.join(dir, 'file3.txt') | 52 path.join(dir, 'file1.txt'), |
66 ])); | 53 path.join(dir, 'file2.txt'), |
| 54 path.join(dir, 'file3.txt')])); |
67 }), completes); | 55 }), completes); |
68 }); | 56 }); |
69 }); | 57 }); |
70 | |
71 group('canonicalize', () { | 58 group('canonicalize', () { |
72 test('resolves a non-link', () { | 59 test('resolves a non-link', () { |
73 expect(withCanonicalTempDir((temp) { | 60 expect(withCanonicalTempDir((temp) { |
74 var filePath = path.join(temp, 'file'); | 61 var filePath = path.join(temp, 'file'); |
75 writeTextFile(filePath, ''); | 62 writeTextFile(filePath, ''); |
76 expect(canonicalize(filePath), equals(filePath)); | 63 expect(canonicalize(filePath), equals(filePath)); |
77 }), completes); | 64 }), completes); |
78 }); | 65 }); |
79 | |
80 test('resolves a non-existent file', () { | 66 test('resolves a non-existent file', () { |
81 expect(withCanonicalTempDir((temp) { | 67 expect(withCanonicalTempDir((temp) { |
82 expect(canonicalize(path.join(temp, 'nothing')), | 68 expect( |
| 69 canonicalize(path.join(temp, 'nothing')), |
83 equals(path.join(temp, 'nothing'))); | 70 equals(path.join(temp, 'nothing'))); |
84 }), completes); | 71 }), completes); |
85 }); | 72 }); |
86 | |
87 test('resolves a symlink', () { | 73 test('resolves a symlink', () { |
88 expect(withCanonicalTempDir((temp) { | 74 expect(withCanonicalTempDir((temp) { |
89 createDir(path.join(temp, 'linked-dir')); | 75 createDir(path.join(temp, 'linked-dir')); |
90 createSymlink( | 76 createSymlink(path.join(temp, 'linked-dir'), path.join(temp, 'dir')); |
91 path.join(temp, 'linked-dir'), | |
92 path.join(temp, 'dir')); | |
93 expect( | 77 expect( |
94 canonicalize(path.join(temp, 'dir')), | 78 canonicalize(path.join(temp, 'dir')), |
95 equals(path.join(temp, 'linked-dir'))); | 79 equals(path.join(temp, 'linked-dir'))); |
96 }), completes); | 80 }), completes); |
97 }); | 81 }); |
98 | |
99 test('resolves a relative symlink', () { | 82 test('resolves a relative symlink', () { |
100 expect(withCanonicalTempDir((temp) { | 83 expect(withCanonicalTempDir((temp) { |
101 createDir(path.join(temp, 'linked-dir')); | 84 createDir(path.join(temp, 'linked-dir')); |
102 createSymlink( | 85 createSymlink( |
103 path.join(temp, 'linked-dir'), | 86 path.join(temp, 'linked-dir'), |
104 path.join(temp, 'dir'), | 87 path.join(temp, 'dir'), |
105 relative: true); | 88 relative: true); |
106 expect( | 89 expect( |
107 canonicalize(path.join(temp, 'dir')), | 90 canonicalize(path.join(temp, 'dir')), |
108 equals(path.join(temp, 'linked-dir'))); | 91 equals(path.join(temp, 'linked-dir'))); |
109 }), completes); | 92 }), completes); |
110 }); | 93 }); |
111 | |
112 test('resolves a single-level horizontally recursive symlink', () { | 94 test('resolves a single-level horizontally recursive symlink', () { |
113 expect(withCanonicalTempDir((temp) { | 95 expect(withCanonicalTempDir((temp) { |
114 var linkPath = path.join(temp, 'foo'); | 96 var linkPath = path.join(temp, 'foo'); |
115 createSymlink(linkPath, linkPath); | 97 createSymlink(linkPath, linkPath); |
116 expect(canonicalize(linkPath), equals(linkPath)); | 98 expect(canonicalize(linkPath), equals(linkPath)); |
117 }), completes); | 99 }), completes); |
118 }); | 100 }); |
119 | |
120 test('resolves a multi-level horizontally recursive symlink', () { | 101 test('resolves a multi-level horizontally recursive symlink', () { |
121 expect(withCanonicalTempDir((temp) { | 102 expect(withCanonicalTempDir((temp) { |
122 var fooPath = path.join(temp, 'foo'); | 103 var fooPath = path.join(temp, 'foo'); |
123 var barPath = path.join(temp, 'bar'); | 104 var barPath = path.join(temp, 'bar'); |
124 var bazPath = path.join(temp, 'baz'); | 105 var bazPath = path.join(temp, 'baz'); |
125 createSymlink(barPath, fooPath); | 106 createSymlink(barPath, fooPath); |
126 createSymlink(bazPath, barPath); | 107 createSymlink(bazPath, barPath); |
127 createSymlink(fooPath, bazPath); | 108 createSymlink(fooPath, bazPath); |
128 expect(canonicalize(fooPath), equals(fooPath)); | 109 expect(canonicalize(fooPath), equals(fooPath)); |
129 expect(canonicalize(barPath), equals(barPath)); | 110 expect(canonicalize(barPath), equals(barPath)); |
130 expect(canonicalize(bazPath), equals(bazPath)); | 111 expect(canonicalize(bazPath), equals(bazPath)); |
131 | |
132 createSymlink(fooPath, path.join(temp, 'outer')); | 112 createSymlink(fooPath, path.join(temp, 'outer')); |
133 expect(canonicalize(path.join(temp, 'outer')), equals(fooPath)); | 113 expect(canonicalize(path.join(temp, 'outer')), equals(fooPath)); |
134 }), completes); | 114 }), completes); |
135 }); | 115 }); |
136 | |
137 test('resolves a broken symlink', () { | 116 test('resolves a broken symlink', () { |
138 expect(withCanonicalTempDir((temp) { | 117 expect(withCanonicalTempDir((temp) { |
139 createSymlink(path.join(temp, 'nonexistent'), path.join(temp, 'foo')); | 118 createSymlink(path.join(temp, 'nonexistent'), path.join(temp, 'foo')); |
140 expect( | 119 expect( |
141 canonicalize(path.join(temp, 'foo')), | 120 canonicalize(path.join(temp, 'foo')), |
142 equals(path.join(temp, 'nonexistent'))); | 121 equals(path.join(temp, 'nonexistent'))); |
143 }), completes); | 122 }), completes); |
144 }); | 123 }); |
145 | |
146 test('resolves multiple nested symlinks', () { | 124 test('resolves multiple nested symlinks', () { |
147 expect(withCanonicalTempDir((temp) { | 125 expect(withCanonicalTempDir((temp) { |
148 var dir1 = path.join(temp, 'dir1'); | 126 var dir1 = path.join(temp, 'dir1'); |
149 var dir2 = path.join(temp, 'dir2'); | 127 var dir2 = path.join(temp, 'dir2'); |
150 var subdir1 = path.join(dir1, 'subdir1'); | 128 var subdir1 = path.join(dir1, 'subdir1'); |
151 var subdir2 = path.join(dir2, 'subdir2'); | 129 var subdir2 = path.join(dir2, 'subdir2'); |
152 createDir(dir2); | 130 createDir(dir2); |
153 createDir(subdir2); | 131 createDir(subdir2); |
154 createSymlink(dir2, dir1); | 132 createSymlink(dir2, dir1); |
155 createSymlink(subdir2, subdir1); | 133 createSymlink(subdir2, subdir1); |
156 expect( | 134 expect( |
157 canonicalize(path.join(subdir1, 'file')), | 135 canonicalize(path.join(subdir1, 'file')), |
158 equals(path.join(subdir2, 'file'))); | 136 equals(path.join(subdir2, 'file'))); |
159 }), completes); | 137 }), completes); |
160 }); | 138 }); |
161 | |
162 test('resolves a nested vertical symlink', () { | 139 test('resolves a nested vertical symlink', () { |
163 expect(withCanonicalTempDir((temp) { | 140 expect(withCanonicalTempDir((temp) { |
164 var dir1 = path.join(temp, 'dir1'); | 141 var dir1 = path.join(temp, 'dir1'); |
165 var dir2 = path.join(temp, 'dir2'); | 142 var dir2 = path.join(temp, 'dir2'); |
166 var subdir = path.join(dir1, 'subdir'); | 143 var subdir = path.join(dir1, 'subdir'); |
167 createDir(dir1); | 144 createDir(dir1); |
168 createDir(dir2); | 145 createDir(dir2); |
169 createSymlink(dir2, subdir); | 146 createSymlink(dir2, subdir); |
170 expect( | 147 expect( |
171 canonicalize(path.join(subdir, 'file')), | 148 canonicalize(path.join(subdir, 'file')), |
172 equals(path.join(dir2, 'file'))); | 149 equals(path.join(dir2, 'file'))); |
173 }), completes); | 150 }), completes); |
174 }); | 151 }); |
175 | |
176 test('resolves a vertically recursive symlink', () { | 152 test('resolves a vertically recursive symlink', () { |
177 expect(withCanonicalTempDir((temp) { | 153 expect(withCanonicalTempDir((temp) { |
178 var dir = path.join(temp, 'dir'); | 154 var dir = path.join(temp, 'dir'); |
179 var subdir = path.join(dir, 'subdir'); | 155 var subdir = path.join(dir, 'subdir'); |
180 createDir(dir); | 156 createDir(dir); |
181 createSymlink(dir, subdir); | 157 createSymlink(dir, subdir); |
182 expect( | 158 expect( |
183 canonicalize(path.join(temp, 'dir', 'subdir', 'subdir', 'subdir', | 159 canonicalize( |
184 'subdir', 'file')), | 160 path.join(temp, 'dir', 'subdir', 'subdir', 'subdir', 'subdir', '
file')), |
185 equals(path.join(dir, 'file'))); | 161 equals(path.join(dir, 'file'))); |
186 }), completes); | 162 }), completes); |
187 }); | 163 }); |
188 | 164 test( |
189 test('resolves a symlink that links to a path that needs more resolving', | 165 'resolves a symlink that links to a path that needs more resolving', |
190 () { | 166 () { |
191 expect(withCanonicalTempDir((temp) { | 167 expect(withCanonicalTempDir((temp) { |
192 var dir = path.join(temp, 'dir'); | 168 var dir = path.join(temp, 'dir'); |
193 var linkdir = path.join(temp, 'linkdir'); | 169 var linkdir = path.join(temp, 'linkdir'); |
194 var linkfile = path.join(dir, 'link'); | 170 var linkfile = path.join(dir, 'link'); |
195 createDir(dir); | 171 createDir(dir); |
196 createSymlink(dir, linkdir); | 172 createSymlink(dir, linkdir); |
197 createSymlink(path.join(linkdir, 'file'), linkfile); | 173 createSymlink(path.join(linkdir, 'file'), linkfile); |
198 expect( | 174 expect(canonicalize(linkfile), equals(path.join(dir, 'file'))); |
199 canonicalize(linkfile), | |
200 equals(path.join(dir, 'file'))); | |
201 }), completes); | 175 }), completes); |
202 }); | 176 }); |
203 | |
204 test('resolves a pair of pathologically-recursive symlinks', () { | 177 test('resolves a pair of pathologically-recursive symlinks', () { |
205 expect(withCanonicalTempDir((temp) { | 178 expect(withCanonicalTempDir((temp) { |
206 var foo = path.join(temp, 'foo'); | 179 var foo = path.join(temp, 'foo'); |
207 var subfoo = path.join(foo, 'subfoo'); | 180 var subfoo = path.join(foo, 'subfoo'); |
208 var bar = path.join(temp, 'bar'); | 181 var bar = path.join(temp, 'bar'); |
209 var subbar = path.join(bar, 'subbar'); | 182 var subbar = path.join(bar, 'subbar'); |
210 createSymlink(subbar, foo); | 183 createSymlink(subbar, foo); |
211 createSymlink(subfoo, bar); | 184 createSymlink(subfoo, bar); |
212 expect( | 185 expect( |
213 canonicalize(subfoo), | 186 canonicalize(subfoo), |
214 equals(path.join(subfoo, 'subbar', 'subfoo'))); | 187 equals(path.join(subfoo, 'subbar', 'subfoo'))); |
215 }), completes); | 188 }), completes); |
216 }); | 189 }); |
217 }); | 190 }); |
218 | 191 testExistencePredicate( |
219 testExistencePredicate("entryExists", entryExists, | 192 "entryExists", |
| 193 entryExists, |
220 forFile: true, | 194 forFile: true, |
221 forFileSymlink: true, | 195 forFileSymlink: true, |
222 forMultiLevelFileSymlink: true, | 196 forMultiLevelFileSymlink: true, |
223 forDirectory: true, | 197 forDirectory: true, |
224 forDirectorySymlink: true, | 198 forDirectorySymlink: true, |
225 forMultiLevelDirectorySymlink: true, | 199 forMultiLevelDirectorySymlink: true, |
226 forBrokenSymlink: true, | 200 forBrokenSymlink: true, |
227 forMultiLevelBrokenSymlink: true); | 201 forMultiLevelBrokenSymlink: true); |
228 | 202 testExistencePredicate( |
229 testExistencePredicate("linkExists", linkExists, | 203 "linkExists", |
| 204 linkExists, |
230 forFile: false, | 205 forFile: false, |
231 forFileSymlink: true, | 206 forFileSymlink: true, |
232 forMultiLevelFileSymlink: true, | 207 forMultiLevelFileSymlink: true, |
233 forDirectory: false, | 208 forDirectory: false, |
234 forDirectorySymlink: true, | 209 forDirectorySymlink: true, |
235 forMultiLevelDirectorySymlink: true, | 210 forMultiLevelDirectorySymlink: true, |
236 forBrokenSymlink: true, | 211 forBrokenSymlink: true, |
237 forMultiLevelBrokenSymlink: true); | 212 forMultiLevelBrokenSymlink: true); |
238 | 213 testExistencePredicate( |
239 testExistencePredicate("fileExists", fileExists, | 214 "fileExists", |
| 215 fileExists, |
240 forFile: true, | 216 forFile: true, |
241 forFileSymlink: true, | 217 forFileSymlink: true, |
242 forMultiLevelFileSymlink: true, | 218 forMultiLevelFileSymlink: true, |
243 forDirectory: false, | 219 forDirectory: false, |
244 forDirectorySymlink: false, | 220 forDirectorySymlink: false, |
245 forMultiLevelDirectorySymlink: false, | 221 forMultiLevelDirectorySymlink: false, |
246 forBrokenSymlink: false, | 222 forBrokenSymlink: false, |
247 forMultiLevelBrokenSymlink: false); | 223 forMultiLevelBrokenSymlink: false); |
248 | 224 testExistencePredicate( |
249 testExistencePredicate("dirExists", dirExists, | 225 "dirExists", |
| 226 dirExists, |
250 forFile: false, | 227 forFile: false, |
251 forFileSymlink: false, | 228 forFileSymlink: false, |
252 forMultiLevelFileSymlink: false, | 229 forMultiLevelFileSymlink: false, |
253 forDirectory: true, | 230 forDirectory: true, |
254 forDirectorySymlink: true, | 231 forDirectorySymlink: true, |
255 forMultiLevelDirectorySymlink: true, | 232 forMultiLevelDirectorySymlink: true, |
256 forBrokenSymlink: false, | 233 forBrokenSymlink: false, |
257 forMultiLevelBrokenSymlink: false); | 234 forMultiLevelBrokenSymlink: false); |
258 } | 235 } |
259 | |
260 void testExistencePredicate(String name, bool predicate(String path), | 236 void testExistencePredicate(String name, bool predicate(String path), |
261 {bool forFile, | 237 {bool forFile, bool forFileSymlink, bool forMultiLevelFileSymlink, |
262 bool forFileSymlink, | 238 bool forDirectory, bool forDirectorySymlink, bool forMultiLevelDirectorySyml
ink, |
263 bool forMultiLevelFileSymlink, | 239 bool forBrokenSymlink, bool forMultiLevelBrokenSymlink}) { |
264 bool forDirectory, | |
265 bool forDirectorySymlink, | |
266 bool forMultiLevelDirectorySymlink, | |
267 bool forBrokenSymlink, | |
268 bool forMultiLevelBrokenSymlink}) { | |
269 group(name, () { | 240 group(name, () { |
270 test('returns $forFile for a file', () { | 241 test('returns $forFile for a file', () { |
271 expect(withTempDir((temp) { | 242 expect(withTempDir((temp) { |
272 var file = path.join(temp, "test.txt"); | 243 var file = path.join(temp, "test.txt"); |
273 writeTextFile(file, "contents"); | 244 writeTextFile(file, "contents"); |
274 expect(predicate(file), equals(forFile)); | 245 expect(predicate(file), equals(forFile)); |
275 }), completes); | 246 }), completes); |
276 }); | 247 }); |
277 | |
278 test('returns $forDirectory for a directory', () { | 248 test('returns $forDirectory for a directory', () { |
279 expect(withTempDir((temp) { | 249 expect(withTempDir((temp) { |
280 var file = path.join(temp, "dir"); | 250 var file = path.join(temp, "dir"); |
281 createDir(file); | 251 createDir(file); |
282 expect(predicate(file), equals(forDirectory)); | 252 expect(predicate(file), equals(forDirectory)); |
283 }), completes); | 253 }), completes); |
284 }); | 254 }); |
285 | |
286 test('returns $forDirectorySymlink for a symlink to a directory', () { | 255 test('returns $forDirectorySymlink for a symlink to a directory', () { |
287 expect(withTempDir((temp) { | 256 expect(withTempDir((temp) { |
288 var targetPath = path.join(temp, "dir"); | 257 var targetPath = path.join(temp, "dir"); |
289 var symlinkPath = path.join(temp, "linkdir"); | 258 var symlinkPath = path.join(temp, "linkdir"); |
290 createDir(targetPath); | 259 createDir(targetPath); |
291 createSymlink(targetPath, symlinkPath); | 260 createSymlink(targetPath, symlinkPath); |
292 expect(predicate(symlinkPath), equals(forDirectorySymlink)); | 261 expect(predicate(symlinkPath), equals(forDirectorySymlink)); |
293 }), completes); | 262 }), completes); |
294 }); | 263 }); |
295 | 264 test( |
296 test('returns $forMultiLevelDirectorySymlink for a multi-level symlink to ' | 265 'returns $forMultiLevelDirectorySymlink for a multi-level symlink to ' |
297 'a directory', () { | 266 'a directory', |
| 267 () { |
298 expect(withTempDir((temp) { | 268 expect(withTempDir((temp) { |
299 var targetPath = path.join(temp, "dir"); | 269 var targetPath = path.join(temp, "dir"); |
300 var symlink1Path = path.join(temp, "link1dir"); | 270 var symlink1Path = path.join(temp, "link1dir"); |
301 var symlink2Path = path.join(temp, "link2dir"); | 271 var symlink2Path = path.join(temp, "link2dir"); |
302 createDir(targetPath); | 272 createDir(targetPath); |
303 createSymlink(targetPath, symlink1Path); | 273 createSymlink(targetPath, symlink1Path); |
304 createSymlink(symlink1Path, symlink2Path); | 274 createSymlink(symlink1Path, symlink2Path); |
305 expect(predicate(symlink2Path), | 275 expect(predicate(symlink2Path), equals(forMultiLevelDirectorySymlink)); |
306 equals(forMultiLevelDirectorySymlink)); | |
307 }), completes); | 276 }), completes); |
308 }); | 277 }); |
309 | |
310 test('returns $forBrokenSymlink for a broken symlink', () { | 278 test('returns $forBrokenSymlink for a broken symlink', () { |
311 expect(withTempDir((temp) { | 279 expect(withTempDir((temp) { |
312 var targetPath = path.join(temp, "dir"); | 280 var targetPath = path.join(temp, "dir"); |
313 var symlinkPath = path.join(temp, "linkdir"); | 281 var symlinkPath = path.join(temp, "linkdir"); |
314 createDir(targetPath); | 282 createDir(targetPath); |
315 createSymlink(targetPath, symlinkPath); | 283 createSymlink(targetPath, symlinkPath); |
316 deleteEntry(targetPath); | 284 deleteEntry(targetPath); |
317 expect(predicate(symlinkPath), equals(forBrokenSymlink)); | 285 expect(predicate(symlinkPath), equals(forBrokenSymlink)); |
318 }), completes); | 286 }), completes); |
319 }); | 287 }); |
320 | 288 test( |
321 test('returns $forMultiLevelBrokenSymlink for a multi-level broken symlink', | 289 'returns $forMultiLevelBrokenSymlink for a multi-level broken symlink', |
322 () { | 290 () { |
323 expect(withTempDir((temp) { | 291 expect(withTempDir((temp) { |
324 var targetPath = path.join(temp, "dir"); | 292 var targetPath = path.join(temp, "dir"); |
325 var symlink1Path = path.join(temp, "link1dir"); | 293 var symlink1Path = path.join(temp, "link1dir"); |
326 var symlink2Path = path.join(temp, "link2dir"); | 294 var symlink2Path = path.join(temp, "link2dir"); |
327 createDir(targetPath); | 295 createDir(targetPath); |
328 createSymlink(targetPath, symlink1Path); | 296 createSymlink(targetPath, symlink1Path); |
329 createSymlink(symlink1Path, symlink2Path); | 297 createSymlink(symlink1Path, symlink2Path); |
330 deleteEntry(targetPath); | 298 deleteEntry(targetPath); |
331 expect(predicate(symlink2Path), equals(forMultiLevelBrokenSymlink)); | 299 expect(predicate(symlink2Path), equals(forMultiLevelBrokenSymlink)); |
332 }), completes); | 300 }), completes); |
333 }); | 301 }); |
334 | |
335 // Windows doesn't support symlinking to files. | |
336 if (Platform.operatingSystem != 'windows') { | 302 if (Platform.operatingSystem != 'windows') { |
337 test('returns $forFileSymlink for a symlink to a file', () { | 303 test('returns $forFileSymlink for a symlink to a file', () { |
338 expect(withTempDir((temp) { | 304 expect(withTempDir((temp) { |
339 var targetPath = path.join(temp, "test.txt"); | 305 var targetPath = path.join(temp, "test.txt"); |
340 var symlinkPath = path.join(temp, "link.txt"); | 306 var symlinkPath = path.join(temp, "link.txt"); |
341 writeTextFile(targetPath, "contents"); | 307 writeTextFile(targetPath, "contents"); |
342 createSymlink(targetPath, symlinkPath); | 308 createSymlink(targetPath, symlinkPath); |
343 expect(predicate(symlinkPath), equals(forFileSymlink)); | 309 expect(predicate(symlinkPath), equals(forFileSymlink)); |
344 }), completes); | 310 }), completes); |
345 }); | 311 }); |
346 | 312 test( |
347 test('returns $forMultiLevelFileSymlink for a multi-level symlink to a ' | 313 'returns $forMultiLevelFileSymlink for a multi-level symlink to a ' 'f
ile', |
348 'file', () { | 314 () { |
349 expect(withTempDir((temp) { | 315 expect(withTempDir((temp) { |
350 var targetPath = path.join(temp, "test.txt"); | 316 var targetPath = path.join(temp, "test.txt"); |
351 var symlink1Path = path.join(temp, "link1.txt"); | 317 var symlink1Path = path.join(temp, "link1.txt"); |
352 var symlink2Path = path.join(temp, "link2.txt"); | 318 var symlink2Path = path.join(temp, "link2.txt"); |
353 writeTextFile(targetPath, "contents"); | 319 writeTextFile(targetPath, "contents"); |
354 createSymlink(targetPath, symlink1Path); | 320 createSymlink(targetPath, symlink1Path); |
355 createSymlink(symlink1Path, symlink2Path); | 321 createSymlink(symlink1Path, symlink2Path); |
356 expect(predicate(symlink2Path), equals(forMultiLevelFileSymlink)); | 322 expect(predicate(symlink2Path), equals(forMultiLevelFileSymlink)); |
357 }), completes); | 323 }), completes); |
358 }); | 324 }); |
359 } | 325 } |
360 }); | 326 }); |
361 } | 327 } |
362 | |
363 /// Like [withTempDir], but canonicalizes the path before passing it to [fn]. | |
364 Future withCanonicalTempDir(Future fn(String path)) => | 328 Future withCanonicalTempDir(Future fn(String path)) => |
365 withTempDir((temp) => fn(canonicalize(temp))); | 329 withTempDir((temp) => fn(canonicalize(temp))); |
OLD | NEW |