| 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 "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
| 6 import "dart:async"; | 6 import "dart:async"; |
| 7 import "dart:io"; | 7 import "dart:io"; |
| 8 | 8 |
| 9 Future throws(callback()) { | 9 Future throws(callback()) { |
| 10 return new Future.value() | 10 return new Future.value() |
| 11 .then((_) => callback()) | 11 .then((_) => callback()) |
| 12 .then((_) { throw "Expected error"; }, | 12 .then((_) { throw "Expected error"; }, |
| 13 onError: (_) {}); | 13 onError: (_) {}); |
| 14 } | 14 } |
| 15 | 15 |
| 16 void testDeleteFileSync() { | 16 void testDeleteFileSync() { |
| 17 var tmp = new Directory("").createTempSync(); | 17 var tmp = Directory.systemTemp.createTempSync('dart_file_system_delete'); |
| 18 var path = "${tmp.path}${Platform.pathSeparator}"; | 18 var path = "${tmp.path}${Platform.pathSeparator}"; |
| 19 | 19 |
| 20 var file = new File("${path}myFile"); | 20 var file = new File("${path}myFile"); |
| 21 | 21 |
| 22 file.createSync(); | 22 file.createSync(); |
| 23 | 23 |
| 24 Expect.isTrue(file.existsSync()); | 24 Expect.isTrue(file.existsSync()); |
| 25 new File(file.path).deleteSync(); | 25 new File(file.path).deleteSync(); |
| 26 Expect.isFalse(file.existsSync()); | 26 Expect.isFalse(file.existsSync()); |
| 27 | 27 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 41 Expect.throws(() => new Link(file.path).deleteSync()); | 41 Expect.throws(() => new Link(file.path).deleteSync()); |
| 42 Expect.isTrue(file.existsSync()); | 42 Expect.isTrue(file.existsSync()); |
| 43 | 43 |
| 44 file.deleteSync(); | 44 file.deleteSync(); |
| 45 Expect.isFalse(file.existsSync()); | 45 Expect.isFalse(file.existsSync()); |
| 46 | 46 |
| 47 tmp.deleteSync(); | 47 tmp.deleteSync(); |
| 48 } | 48 } |
| 49 | 49 |
| 50 void testDeleteFile() { | 50 void testDeleteFile() { |
| 51 new Directory("").createTemp().then((tmp) { | 51 Directory.systemTemp.createTemp('dart_file_system_delete').then((tmp) { |
| 52 var path = "${tmp.path}${Platform.pathSeparator}"; | 52 var path = "${tmp.path}${Platform.pathSeparator}"; |
| 53 var file = new File("${path}myFile"); | 53 var file = new File("${path}myFile"); |
| 54 return file.create() | 54 return file.create() |
| 55 .then((_) => file.exists().then(Expect.isTrue)) | 55 .then((_) => file.exists().then(Expect.isTrue)) |
| 56 .then((_) => new File(file.path).delete()) | 56 .then((_) => new File(file.path).delete()) |
| 57 .then((_) => file.exists().then(Expect.isFalse)) | 57 .then((_) => file.exists().then(Expect.isFalse)) |
| 58 | 58 |
| 59 .then((_) => file.create()) | 59 .then((_) => file.create()) |
| 60 | 60 |
| 61 .then((_) => file.exists().then(Expect.isTrue)) | 61 .then((_) => file.exists().then(Expect.isTrue)) |
| 62 .then((_) => new Directory(file.path).delete(recursive: true)) | 62 .then((_) => new Directory(file.path).delete(recursive: true)) |
| 63 .then((_) => file.exists().then(Expect.isFalse)) | 63 .then((_) => file.exists().then(Expect.isFalse)) |
| 64 | 64 |
| 65 .then((_) => file.create()) | 65 .then((_) => file.create()) |
| 66 | 66 |
| 67 .then((_) => file.exists().then(Expect.isTrue)) | 67 .then((_) => file.exists().then(Expect.isTrue)) |
| 68 .then((_) => throws(() => new Directory(file.path).delete())) | 68 .then((_) => throws(() => new Directory(file.path).delete())) |
| 69 .then((_) => file.exists().then(Expect.isTrue)) | 69 .then((_) => file.exists().then(Expect.isTrue)) |
| 70 | 70 |
| 71 .then((_) => file.exists().then(Expect.isTrue)) | 71 .then((_) => file.exists().then(Expect.isTrue)) |
| 72 .then((_) => throws(() => new Link(file.path).delete())) | 72 .then((_) => throws(() => new Link(file.path).delete())) |
| 73 .then((_) => file.exists().then(Expect.isTrue)) | 73 .then((_) => file.exists().then(Expect.isTrue)) |
| 74 | 74 |
| 75 .then((_) => file.delete()) | 75 .then((_) => file.delete()) |
| 76 .then((_) => tmp.delete()); | 76 .then((_) => tmp.delete()); |
| 77 }); | 77 }); |
| 78 } | 78 } |
| 79 | 79 |
| 80 void testDeleteDirectorySync() { | 80 void testDeleteDirectorySync() { |
| 81 var tmp = new Directory("").createTempSync(); | 81 var tmp = Directory.systemTemp.createTempSync('dart_file_system_delete'); |
| 82 var path = "${tmp.path}${Platform.pathSeparator}"; | 82 var path = "${tmp.path}${Platform.pathSeparator}"; |
| 83 | 83 |
| 84 var dir = new Directory("${path}myDirectory"); | 84 var dir = new Directory("${path}myDirectory"); |
| 85 | 85 |
| 86 dir.createSync(); | 86 dir.createSync(); |
| 87 | 87 |
| 88 Expect.isTrue(dir.existsSync()); | 88 Expect.isTrue(dir.existsSync()); |
| 89 new Directory(dir.path).deleteSync(); | 89 new Directory(dir.path).deleteSync(); |
| 90 Expect.isFalse(dir.existsSync()); | 90 Expect.isFalse(dir.existsSync()); |
| 91 | 91 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 105 Expect.throws(() => new Link(dir.path).deleteSync()); | 105 Expect.throws(() => new Link(dir.path).deleteSync()); |
| 106 Expect.isTrue(dir.existsSync()); | 106 Expect.isTrue(dir.existsSync()); |
| 107 | 107 |
| 108 dir.deleteSync(); | 108 dir.deleteSync(); |
| 109 Expect.isFalse(dir.existsSync()); | 109 Expect.isFalse(dir.existsSync()); |
| 110 | 110 |
| 111 tmp.deleteSync(); | 111 tmp.deleteSync(); |
| 112 } | 112 } |
| 113 | 113 |
| 114 void testDeleteDirectory() { | 114 void testDeleteDirectory() { |
| 115 new Directory("").createTemp().then((tmp) { | 115 Directory.systemTemp.createTemp('dart_file_system_delete').then((tmp) { |
| 116 var path = "${tmp.path}${Platform.pathSeparator}"; | 116 var path = "${tmp.path}${Platform.pathSeparator}"; |
| 117 var dir = new Directory("${path}myDirectory"); | 117 var dir = new Directory("${path}myDirectory"); |
| 118 return dir.create() | 118 return dir.create() |
| 119 .then((_) => dir.exists().then(Expect.isTrue)) | 119 .then((_) => dir.exists().then(Expect.isTrue)) |
| 120 .then((_) => new Directory(dir.path).delete()) | 120 .then((_) => new Directory(dir.path).delete()) |
| 121 .then((_) => dir.exists().then(Expect.isFalse)) | 121 .then((_) => dir.exists().then(Expect.isFalse)) |
| 122 | 122 |
| 123 .then((_) => dir.create()) | 123 .then((_) => dir.create()) |
| 124 | 124 |
| 125 .then((_) => dir.exists().then(Expect.isTrue)) | 125 .then((_) => dir.exists().then(Expect.isTrue)) |
| 126 .then((_) => new Directory(dir.path).delete(recursive: true)) | 126 .then((_) => new Directory(dir.path).delete(recursive: true)) |
| 127 .then((_) => dir.exists().then(Expect.isFalse)) | 127 .then((_) => dir.exists().then(Expect.isFalse)) |
| 128 | 128 |
| 129 .then((_) => dir.create()) | 129 .then((_) => dir.create()) |
| 130 | 130 |
| 131 .then((_) => dir.exists().then(Expect.isTrue)) | 131 .then((_) => dir.exists().then(Expect.isTrue)) |
| 132 .then((_) => throws(() => new File(dir.path).delete())) | 132 .then((_) => throws(() => new File(dir.path).delete())) |
| 133 .then((_) => dir.exists().then(Expect.isTrue)) | 133 .then((_) => dir.exists().then(Expect.isTrue)) |
| 134 | 134 |
| 135 .then((_) => dir.exists().then(Expect.isTrue)) | 135 .then((_) => dir.exists().then(Expect.isTrue)) |
| 136 .then((_) => throws(() => new Link(dir.path).delete())) | 136 .then((_) => throws(() => new Link(dir.path).delete())) |
| 137 .then((_) => dir.exists().then(Expect.isTrue)) | 137 .then((_) => dir.exists().then(Expect.isTrue)) |
| 138 | 138 |
| 139 .then((_) => dir.delete()) | 139 .then((_) => dir.delete()) |
| 140 .then((_) => tmp.delete()); | 140 .then((_) => tmp.delete()); |
| 141 }); | 141 }); |
| 142 } | 142 } |
| 143 | 143 |
| 144 void testDeleteFileLinkSync() { | 144 void testDeleteFileLinkSync() { |
| 145 var tmp = new Directory("").createTempSync(); | 145 var tmp = Directory.systemTemp.createTempSync('dart_file_system_delete'); |
| 146 var path = "${tmp.path}${Platform.pathSeparator}"; | 146 var path = "${tmp.path}${Platform.pathSeparator}"; |
| 147 | 147 |
| 148 var file = new File("${path}myFile"); | 148 var file = new File("${path}myFile"); |
| 149 file.createSync(); | 149 file.createSync(); |
| 150 | 150 |
| 151 var link = new Link("${path}myLink"); | 151 var link = new Link("${path}myLink"); |
| 152 | 152 |
| 153 link.createSync(file.path); | 153 link.createSync(file.path); |
| 154 | 154 |
| 155 Expect.isTrue(link.existsSync()); | 155 Expect.isTrue(link.existsSync()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 178 Expect.isFalse(link.existsSync()); | 178 Expect.isFalse(link.existsSync()); |
| 179 | 179 |
| 180 Expect.isTrue(file.existsSync()); | 180 Expect.isTrue(file.existsSync()); |
| 181 file.deleteSync(); | 181 file.deleteSync(); |
| 182 Expect.isFalse(file.existsSync()); | 182 Expect.isFalse(file.existsSync()); |
| 183 | 183 |
| 184 tmp.deleteSync(); | 184 tmp.deleteSync(); |
| 185 } | 185 } |
| 186 | 186 |
| 187 void testDeleteFileLink() { | 187 void testDeleteFileLink() { |
| 188 new Directory("").createTemp().then((tmp) { | 188 Directory.systemTemp.createTemp('dart_file_system_delete').then((tmp) { |
| 189 var path = "${tmp.path}${Platform.pathSeparator}"; | 189 var path = "${tmp.path}${Platform.pathSeparator}"; |
| 190 var file = new File("${path}myFile"); | 190 var file = new File("${path}myFile"); |
| 191 var link = new Link("${path}myLink"); | 191 var link = new Link("${path}myLink"); |
| 192 return file.create() | 192 return file.create() |
| 193 .then((_) => link.create(file.path)) | 193 .then((_) => link.create(file.path)) |
| 194 | 194 |
| 195 .then((_) => link.exists().then(Expect.isTrue)) | 195 .then((_) => link.exists().then(Expect.isTrue)) |
| 196 .then((_) => new File(link.path).delete()) | 196 .then((_) => new File(link.path).delete()) |
| 197 .then((_) => link.exists().then(Expect.isFalse)) | 197 .then((_) => link.exists().then(Expect.isFalse)) |
| 198 | 198 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 219 | 219 |
| 220 .then((_) => file.exists().then(Expect.isTrue)) | 220 .then((_) => file.exists().then(Expect.isTrue)) |
| 221 .then((_) => file.delete()) | 221 .then((_) => file.delete()) |
| 222 .then((_) => file.exists().then(Expect.isFalse)) | 222 .then((_) => file.exists().then(Expect.isFalse)) |
| 223 | 223 |
| 224 .then((_) => tmp.delete()); | 224 .then((_) => tmp.delete()); |
| 225 }); | 225 }); |
| 226 } | 226 } |
| 227 | 227 |
| 228 void testDeleteDirectoryLinkSync() { | 228 void testDeleteDirectoryLinkSync() { |
| 229 var tmp = new Directory("").createTempSync(); | 229 var tmp = Directory.systemTemp.createTempSync('dart_file_system_delete'); |
| 230 var path = "${tmp.path}${Platform.pathSeparator}"; | 230 var path = "${tmp.path}${Platform.pathSeparator}"; |
| 231 | 231 |
| 232 var directory = new Directory("${path}myDirectory"); | 232 var directory = new Directory("${path}myDirectory"); |
| 233 directory.createSync(); | 233 directory.createSync(); |
| 234 | 234 |
| 235 var link = new Link("${path}myLink"); | 235 var link = new Link("${path}myLink"); |
| 236 | 236 |
| 237 link.createSync(directory.path); | 237 link.createSync(directory.path); |
| 238 | 238 |
| 239 Expect.isTrue(link.existsSync()); | 239 Expect.isTrue(link.existsSync()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 262 Expect.isFalse(link.existsSync()); | 262 Expect.isFalse(link.existsSync()); |
| 263 | 263 |
| 264 Expect.isTrue(directory.existsSync()); | 264 Expect.isTrue(directory.existsSync()); |
| 265 directory.deleteSync(); | 265 directory.deleteSync(); |
| 266 Expect.isFalse(directory.existsSync()); | 266 Expect.isFalse(directory.existsSync()); |
| 267 | 267 |
| 268 tmp.deleteSync(); | 268 tmp.deleteSync(); |
| 269 } | 269 } |
| 270 | 270 |
| 271 void testDeleteDirectoryLink() { | 271 void testDeleteDirectoryLink() { |
| 272 new Directory("").createTemp().then((tmp) { | 272 Directory.systemTemp.createTemp('dart_file_system_delete').then((tmp) { |
| 273 var path = "${tmp.path}${Platform.pathSeparator}"; | 273 var path = "${tmp.path}${Platform.pathSeparator}"; |
| 274 var dir = new Directory("${path}myDir"); | 274 var dir = new Directory("${path}myDir"); |
| 275 var link = new Link("${path}myLink"); | 275 var link = new Link("${path}myLink"); |
| 276 return dir.create() | 276 return dir.create() |
| 277 .then((_) => link.create(dir.path)) | 277 .then((_) => link.create(dir.path)) |
| 278 | 278 |
| 279 .then((_) => link.exists().then(Expect.isTrue)) | 279 .then((_) => link.exists().then(Expect.isTrue)) |
| 280 .then((_) => new Directory(link.path).delete()) | 280 .then((_) => new Directory(link.path).delete()) |
| 281 .then((_) => link.exists().then(Expect.isFalse)) | 281 .then((_) => link.exists().then(Expect.isFalse)) |
| 282 | 282 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 303 | 303 |
| 304 .then((_) => dir.exists().then(Expect.isTrue)) | 304 .then((_) => dir.exists().then(Expect.isTrue)) |
| 305 .then((_) => dir.delete()) | 305 .then((_) => dir.delete()) |
| 306 .then((_) => dir.exists().then(Expect.isFalse)) | 306 .then((_) => dir.exists().then(Expect.isFalse)) |
| 307 | 307 |
| 308 .then((_) => tmp.delete()); | 308 .then((_) => tmp.delete()); |
| 309 }); | 309 }); |
| 310 } | 310 } |
| 311 | 311 |
| 312 void testDeleteBrokenLinkSync() { | 312 void testDeleteBrokenLinkSync() { |
| 313 var tmp = new Directory("").createTempSync(); | 313 var tmp = Directory.systemTemp.createTempSync('dart_file_system_delete'); |
| 314 var path = "${tmp.path}${Platform.pathSeparator}"; | 314 var path = "${tmp.path}${Platform.pathSeparator}"; |
| 315 | 315 |
| 316 var directory = new Directory("${path}myDirectory"); | 316 var directory = new Directory("${path}myDirectory"); |
| 317 directory.createSync(); | 317 directory.createSync(); |
| 318 | 318 |
| 319 var link = new Link("${path}myLink"); | 319 var link = new Link("${path}myLink"); |
| 320 | 320 |
| 321 link.createSync(directory.path); | 321 link.createSync(directory.path); |
| 322 directory.deleteSync(); | 322 directory.deleteSync(); |
| 323 | 323 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 345 Expect.throws(() => new File(link.path).deleteSync()); | 345 Expect.throws(() => new File(link.path).deleteSync()); |
| 346 Expect.isTrue(link.existsSync()); | 346 Expect.isTrue(link.existsSync()); |
| 347 | 347 |
| 348 link.deleteSync(); | 348 link.deleteSync(); |
| 349 Expect.isFalse(link.existsSync()); | 349 Expect.isFalse(link.existsSync()); |
| 350 | 350 |
| 351 tmp.deleteSync(); | 351 tmp.deleteSync(); |
| 352 } | 352 } |
| 353 | 353 |
| 354 void testDeleteBrokenLink() { | 354 void testDeleteBrokenLink() { |
| 355 new Directory("").createTemp().then((tmp) { | 355 Directory.systemTemp.createTemp('dart_file_system_delete').then((tmp) { |
| 356 var path = "${tmp.path}${Platform.pathSeparator}"; | 356 var path = "${tmp.path}${Platform.pathSeparator}"; |
| 357 var dir = new Directory("${path}myDir"); | 357 var dir = new Directory("${path}myDir"); |
| 358 var link = new Link("${path}myLink"); | 358 var link = new Link("${path}myLink"); |
| 359 return dir.create() | 359 return dir.create() |
| 360 .then((_) => link.create(dir.path)) | 360 .then((_) => link.create(dir.path)) |
| 361 .then((_) => dir.delete()) | 361 .then((_) => dir.delete()) |
| 362 | 362 |
| 363 .then((_) => link.exists().then(Expect.isTrue)) | 363 .then((_) => link.exists().then(Expect.isTrue)) |
| 364 .then((_) => new Link(link.path).delete()) | 364 .then((_) => new Link(link.path).delete()) |
| 365 .then((_) => link.exists().then(Expect.isFalse)) | 365 .then((_) => link.exists().then(Expect.isFalse)) |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 testDeleteDirectory(); | 398 testDeleteDirectory(); |
| 399 if (Platform.operatingSystem != 'windows') { | 399 if (Platform.operatingSystem != 'windows') { |
| 400 testDeleteFileLinkSync(); | 400 testDeleteFileLinkSync(); |
| 401 testDeleteFileLink(); | 401 testDeleteFileLink(); |
| 402 } | 402 } |
| 403 testDeleteDirectoryLinkSync(); | 403 testDeleteDirectoryLinkSync(); |
| 404 testDeleteDirectoryLink(); | 404 testDeleteDirectoryLink(); |
| 405 testDeleteBrokenLinkSync(); | 405 testDeleteBrokenLinkSync(); |
| 406 testDeleteBrokenLink(); | 406 testDeleteBrokenLink(); |
| 407 } | 407 } |
| OLD | NEW |