| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 class DirectoryTest { | 7 class DirectoryTest { |
| 8 static void testListing() { | 8 static void testListing() { |
| 9 bool listedSomething = false; | 9 bool listedDir = false; |
| 10 Directory directory = new Directory("."); | 10 bool listedFile = false; |
| 11 |
| 12 Directory directory = new Directory(""); |
| 13 directory.createTempSync(); |
| 14 Directory subDirectory = new Directory("${directory.path}/subdir"); |
| 15 Expect.isFalse(subDirectory.existsSync()); |
| 16 subDirectory.createSync(); |
| 17 File f = new File('${subDirectory.path}/file.txt'); |
| 18 Expect.isFalse(f.existsSync()); |
| 19 f.createSync(); |
| 11 | 20 |
| 12 directory.dirHandler = (dir) { | 21 directory.dirHandler = (dir) { |
| 13 listedSomething = true; | 22 print(dir); |
| 23 listedDir = true; |
| 24 Expect.isTrue(dir.contains('subdir')); |
| 14 }; | 25 }; |
| 15 | 26 |
| 16 directory.fileHandler = (f) { | 27 directory.fileHandler = (f) { |
| 17 listedSomething = true; | 28 print(f); |
| 29 listedFile = true; |
| 30 Expect.isTrue(f.contains('subdir')); |
| 31 Expect.isTrue(f.contains('file.txt')); |
| 18 }; | 32 }; |
| 19 | 33 |
| 20 directory.doneHandler = (completed) { | 34 directory.doneHandler = (completed) { |
| 21 Expect.isTrue(completed, "directory listing did not complete"); | 35 Expect.isTrue(completed, "directory listing did not complete"); |
| 22 Expect.isTrue(listedSomething, "empty directory"); | 36 Expect.isTrue(listedDir, "directory not found"); |
| 37 Expect.isTrue(listedFile, "file not found"); |
| 38 f.deleteHandler = () { |
| 39 // TODO(ager): use async directory deletion API when available. |
| 40 subDirectory.deleteSync(); |
| 41 directory.deleteSync(); |
| 42 }; |
| 43 f.delete(); |
| 23 }; | 44 }; |
| 24 | 45 |
| 25 directory.errorHandler = (error) { | 46 directory.errorHandler = (error) { |
| 26 Expect.fail("error listing directory: $error"); | 47 Expect.fail("error listing directory: $error"); |
| 27 }; | 48 }; |
| 28 | 49 |
| 29 directory.list(); | 50 directory.list(recursive: true); |
| 30 | 51 |
| 31 // Listing is asynchronous, so nothing should be listed at this | 52 // Listing is asynchronous, so nothing should be listed at this |
| 32 // point. | 53 // point. |
| 33 Expect.isFalse(listedSomething); | 54 Expect.isFalse(listedDir); |
| 55 Expect.isFalse(listedFile); |
| 34 } | 56 } |
| 35 | 57 |
| 36 static void testExistsCreateDelete() { | 58 static void testExistsCreateDelete() { |
| 37 Directory d = new Directory("____DIRECTORY_TEST_DIRECTORY____"); | 59 Directory d = new Directory("/tmp/dart_temp_dir_"); |
| 38 Expect.isFalse(d.existsSync()); | 60 d.createTempSync(); |
| 39 d.createSync(); | |
| 40 Expect.isTrue(d.existsSync()); | 61 Expect.isTrue(d.existsSync()); |
| 62 Directory created = new Directory("${d.path}/subdir"); |
| 63 created.createSync(); |
| 64 Expect.isTrue(created.existsSync()); |
| 65 created.deleteSync(); |
| 66 Expect.isFalse(created.existsSync()); |
| 41 d.deleteSync(); | 67 d.deleteSync(); |
| 42 Expect.isFalse(d.existsSync()); | 68 Expect.isFalse(d.existsSync()); |
| 43 | 69 |
| 44 Directory tempDir1 = new Directory("/tmp/dart_temp_dir_"); | 70 Directory tempDir1 = new Directory("/tmp/dart_temp_dir_"); |
| 45 Directory tempDir2 = new Directory("/tmp/dart_temp_dir_"); | 71 Directory tempDir2 = new Directory("/tmp/dart_temp_dir_"); |
| 46 bool stage1aDone = false; | 72 bool stage1aDone = false; |
| 47 bool stage1bDone = false; | 73 bool stage1bDone = false; |
| 48 bool emptyTemplateTestRunning = false; | 74 bool emptyTemplateTestRunning = false; |
| 49 | 75 |
| 50 // Stages 0 through 2 run twice, the second time with an empty path. | 76 // Stages 0 through 2 run twice, the second time with an empty path. |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 new NestedTempDirectoryTest().startTest(); | 248 new NestedTempDirectoryTest().startTest(); |
| 223 new NestedTempDirectoryTest().startTest(); | 249 new NestedTempDirectoryTest().startTest(); |
| 224 } | 250 } |
| 225 } | 251 } |
| 226 | 252 |
| 227 | 253 |
| 228 main() { | 254 main() { |
| 229 DirectoryTest.testMain(); | 255 DirectoryTest.testMain(); |
| 230 NestedTempDirectoryTest.testMain(); | 256 NestedTempDirectoryTest.testMain(); |
| 231 } | 257 } |
| OLD | NEW |