OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 import "dart:async"; |
| 6 import "dart:io"; |
| 7 |
| 8 Future throws(callback()) { |
| 9 return new Future.immediate(null) |
| 10 .then((_) => callback()) |
| 11 .then((_) { throw "Expected error"; }, |
| 12 onError: (_) {}); |
| 13 } |
| 14 |
| 15 void testDeleteFileSync() { |
| 16 var tmp = new Directory("").createTempSync(); |
| 17 var path = "${tmp.path}${Platform.pathSeparator}"; |
| 18 |
| 19 var file = new File("${path}myFile"); |
| 20 |
| 21 file.createSync(); |
| 22 |
| 23 Expect.isTrue(file.existsSync()); |
| 24 new File(file.path).deleteSync(); |
| 25 Expect.isFalse(file.existsSync()); |
| 26 |
| 27 file.createSync(); |
| 28 |
| 29 Expect.isTrue(file.existsSync()); |
| 30 Expect.throws(() => new Directory(file.path).deleteSync()); |
| 31 Expect.isTrue(file.existsSync()); |
| 32 |
| 33 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()); |
| 39 Expect.isTrue(file.existsSync()); |
| 40 |
| 41 file.deleteSync(); |
| 42 Expect.isFalse(file.existsSync()); |
| 43 |
| 44 tmp.deleteSync(); |
| 45 } |
| 46 |
| 47 void testDeleteFile() { |
| 48 new Directory("").createTemp().then((tmp) { |
| 49 var path = "${tmp.path}${Platform.pathSeparator}"; |
| 50 var file = new File("${path}myFile"); |
| 51 return file.create() |
| 52 .then((_) => file.exists().then(Expect.isTrue)) |
| 53 .then((_) => new File(file.path).delete()) |
| 54 .then((_) => file.exists().then(Expect.isFalse)) |
| 55 |
| 56 .then((_) => file.create()) |
| 57 |
| 58 .then((_) => file.exists().then(Expect.isTrue)) |
| 59 .then((_) => throws(() => new Directory(file.path).delete())) |
| 60 .then((_) => file.exists().then(Expect.isTrue)) |
| 61 |
| 62 .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())) |
| 69 .then((_) => file.exists().then(Expect.isTrue)) |
| 70 |
| 71 .then((_) => file.delete()) |
| 72 .then((_) => tmp.delete()); |
| 73 }); |
| 74 } |
| 75 |
| 76 void testDeleteDirectorySync() { |
| 77 var tmp = new Directory("").createTempSync(); |
| 78 var path = "${tmp.path}${Platform.pathSeparator}"; |
| 79 |
| 80 var dir = new Directory("${path}myDirectory"); |
| 81 |
| 82 dir.createSync(); |
| 83 |
| 84 Expect.isTrue(dir.existsSync()); |
| 85 new Directory(dir.path).deleteSync(); |
| 86 Expect.isFalse(dir.existsSync()); |
| 87 |
| 88 dir.createSync(); |
| 89 |
| 90 Expect.isTrue(dir.existsSync()); |
| 91 new Directory(dir.path).deleteSync(recursive: true); |
| 92 Expect.isFalse(dir.existsSync()); |
| 93 |
| 94 dir.createSync(); |
| 95 |
| 96 Expect.isTrue(dir.existsSync()); |
| 97 Expect.throws(() => new File(dir.path).deleteSync()); |
| 98 Expect.isTrue(dir.existsSync()); |
| 99 |
| 100 Expect.isTrue(dir.existsSync()); |
| 101 Expect.throws(() => new Link(dir.path).deleteSync()); |
| 102 Expect.isTrue(dir.existsSync()); |
| 103 |
| 104 dir.deleteSync(); |
| 105 Expect.isFalse(dir.existsSync()); |
| 106 |
| 107 tmp.deleteSync(); |
| 108 } |
| 109 |
| 110 void testDeleteDirectory() { |
| 111 new Directory("").createTemp().then((tmp) { |
| 112 var path = "${tmp.path}${Platform.pathSeparator}"; |
| 113 var dir = new Directory("${path}myDirectory"); |
| 114 return dir.create() |
| 115 .then((_) => dir.exists().then(Expect.isTrue)) |
| 116 .then((_) => new Directory(dir.path).delete()) |
| 117 .then((_) => dir.exists().then(Expect.isFalse)) |
| 118 |
| 119 .then((_) => dir.create()) |
| 120 |
| 121 .then((_) => dir.exists().then(Expect.isTrue)) |
| 122 .then((_) => new Directory(dir.path).delete(recursive: true)) |
| 123 .then((_) => dir.exists().then(Expect.isFalse)) |
| 124 |
| 125 .then((_) => dir.create()) |
| 126 |
| 127 .then((_) => dir.exists().then(Expect.isTrue)) |
| 128 .then((_) => throws(() => new File(dir.path).delete())) |
| 129 .then((_) => dir.exists().then(Expect.isTrue)) |
| 130 |
| 131 .then((_) => dir.exists().then(Expect.isTrue)) |
| 132 .then((_) => throws(() => new Link(dir.path).delete())) |
| 133 .then((_) => dir.exists().then(Expect.isTrue)) |
| 134 |
| 135 .then((_) => dir.delete()) |
| 136 .then((_) => tmp.delete()); |
| 137 }); |
| 138 } |
| 139 |
| 140 void testDeleteFileLinkSync() { |
| 141 var tmp = new Directory("").createTempSync(); |
| 142 var path = "${tmp.path}${Platform.pathSeparator}"; |
| 143 |
| 144 var file = new File("${path}myFile"); |
| 145 file.createSync(); |
| 146 |
| 147 var link = new Link("${path}myLink"); |
| 148 |
| 149 link.createSync(file.path); |
| 150 |
| 151 Expect.isTrue(link.existsSync()); |
| 152 new File(link.path).deleteSync(); |
| 153 Expect.isFalse(link.existsSync()); |
| 154 |
| 155 link.createSync(file.path); |
| 156 |
| 157 Expect.isTrue(link.existsSync()); |
| 158 new Link(link.path).deleteSync(); |
| 159 Expect.isFalse(link.existsSync()); |
| 160 |
| 161 link.createSync(file.path); |
| 162 |
| 163 Expect.isTrue(link.existsSync()); |
| 164 Expect.throws(() => new Directory(link.path).deleteSync()); |
| 165 Expect.isTrue(link.existsSync()); |
| 166 |
| 167 Expect.isTrue(link.existsSync()); |
| 168 Expect.throws(() => new Directory(link.path).deleteSync(recursive: true)); |
| 169 Expect.isTrue(link.existsSync()); |
| 170 |
| 171 link.deleteSync(); |
| 172 Expect.isFalse(link.existsSync()); |
| 173 |
| 174 Expect.isTrue(file.existsSync()); |
| 175 file.deleteSync(); |
| 176 Expect.isFalse(file.existsSync()); |
| 177 |
| 178 tmp.deleteSync(); |
| 179 } |
| 180 |
| 181 void testDeleteFileLink() { |
| 182 new Directory("").createTemp().then((tmp) { |
| 183 var path = "${tmp.path}${Platform.pathSeparator}"; |
| 184 var file = new File("${path}myFile"); |
| 185 var link = new Link("${path}myLink"); |
| 186 return file.create() |
| 187 .then((_) => link.create(file.path)) |
| 188 |
| 189 .then((_) => link.exists().then(Expect.isTrue)) |
| 190 .then((_) => new File(link.path).delete()) |
| 191 .then((_) => link.exists().then(Expect.isFalse)) |
| 192 |
| 193 .then((_) => link.create(file.path)) |
| 194 |
| 195 .then((_) => link.exists().then(Expect.isTrue)) |
| 196 .then((_) => new Link(link.path).delete()) |
| 197 .then((_) => link.exists().then(Expect.isFalse)) |
| 198 |
| 199 .then((_) => link.create(file.path)) |
| 200 |
| 201 .then((_) => link.exists().then(Expect.isTrue)) |
| 202 .then((_) => throws(() => new Directory(link.path).delete())) |
| 203 .then((_) => link.exists().then(Expect.isTrue)) |
| 204 |
| 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()) |
| 211 .then((_) => link.exists().then(Expect.isFalse)) |
| 212 |
| 213 .then((_) => file.exists().then(Expect.isTrue)) |
| 214 .then((_) => file.delete()) |
| 215 .then((_) => file.exists().then(Expect.isFalse)) |
| 216 |
| 217 .then((_) => tmp.delete()); |
| 218 }); |
| 219 } |
| 220 |
| 221 void testDeleteDirectoryLinkSync() { |
| 222 var tmp = new Directory("").createTempSync(); |
| 223 var path = "${tmp.path}${Platform.pathSeparator}"; |
| 224 |
| 225 var directory = new Directory("${path}myDirectory"); |
| 226 directory.createSync(); |
| 227 |
| 228 var link = new Link("${path}myLink"); |
| 229 |
| 230 link.createSync(directory.path); |
| 231 |
| 232 Expect.isTrue(link.existsSync()); |
| 233 new Link(link.path).deleteSync(); |
| 234 Expect.isFalse(link.existsSync()); |
| 235 |
| 236 link.createSync(directory.path); |
| 237 |
| 238 Expect.isTrue(link.existsSync()); |
| 239 new Directory(link.path).deleteSync(); |
| 240 Expect.isFalse(link.existsSync()); |
| 241 |
| 242 link.createSync(directory.path); |
| 243 |
| 244 Expect.isTrue(link.existsSync()); |
| 245 new Directory(link.path).deleteSync(recursive: true); |
| 246 Expect.isFalse(link.existsSync()); |
| 247 |
| 248 link.createSync(directory.path); |
| 249 |
| 250 Expect.isTrue(link.existsSync()); |
| 251 Expect.throws(() => new File(link.path).deleteSync()); |
| 252 Expect.isTrue(link.existsSync()); |
| 253 |
| 254 link.deleteSync(); |
| 255 Expect.isFalse(link.existsSync()); |
| 256 |
| 257 Expect.isTrue(directory.existsSync()); |
| 258 directory.deleteSync(); |
| 259 Expect.isFalse(directory.existsSync()); |
| 260 |
| 261 tmp.deleteSync(); |
| 262 } |
| 263 |
| 264 void testDeleteDirectoryLink() { |
| 265 new Directory("").createTemp().then((tmp) { |
| 266 var path = "${tmp.path}${Platform.pathSeparator}"; |
| 267 var dir = new Directory("${path}myDir"); |
| 268 var link = new Link("${path}myLink"); |
| 269 return dir.create() |
| 270 .then((_) => link.create(dir.path)) |
| 271 |
| 272 .then((_) => link.exists().then(Expect.isTrue)) |
| 273 .then((_) => new Directory(link.path).delete()) |
| 274 .then((_) => link.exists().then(Expect.isFalse)) |
| 275 |
| 276 .then((_) => link.create(dir.path)) |
| 277 |
| 278 .then((_) => link.exists().then(Expect.isTrue)) |
| 279 .then((_) => new Directory(link.path).delete(recursive: true)) |
| 280 .then((_) => link.exists().then(Expect.isFalse)) |
| 281 |
| 282 .then((_) => link.create(dir.path)) |
| 283 |
| 284 .then((_) => link.exists().then(Expect.isTrue)) |
| 285 .then((_) => new Link(link.path).delete()) |
| 286 .then((_) => link.exists().then(Expect.isFalse)) |
| 287 |
| 288 .then((_) => link.create(dir.path)) |
| 289 |
| 290 .then((_) => link.exists().then(Expect.isTrue)) |
| 291 .then((_) => throws(() => new File(link.path).delete())) |
| 292 .then((_) => link.exists().then(Expect.isTrue)) |
| 293 |
| 294 .then((_) => link.deleteSync()) |
| 295 .then((_) => link.exists().then(Expect.isFalse)) |
| 296 |
| 297 .then((_) => dir.exists().then(Expect.isTrue)) |
| 298 .then((_) => dir.delete()) |
| 299 .then((_) => dir.exists().then(Expect.isFalse)) |
| 300 |
| 301 .then((_) => tmp.delete()); |
| 302 }); |
| 303 } |
| 304 |
| 305 void testDeleteBrokenLinkSync() { |
| 306 var tmp = new Directory("").createTempSync(); |
| 307 var path = "${tmp.path}${Platform.pathSeparator}"; |
| 308 |
| 309 var directory = new Directory("${path}myDirectory"); |
| 310 directory.createSync(); |
| 311 |
| 312 var link = new Link("${path}myLink"); |
| 313 |
| 314 link.createSync(directory.path); |
| 315 directory.deleteSync(); |
| 316 |
| 317 Expect.isTrue(link.existsSync()); |
| 318 new Link(link.path).deleteSync(); |
| 319 Expect.isFalse(link.existsSync()); |
| 320 |
| 321 directory.createSync(); |
| 322 link.createSync(directory.path); |
| 323 directory.deleteSync(); |
| 324 |
| 325 Expect.isTrue(link.existsSync()); |
| 326 Expect.throws(() => new Directory(link.path).deleteSync()); |
| 327 Expect.isTrue(link.existsSync()); |
| 328 |
| 329 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()); |
| 335 Expect.isTrue(link.existsSync()); |
| 336 |
| 337 link.deleteSync(); |
| 338 Expect.isFalse(link.existsSync()); |
| 339 |
| 340 tmp.deleteSync(); |
| 341 } |
| 342 |
| 343 void testDeleteBrokenLink() { |
| 344 new Directory("").createTemp().then((tmp) { |
| 345 var path = "${tmp.path}${Platform.pathSeparator}"; |
| 346 var dir = new Directory("${path}myDir"); |
| 347 var link = new Link("${path}myLink"); |
| 348 return dir.create() |
| 349 .then((_) => link.create(dir.path)) |
| 350 .then((_) => dir.delete()) |
| 351 |
| 352 .then((_) => link.exists().then(Expect.isTrue)) |
| 353 .then((_) => new Link(link.path).delete()) |
| 354 .then((_) => link.exists().then(Expect.isFalse)) |
| 355 |
| 356 .then((_) => dir.create()) |
| 357 .then((_) => link.create(dir.path)) |
| 358 .then((_) => dir.delete()) |
| 359 |
| 360 .then((_) => link.exists().then(Expect.isTrue)) |
| 361 .then((_) => throws(() => new Directory(link.path).delete())) |
| 362 .then((_) => link.exists().then(Expect.isTrue)) |
| 363 |
| 364 .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())) |
| 371 .then((_) => link.exists().then(Expect.isTrue)) |
| 372 |
| 373 .then((_) => link.deleteSync()) |
| 374 .then((_) => link.exists().then(Expect.isFalse)) |
| 375 |
| 376 .then((_) => tmp.delete()); |
| 377 }); |
| 378 } |
| 379 |
| 380 void main() { |
| 381 testDeleteFileSync(); |
| 382 testDeleteFile(); |
| 383 testDeleteDirectorySync(); |
| 384 testDeleteDirectory(); |
| 385 if (Platform.operatingSystem != 'windows') { |
| 386 testDeleteFileLinkSync(); |
| 387 testDeleteFileLink(); |
| 388 } |
| 389 testDeleteDirectoryLinkSync(); |
| 390 testDeleteDirectoryLink(); |
| 391 testDeleteBrokenLinkSync(); |
| 392 testDeleteBrokenLink(); |
| 393 } |
OLD | NEW |