Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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 // Directory listing test. | 5 // Directory listing test. |
| 6 | 6 |
| 7 #import("dart:io"); | 7 #import("dart:io"); |
| 8 #import("dart:isolate"); | 8 #import("dart:isolate"); |
| 9 | 9 |
| 10 class DirectoryTest { | 10 class DirectoryTest { |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 179 buffer.add(subDir.path); | 179 buffer.add(subDir.path); |
| 180 for (var i = 0; i < 1000; i++) { | 180 for (var i = 0; i < 1000; i++) { |
| 181 buffer.add("/../${subDirName}"); | 181 buffer.add("/../${subDirName}"); |
| 182 } | 182 } |
| 183 var long = new Directory("${buffer.toString()}"); | 183 var long = new Directory("${buffer.toString()}"); |
| 184 Expect.throws(long.deleteSync); | 184 Expect.throws(long.deleteSync); |
| 185 Expect.throws(() => long.deleteRecursivelySync()); | 185 Expect.throws(() => long.deleteRecursivelySync()); |
| 186 d.deleteRecursivelySync(); | 186 d.deleteRecursivelySync(); |
| 187 } | 187 } |
| 188 | 188 |
| 189 static void testDeleteWindowsJunction() { | |
|
Søren Gjesse
2012/08/17 07:07:37
Shouldn't we make this test run with symlinks on L
Mads Ager (google)
2012/08/17 07:08:46
Does this test leave a temporary directory behind.
Bob Nystrom
2012/08/20 23:24:32
Done.
Bob Nystrom
2012/08/20 23:24:32
Done.
| |
| 190 if (Platform.operatingSystem != "windows") return; | |
| 191 | |
| 192 // temp/ | |
| 193 // a/ | |
| 194 // file.txt | |
| 195 // b/ | |
| 196 // a_junction -> a | |
| 197 var d = new Directory("").createTempSync(); | |
| 198 new Directory("${d.path}\\a").createSync(); | |
| 199 | |
| 200 var b = new Directory("${d.path}\\b"); | |
| 201 b.createSync(); | |
| 202 | |
| 203 var f = new File("${d.path}\\a\\file.txt"); | |
| 204 f.createSync(); | |
| 205 Expect.isTrue(f.existsSync()); | |
| 206 | |
| 207 // Create a junction from temp/b/a_junction -> temp/a. | |
| 208 var args = ["/c", "mklink", "/j", | |
| 209 "${d.path}\\b\\a_junction", "${d.path}\\a"]; | |
| 210 Process.run("cmd", args).then((_) { | |
| 211 // Delete the directory containing the junction. | |
| 212 b.deleteRecursivelySync(); | |
| 213 | |
| 214 // We should not have recursed through a_junction into a. | |
| 215 Expect.isTrue(f.existsSync()); | |
| 216 }); | |
| 217 } | |
| 218 | |
| 189 static void testExistsCreateDelete() { | 219 static void testExistsCreateDelete() { |
| 190 new Directory("").createTemp().then((d) { | 220 new Directory("").createTemp().then((d) { |
| 191 d.exists().then((bool exists) { | 221 d.exists().then((bool exists) { |
| 192 Expect.isTrue(exists); | 222 Expect.isTrue(exists); |
| 193 Directory created = new Directory("${d.path}/subdir"); | 223 Directory created = new Directory("${d.path}/subdir"); |
| 194 created.create().then((ignore) { | 224 created.create().then((ignore) { |
| 195 created.exists().then((bool exists) { | 225 created.exists().then((bool exists) { |
| 196 Expect.isTrue(exists); | 226 Expect.isTrue(exists); |
| 197 created.delete().then((ignore) { | 227 created.delete().then((ignore) { |
| 198 created.exists().then((bool exists) { | 228 created.exists().then((bool exists) { |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 330 } | 360 } |
| 331 | 361 |
| 332 static void testMain() { | 362 static void testMain() { |
| 333 testListing(); | 363 testListing(); |
| 334 testListNonExistent(); | 364 testListNonExistent(); |
| 335 testListTooLongName(); | 365 testListTooLongName(); |
| 336 testDeleteNonExistent(); | 366 testDeleteNonExistent(); |
| 337 testDeleteTooLongName(); | 367 testDeleteTooLongName(); |
| 338 testDeleteNonExistentSync(); | 368 testDeleteNonExistentSync(); |
| 339 testDeleteTooLongNameSync(); | 369 testDeleteTooLongNameSync(); |
| 370 testDeleteWindowsJunction(); | |
| 340 testExistsCreateDelete(); | 371 testExistsCreateDelete(); |
| 341 testExistsCreateDeleteSync(); | 372 testExistsCreateDeleteSync(); |
| 342 testCreateTemp(); | 373 testCreateTemp(); |
| 343 testCreateDeleteTemp(); | 374 testCreateDeleteTemp(); |
| 344 testCurrent(); | 375 testCurrent(); |
| 345 testFromPath(); | 376 testFromPath(); |
| 346 } | 377 } |
| 347 } | 378 } |
| 348 | 379 |
| 349 | 380 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 429 temp2.rename(temp1.path).then((temp4) { | 460 temp2.rename(temp1.path).then((temp4) { |
| 430 Expect.isFalse(temp3.existsSync()); | 461 Expect.isFalse(temp3.existsSync()); |
| 431 Expect.isFalse(temp2.existsSync()); | 462 Expect.isFalse(temp2.existsSync()); |
| 432 Expect.isTrue(temp1.existsSync()); | 463 Expect.isTrue(temp1.existsSync()); |
| 433 Expect.isTrue(temp4.existsSync()); | 464 Expect.isTrue(temp4.existsSync()); |
| 434 Expect.equals(temp1.path, temp4.path); | 465 Expect.equals(temp1.path, temp4.path); |
| 435 temp1.deleteRecursivelySync(); | 466 temp1.deleteRecursivelySync(); |
| 436 }); | 467 }); |
| 437 } | 468 } |
| 438 | 469 |
| 470 Future<File> writeFile(File file, String contents) { | |
|
Mads Ager (google)
2012/08/17 07:08:46
Where are you using this? Remove?
Bob Nystrom
2012/08/20 23:24:32
Done.
| |
| 471 return file.open(FileMode.WRITE).chain((opened) { | |
| 472 return opened.writeString(contents).chain((_) { | |
| 473 return opened.close().transform((ignore) => file); | |
| 474 }); | |
| 475 }); | |
| 476 } | |
| 439 | 477 |
| 440 main() { | 478 main() { |
| 441 DirectoryTest.testMain(); | 479 DirectoryTest.testMain(); |
| 442 NestedTempDirectoryTest.testMain(); | 480 NestedTempDirectoryTest.testMain(); |
| 443 testCreateTempErrorSync(); | 481 testCreateTempErrorSync(); |
| 444 testCreateTempError(); | 482 testCreateTempError(); |
| 445 testRename(); | 483 testRename(); |
| 446 } | 484 } |
| OLD | NEW |