Chromium Code Reviews| 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("/tmp/dart_temp_dir_"); | |
|
Bill Hesse
2011/12/05 13:21:39
Surely this won't work on Windows, will it? Unles
Mads Ager (google)
2011/12/05 13:32:01
Thanks. I'll just use an empty string. I was copyi
| |
| 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('dart_temp_dir')); | |
| 25 Expect.isTrue(dir.contains('subdir')); | |
| 14 }; | 26 }; |
| 15 | 27 |
| 16 directory.fileHandler = (f) { | 28 directory.fileHandler = (f) { |
| 17 listedSomething = true; | 29 print(f); |
| 30 listedFile = true; | |
| 31 Expect.isTrue(f.contains('dart_temp_dir')); | |
| 32 Expect.isTrue(f.contains('subdir')); | |
| 33 Expect.isTrue(f.contains('file.txt')); | |
| 18 }; | 34 }; |
| 19 | 35 |
| 20 directory.doneHandler = (completed) { | 36 directory.doneHandler = (completed) { |
| 21 Expect.isTrue(completed, "directory listing did not complete"); | 37 Expect.isTrue(completed, "directory listing did not complete"); |
| 22 Expect.isTrue(listedSomething, "empty directory"); | 38 Expect.isTrue(listedDir, "directory not found"); |
| 39 Expect.isTrue(listedFile, "file not found"); | |
| 40 f.deleteHandler = () { | |
| 41 // TODO(ager): use async directory deletion API when available. | |
| 42 subDirectory.deleteSync(); | |
| 43 directory.deleteSync(); | |
| 44 }; | |
| 45 f.delete(); | |
| 23 }; | 46 }; |
| 24 | 47 |
| 25 directory.errorHandler = (error) { | 48 directory.errorHandler = (error) { |
| 26 Expect.fail("error listing directory: $error"); | 49 Expect.fail("error listing directory: $error"); |
| 27 }; | 50 }; |
| 28 | 51 |
| 29 directory.list(); | 52 directory.list(recursive: true); |
| 30 | 53 |
| 31 // Listing is asynchronous, so nothing should be listed at this | 54 // Listing is asynchronous, so nothing should be listed at this |
| 32 // point. | 55 // point. |
| 33 Expect.isFalse(listedSomething); | 56 Expect.isFalse(listedDir); |
| 57 Expect.isFalse(listedFile); | |
| 34 } | 58 } |
| 35 | 59 |
| 36 static void testExistsCreateDelete() { | 60 static void testExistsCreateDelete() { |
| 37 Directory d = new Directory("____DIRECTORY_TEST_DIRECTORY____"); | 61 Directory d = new Directory("/tmp/dart_temp_dir_"); |
| 38 Expect.isFalse(d.existsSync()); | 62 d.createTempSync(); |
| 39 d.createSync(); | |
| 40 Expect.isTrue(d.existsSync()); | 63 Expect.isTrue(d.existsSync()); |
| 64 Directory created = new Directory("${d.path}/subdir"); | |
| 65 created.createSync(); | |
| 66 Expect.isTrue(created.existsSync()); | |
| 67 created.deleteSync(); | |
| 68 Expect.isFalse(created.existsSync()); | |
| 41 d.deleteSync(); | 69 d.deleteSync(); |
| 42 Expect.isFalse(d.existsSync()); | 70 Expect.isFalse(d.existsSync()); |
| 43 | 71 |
| 44 Directory tempDir1 = new Directory("/tmp/dart_temp_dir_"); | 72 Directory tempDir1 = new Directory("/tmp/dart_temp_dir_"); |
| 45 Directory tempDir2 = new Directory("/tmp/dart_temp_dir_"); | 73 Directory tempDir2 = new Directory("/tmp/dart_temp_dir_"); |
| 46 bool stage1aDone = false; | 74 bool stage1aDone = false; |
| 47 bool stage1bDone = false; | 75 bool stage1bDone = false; |
| 48 bool emptyTemplateTestRunning = false; | 76 bool emptyTemplateTestRunning = false; |
| 49 | 77 |
| 50 // Stages 0 through 2 run twice, the second time with an empty path. | 78 // 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(); | 250 new NestedTempDirectoryTest().startTest(); |
| 223 new NestedTempDirectoryTest().startTest(); | 251 new NestedTempDirectoryTest().startTest(); |
| 224 } | 252 } |
| 225 } | 253 } |
| 226 | 254 |
| 227 | 255 |
| 228 main() { | 256 main() { |
| 229 DirectoryTest.testMain(); | 257 DirectoryTest.testMain(); |
| 230 NestedTempDirectoryTest.testMain(); | 258 NestedTempDirectoryTest.testMain(); |
| 231 } | 259 } |
| OLD | NEW |