OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 import "dart:async"; | 5 import "dart:async"; |
6 import "dart:io"; | 6 import "dart:io"; |
7 | 7 |
8 Future throws(callback()) { | 8 Future throws(callback()) { |
9 return new Future.immediate(null) | 9 return new Future.immediate(null) |
10 .then((_) => callback()) | 10 .then((_) => callback()) |
11 .then((_) { throw "Expected error"; }, | 11 .then((_) { throw "Expected error"; }, |
12 onError: (_) {}); | 12 onError: (_) {}); |
13 } | 13 } |
14 | 14 |
15 void testDeleteFileSync() { | 15 void testDeleteFileSync() { |
16 var tmp = new Directory("").createTempSync(); | 16 var tmp = new Directory("").createTempSync(); |
17 var path = "${tmp.path}${Platform.pathSeparator}"; | 17 var path = "${tmp.path}${Platform.pathSeparator}"; |
18 | 18 |
19 var file = new File("${path}myFile"); | 19 var file = new File("${path}myFile"); |
20 | 20 |
21 file.createSync(); | 21 file.createSync(); |
22 | 22 |
23 Expect.isTrue(file.existsSync()); | 23 Expect.isTrue(file.existsSync()); |
24 new File(file.path).deleteSync(); | 24 new File(file.path).deleteSync(); |
25 Expect.isFalse(file.existsSync()); | 25 Expect.isFalse(file.existsSync()); |
26 | 26 |
27 file.createSync(); | 27 file.createSync(); |
28 | 28 |
29 Expect.isTrue(file.existsSync()); | 29 Expect.isTrue(file.existsSync()); |
| 30 new Directory(file.path).deleteSync(recursive: true); |
| 31 Expect.isFalse(file.existsSync()); |
| 32 |
| 33 file.createSync(); |
| 34 |
| 35 Expect.isTrue(file.existsSync()); |
30 Expect.throws(() => new Directory(file.path).deleteSync()); | 36 Expect.throws(() => new Directory(file.path).deleteSync()); |
31 Expect.isTrue(file.existsSync()); | 37 Expect.isTrue(file.existsSync()); |
32 | 38 |
33 Expect.isTrue(file.existsSync()); | 39 Expect.isTrue(file.existsSync()); |
34 Expect.throws(() => new Directory(file.path).deleteSync(recursive: true)); | |
35 Expect.isTrue(file.existsSync()); | |
36 | |
37 Expect.isTrue(file.existsSync()); | |
38 Expect.throws(() => new Link(file.path).deleteSync()); | 40 Expect.throws(() => new Link(file.path).deleteSync()); |
39 Expect.isTrue(file.existsSync()); | 41 Expect.isTrue(file.existsSync()); |
40 | 42 |
41 file.deleteSync(); | 43 file.deleteSync(); |
42 Expect.isFalse(file.existsSync()); | 44 Expect.isFalse(file.existsSync()); |
43 | 45 |
44 tmp.deleteSync(); | 46 tmp.deleteSync(); |
45 } | 47 } |
46 | 48 |
47 void testDeleteFile() { | 49 void testDeleteFile() { |
48 new Directory("").createTemp().then((tmp) { | 50 new Directory("").createTemp().then((tmp) { |
49 var path = "${tmp.path}${Platform.pathSeparator}"; | 51 var path = "${tmp.path}${Platform.pathSeparator}"; |
50 var file = new File("${path}myFile"); | 52 var file = new File("${path}myFile"); |
51 return file.create() | 53 return file.create() |
52 .then((_) => file.exists().then(Expect.isTrue)) | 54 .then((_) => file.exists().then(Expect.isTrue)) |
53 .then((_) => new File(file.path).delete()) | 55 .then((_) => new File(file.path).delete()) |
54 .then((_) => file.exists().then(Expect.isFalse)) | 56 .then((_) => file.exists().then(Expect.isFalse)) |
55 | 57 |
56 .then((_) => file.create()) | 58 .then((_) => file.create()) |
57 | 59 |
58 .then((_) => file.exists().then(Expect.isTrue)) | 60 .then((_) => file.exists().then(Expect.isTrue)) |
| 61 .then((_) => new Directory(file.path).delete(recursive: true)) |
| 62 .then((_) => file.exists().then(Expect.isFalse)) |
| 63 |
| 64 .then((_) => file.create()) |
| 65 |
| 66 .then((_) => file.exists().then(Expect.isTrue)) |
59 .then((_) => throws(() => new Directory(file.path).delete())) | 67 .then((_) => throws(() => new Directory(file.path).delete())) |
60 .then((_) => file.exists().then(Expect.isTrue)) | 68 .then((_) => file.exists().then(Expect.isTrue)) |
61 | 69 |
62 .then((_) => file.exists().then(Expect.isTrue)) | 70 .then((_) => file.exists().then(Expect.isTrue)) |
63 .then((_) => throws( | |
64 () => new Directory(file.path).delete(recursive: true))) | |
65 .then((_) => file.exists().then(Expect.isTrue)) | |
66 | |
67 .then((_) => file.exists().then(Expect.isTrue)) | |
68 .then((_) => throws(() => new Link(file.path).delete())) | 71 .then((_) => throws(() => new Link(file.path).delete())) |
69 .then((_) => file.exists().then(Expect.isTrue)) | 72 .then((_) => file.exists().then(Expect.isTrue)) |
70 | 73 |
71 .then((_) => file.delete()) | 74 .then((_) => file.delete()) |
72 .then((_) => tmp.delete()); | 75 .then((_) => tmp.delete()); |
73 }); | 76 }); |
74 } | 77 } |
75 | 78 |
76 void testDeleteDirectorySync() { | 79 void testDeleteDirectorySync() { |
77 var tmp = new Directory("").createTempSync(); | 80 var tmp = new Directory("").createTempSync(); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 | 157 |
155 link.createSync(file.path); | 158 link.createSync(file.path); |
156 | 159 |
157 Expect.isTrue(link.existsSync()); | 160 Expect.isTrue(link.existsSync()); |
158 new Link(link.path).deleteSync(); | 161 new Link(link.path).deleteSync(); |
159 Expect.isFalse(link.existsSync()); | 162 Expect.isFalse(link.existsSync()); |
160 | 163 |
161 link.createSync(file.path); | 164 link.createSync(file.path); |
162 | 165 |
163 Expect.isTrue(link.existsSync()); | 166 Expect.isTrue(link.existsSync()); |
| 167 new Directory(link.path).deleteSync(recursive: true); |
| 168 Expect.isFalse(link.existsSync()); |
| 169 |
| 170 link.createSync(file.path); |
| 171 |
| 172 Expect.isTrue(link.existsSync()); |
164 Expect.throws(() => new Directory(link.path).deleteSync()); | 173 Expect.throws(() => new Directory(link.path).deleteSync()); |
165 Expect.isTrue(link.existsSync()); | 174 Expect.isTrue(link.existsSync()); |
166 | 175 |
167 Expect.isTrue(link.existsSync()); | |
168 Expect.throws(() => new Directory(link.path).deleteSync(recursive: true)); | |
169 Expect.isTrue(link.existsSync()); | |
170 | |
171 link.deleteSync(); | 176 link.deleteSync(); |
172 Expect.isFalse(link.existsSync()); | 177 Expect.isFalse(link.existsSync()); |
173 | 178 |
174 Expect.isTrue(file.existsSync()); | 179 Expect.isTrue(file.existsSync()); |
175 file.deleteSync(); | 180 file.deleteSync(); |
176 Expect.isFalse(file.existsSync()); | 181 Expect.isFalse(file.existsSync()); |
177 | 182 |
178 tmp.deleteSync(); | 183 tmp.deleteSync(); |
179 } | 184 } |
180 | 185 |
(...skipping 11 matching lines...) Expand all Loading... |
192 | 197 |
193 .then((_) => link.create(file.path)) | 198 .then((_) => link.create(file.path)) |
194 | 199 |
195 .then((_) => link.exists().then(Expect.isTrue)) | 200 .then((_) => link.exists().then(Expect.isTrue)) |
196 .then((_) => new Link(link.path).delete()) | 201 .then((_) => new Link(link.path).delete()) |
197 .then((_) => link.exists().then(Expect.isFalse)) | 202 .then((_) => link.exists().then(Expect.isFalse)) |
198 | 203 |
199 .then((_) => link.create(file.path)) | 204 .then((_) => link.create(file.path)) |
200 | 205 |
201 .then((_) => link.exists().then(Expect.isTrue)) | 206 .then((_) => link.exists().then(Expect.isTrue)) |
| 207 .then((_) => new Directory(link.path).delete(recursive: true)) |
| 208 .then((_) => link.exists().then(Expect.isFalse)) |
| 209 |
| 210 .then((_) => link.create(file.path)) |
| 211 |
| 212 .then((_) => link.exists().then(Expect.isTrue)) |
202 .then((_) => throws(() => new Directory(link.path).delete())) | 213 .then((_) => throws(() => new Directory(link.path).delete())) |
203 .then((_) => link.exists().then(Expect.isTrue)) | 214 .then((_) => link.exists().then(Expect.isTrue)) |
204 | 215 |
205 .then((_) => link.exists().then(Expect.isTrue)) | |
206 .then((_) => throws( | |
207 () => new Directory(link.path).delete(recursive: true))) | |
208 .then((_) => link.exists().then(Expect.isTrue)) | |
209 | |
210 .then((_) => link.deleteSync()) | 216 .then((_) => link.deleteSync()) |
211 .then((_) => link.exists().then(Expect.isFalse)) | 217 .then((_) => link.exists().then(Expect.isFalse)) |
212 | 218 |
213 .then((_) => file.exists().then(Expect.isTrue)) | 219 .then((_) => file.exists().then(Expect.isTrue)) |
214 .then((_) => file.delete()) | 220 .then((_) => file.delete()) |
215 .then((_) => file.exists().then(Expect.isFalse)) | 221 .then((_) => file.exists().then(Expect.isFalse)) |
216 | 222 |
217 .then((_) => tmp.delete()); | 223 .then((_) => tmp.delete()); |
218 }); | 224 }); |
219 } | 225 } |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 | 322 |
317 Expect.isTrue(link.existsSync()); | 323 Expect.isTrue(link.existsSync()); |
318 new Link(link.path).deleteSync(); | 324 new Link(link.path).deleteSync(); |
319 Expect.isFalse(link.existsSync()); | 325 Expect.isFalse(link.existsSync()); |
320 | 326 |
321 directory.createSync(); | 327 directory.createSync(); |
322 link.createSync(directory.path); | 328 link.createSync(directory.path); |
323 directory.deleteSync(); | 329 directory.deleteSync(); |
324 | 330 |
325 Expect.isTrue(link.existsSync()); | 331 Expect.isTrue(link.existsSync()); |
| 332 new Directory(link.path).deleteSync(recursive: true); |
| 333 Expect.isFalse(link.existsSync()); |
| 334 |
| 335 directory.createSync(); |
| 336 link.createSync(directory.path); |
| 337 directory.deleteSync(); |
| 338 |
| 339 Expect.isTrue(link.existsSync()); |
326 Expect.throws(() => new Directory(link.path).deleteSync()); | 340 Expect.throws(() => new Directory(link.path).deleteSync()); |
327 Expect.isTrue(link.existsSync()); | 341 Expect.isTrue(link.existsSync()); |
328 | 342 |
329 Expect.isTrue(link.existsSync()); | 343 Expect.isTrue(link.existsSync()); |
330 Expect.throws(() => new Directory(link.path).deleteSync(recursive: true)); | |
331 Expect.isTrue(link.existsSync()); | |
332 | |
333 Expect.isTrue(link.existsSync()); | |
334 Expect.throws(() => new File(link.path).deleteSync()); | 344 Expect.throws(() => new File(link.path).deleteSync()); |
335 Expect.isTrue(link.existsSync()); | 345 Expect.isTrue(link.existsSync()); |
336 | 346 |
337 link.deleteSync(); | 347 link.deleteSync(); |
338 Expect.isFalse(link.existsSync()); | 348 Expect.isFalse(link.existsSync()); |
339 | 349 |
340 tmp.deleteSync(); | 350 tmp.deleteSync(); |
341 } | 351 } |
342 | 352 |
343 void testDeleteBrokenLink() { | 353 void testDeleteBrokenLink() { |
344 new Directory("").createTemp().then((tmp) { | 354 new Directory("").createTemp().then((tmp) { |
345 var path = "${tmp.path}${Platform.pathSeparator}"; | 355 var path = "${tmp.path}${Platform.pathSeparator}"; |
346 var dir = new Directory("${path}myDir"); | 356 var dir = new Directory("${path}myDir"); |
347 var link = new Link("${path}myLink"); | 357 var link = new Link("${path}myLink"); |
348 return dir.create() | 358 return dir.create() |
349 .then((_) => link.create(dir.path)) | 359 .then((_) => link.create(dir.path)) |
350 .then((_) => dir.delete()) | 360 .then((_) => dir.delete()) |
351 | 361 |
352 .then((_) => link.exists().then(Expect.isTrue)) | 362 .then((_) => link.exists().then(Expect.isTrue)) |
353 .then((_) => new Link(link.path).delete()) | 363 .then((_) => new Link(link.path).delete()) |
354 .then((_) => link.exists().then(Expect.isFalse)) | 364 .then((_) => link.exists().then(Expect.isFalse)) |
355 | 365 |
356 .then((_) => dir.create()) | 366 .then((_) => dir.create()) |
357 .then((_) => link.create(dir.path)) | 367 .then((_) => link.create(dir.path)) |
358 .then((_) => dir.delete()) | 368 .then((_) => dir.delete()) |
359 | 369 |
360 .then((_) => link.exists().then(Expect.isTrue)) | 370 .then((_) => link.exists().then(Expect.isTrue)) |
| 371 .then((_) => new Directory(link.path).delete(recursive: true)) |
| 372 .then((_) => link.exists().then(Expect.isFalse)) |
| 373 |
| 374 .then((_) => dir.create()) |
| 375 .then((_) => link.create(dir.path)) |
| 376 .then((_) => dir.delete()) |
| 377 |
| 378 .then((_) => link.exists().then(Expect.isTrue)) |
361 .then((_) => throws(() => new Directory(link.path).delete())) | 379 .then((_) => throws(() => new Directory(link.path).delete())) |
362 .then((_) => link.exists().then(Expect.isTrue)) | 380 .then((_) => link.exists().then(Expect.isTrue)) |
363 | 381 |
364 .then((_) => link.exists().then(Expect.isTrue)) | 382 .then((_) => link.exists().then(Expect.isTrue)) |
365 .then((_) => throws( | |
366 () => new Directory(link.path).delete(recursive: true))) | |
367 .then((_) => link.exists().then(Expect.isTrue)) | |
368 | |
369 .then((_) => link.exists().then(Expect.isTrue)) | |
370 .then((_) => throws(() => new File(link.path).delete())) | 383 .then((_) => throws(() => new File(link.path).delete())) |
371 .then((_) => link.exists().then(Expect.isTrue)) | 384 .then((_) => link.exists().then(Expect.isTrue)) |
372 | 385 |
373 .then((_) => link.deleteSync()) | 386 .then((_) => link.deleteSync()) |
374 .then((_) => link.exists().then(Expect.isFalse)) | 387 .then((_) => link.exists().then(Expect.isFalse)) |
375 | 388 |
376 .then((_) => tmp.delete()); | 389 .then((_) => tmp.delete()); |
377 }); | 390 }); |
378 } | 391 } |
379 | 392 |
380 void main() { | 393 void main() { |
381 testDeleteFileSync(); | 394 testDeleteFileSync(); |
382 testDeleteFile(); | 395 testDeleteFile(); |
383 testDeleteDirectorySync(); | 396 testDeleteDirectorySync(); |
384 testDeleteDirectory(); | 397 testDeleteDirectory(); |
385 if (Platform.operatingSystem != 'windows') { | 398 if (Platform.operatingSystem != 'windows') { |
386 testDeleteFileLinkSync(); | 399 testDeleteFileLinkSync(); |
387 testDeleteFileLink(); | 400 testDeleteFileLink(); |
388 } | 401 } |
389 testDeleteDirectoryLinkSync(); | 402 testDeleteDirectoryLinkSync(); |
390 testDeleteDirectoryLink(); | 403 testDeleteDirectoryLink(); |
391 testDeleteBrokenLinkSync(); | 404 testDeleteBrokenLinkSync(); |
392 testDeleteBrokenLink(); | 405 testDeleteBrokenLink(); |
393 } | 406 } |
OLD | NEW |