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