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 { |
| 11 static void testListing() { | 11 static void testListing() { |
| 12 bool listedDir = false; | 12 bool listedDir = false; |
| 13 bool listedFile = false; | 13 bool listedFile = false; |
| 14 | 14 |
| 15 Directory directory = new Directory(""); | 15 Directory directory = new Directory("").createTempSync(); |
| 16 directory.createTempSync(); | |
| 17 Directory subDirectory = new Directory("${directory.path}/subdir"); | 16 Directory subDirectory = new Directory("${directory.path}/subdir"); |
| 18 Expect.isFalse(subDirectory.existsSync()); | 17 Expect.isFalse(subDirectory.existsSync()); |
| 19 subDirectory.createSync(); | 18 subDirectory.createSync(); |
| 20 File f = new File('${subDirectory.path}/file.txt'); | 19 File f = new File('${subDirectory.path}/file.txt'); |
| 21 Expect.isFalse(f.existsSync()); | 20 Expect.isFalse(f.existsSync()); |
| 22 f.createSync(); | 21 f.createSync(); |
| 23 | 22 |
| 24 directory.onDir = (dir) { | 23 var lister = directory.list(recursive: true); |
| 24 | |
| 25 lister.onDir = (dir) { | |
| 25 listedDir = true; | 26 listedDir = true; |
| 26 Expect.isTrue(dir.contains(directory.path)); | 27 Expect.isTrue(dir.contains(directory.path)); |
| 27 Expect.isTrue(dir.contains('subdir')); | 28 Expect.isTrue(dir.contains('subdir')); |
| 28 }; | 29 }; |
| 29 | 30 |
| 30 directory.onFile = (f) { | 31 lister.onFile = (f) { |
| 31 listedFile = true; | 32 listedFile = true; |
| 32 Expect.isTrue(f.contains(directory.path)); | 33 Expect.isTrue(f.contains(directory.path)); |
| 33 Expect.isTrue(f.contains('subdir')); | 34 Expect.isTrue(f.contains('subdir')); |
| 34 Expect.isTrue(f.contains('file.txt')); | 35 Expect.isTrue(f.contains('file.txt')); |
| 35 }; | 36 }; |
| 36 | 37 |
| 37 directory.onDone = (completed) { | 38 lister.onDone = (completed) { |
| 38 Expect.isTrue(completed, "directory listing did not complete"); | 39 Expect.isTrue(completed, "directory listing did not complete"); |
| 39 Expect.isTrue(listedDir, "directory not found"); | 40 Expect.isTrue(listedDir, "directory not found"); |
| 40 Expect.isTrue(listedFile, "file not found"); | 41 Expect.isTrue(listedFile, "file not found"); |
| 41 directory.deleteRecursively(() { | 42 directory.deleteRecursively().then((ignore) { |
| 42 f.exists((exists) => Expect.isFalse(exists)); | 43 f.exists().then((exists) => Expect.isFalse(exists)); |
| 43 directory.exists((exists) => Expect.isFalse(exists)); | 44 directory.exists().then((exists) => Expect.isFalse(exists)); |
| 44 subDirectory.exists((exists) => Expect.isFalse(exists)); | 45 subDirectory.exists().then((exists) => Expect.isFalse(exists)); |
| 45 }); | 46 }); |
| 46 }; | 47 }; |
| 47 | 48 |
| 48 directory.onError = (e) { | |
| 49 Expect.fail("error listing directory: $e"); | |
| 50 }; | |
| 51 | |
| 52 directory.list(recursive: true); | |
| 53 | |
| 54 // Listing is asynchronous, so nothing should be listed at this | 49 // Listing is asynchronous, so nothing should be listed at this |
| 55 // point. | 50 // point. |
| 56 Expect.isFalse(listedDir); | 51 Expect.isFalse(listedDir); |
| 57 Expect.isFalse(listedFile); | 52 Expect.isFalse(listedFile); |
| 58 } | 53 } |
| 59 | 54 |
| 60 static void testListNonExistent() { | 55 static void testListNonExistent() { |
| 61 Directory d = new Directory(""); | 56 setupListerHandlers(DirectoryLister lister) { |
| 62 d.onError = (e) { | 57 // Test that listing a non-existing directory fails. |
| 63 Expect.fail("Directory error: $e"); | 58 lister.onError = (e) { |
| 64 }; | 59 Expect.isTrue(e is DirectoryIOException); |
| 65 d.createTemp(() { | 60 }; |
| 66 d.delete(() { | 61 lister.onFile = (file) { |
| 67 // Test that listing a non-existing directory fails. | 62 Expect.fail("Listing of non-existing directory should fail"); |
| 68 d.onError = (e) { | 63 }; |
| 69 Expect.isTrue(e is DirectoryIOException); | 64 lister.onDir = (dir) { |
| 70 }; | 65 Expect.fail("Listing of non-existing directory should fail"); |
| 71 d.onFile = (file) { | 66 }; |
| 72 Expect.fail("Listing of non-existing directory should fail"); | 67 lister.onDone = (done) { |
|
ricow1
2012/05/10 11:48:01
I would probably rename done to success, makes mor
Mads Ager (google)
2012/05/10 12:42:38
Done here and above.
| |
| 73 }; | 68 Expect.isFalse(done); |
| 74 d.onDir = (dir) { | 69 }; |
| 75 Expect.fail("Listing of non-existing directory should fail"); | 70 } |
| 76 }; | 71 new Directory("").createTemp().then((d) { |
| 77 d.onDone = (done) { | 72 d.delete().then((ignore) { |
| 78 Expect.isFalse(done); | 73 setupListerHandlers(d.list()); |
| 79 }; | 74 setupListerHandlers(d.list(recursive: true)); |
| 80 d.list(); | |
| 81 d.list(recursive: true); | |
| 82 }); | 75 }); |
| 83 }); | 76 }); |
| 84 } | 77 } |
| 85 | 78 |
| 86 static void testListTooLongName() { | 79 static void testListTooLongName() { |
| 87 Directory d = new Directory(""); | 80 new Directory("").createTemp().then((d) { |
| 88 d.onError = (e) { | 81 var errors = 0; |
| 89 Expect.fail("Directory error: $e"); | 82 setupListHandlers(DirectoryLister lister) { |
| 90 }; | 83 lister.onError = (e) { |
| 91 d.createTemp(() { | 84 Expect.isTrue(e is DirectoryIOException); |
| 85 if (++errors == 2) { | |
| 86 d.deleteRecursively(); | |
| 87 } | |
| 88 }; | |
| 89 lister.onFile = (file) { | |
| 90 Expect.fail("Listing of non-existing directory should fail"); | |
| 91 }; | |
| 92 lister.onDir = (dir) { | |
| 93 Expect.fail("Listing of non-existing directory should fail"); | |
| 94 }; | |
| 95 lister.onDone = (done) { | |
| 96 Expect.isFalse(done); | |
| 97 }; | |
| 98 } | |
| 92 var subDirName = 'subdir'; | 99 var subDirName = 'subdir'; |
| 93 var subDir = new Directory("${d.path}/$subDirName"); | 100 var subDir = new Directory("${d.path}/$subDirName"); |
| 94 subDir.onError = (e) { | 101 subDir.create().then((ignore) { |
| 95 Expect.fail("Directory error: $e"); | |
| 96 }; | |
| 97 subDir.create(() { | |
| 98 // Construct a long string of the form | 102 // Construct a long string of the form |
| 99 // 'tempdir/subdir/../subdir/../subdir'. | 103 // 'tempdir/subdir/../subdir/../subdir'. |
| 100 var buffer = new StringBuffer(); | 104 var buffer = new StringBuffer(); |
| 101 buffer.add(subDir.path); | 105 buffer.add(subDir.path); |
| 102 for (var i = 0; i < 1000; i++) { | 106 for (var i = 0; i < 1000; i++) { |
| 103 buffer.add("/../${subDirName}"); | 107 buffer.add("/../${subDirName}"); |
| 104 } | 108 } |
| 105 var long = new Directory("${buffer.toString()}"); | 109 var long = new Directory("${buffer.toString()}"); |
| 106 var errors = 0; | 110 setupListHandlers(long.list()); |
| 107 long.onError = (e) { | 111 setupListHandlers(long.list(recursive: true)); |
| 108 Expect.isTrue(e is DirectoryIOException); | |
| 109 if (++errors == 2) { | |
| 110 d.deleteRecursively(() => null); | |
| 111 } | |
| 112 }; | |
| 113 long.onFile = (file) { | |
| 114 Expect.fail("Listing of non-existing directory should fail"); | |
| 115 }; | |
| 116 long.onDir = (dir) { | |
| 117 Expect.fail("Listing of non-existing directory should fail"); | |
| 118 }; | |
| 119 long.onDone = (done) { | |
| 120 Expect.isFalse(done); | |
| 121 }; | |
| 122 long.list(); | |
| 123 long.list(recursive: true); | |
| 124 }); | 112 }); |
| 125 }); | 113 }); |
| 126 } | 114 } |
| 127 | 115 |
| 128 static void testDeleteNonExistent() { | 116 static void testDeleteNonExistent() { |
| 129 Directory d = new Directory(""); | 117 // Test that deleting a non-existing directory fails. |
| 130 d.onError = (e) { | 118 setupFutureHandlers(future) { |
| 131 Expect.fail("Directory error: $e"); | 119 future.handleException((e) { |
| 132 }; | 120 Expect.isTrue(e is DirectoryIOException); |
| 133 d.createTemp(() { | 121 return true; |
| 134 d.delete(() { | 122 }); |
| 135 // Test that deleting a non-existing directory fails. | 123 future.then((ignore) { |
| 136 d.onError = (e) { | 124 Expect.fail("Deletion of non-existing directory should fail"); |
| 137 Expect.isTrue(e is DirectoryIOException); | 125 }); |
| 138 }; | 126 } |
| 139 d.delete(() { | 127 |
| 140 Expect.fail("Deletion of non-existing directory should fail"); | 128 new Directory("").createTemp().then((d) { |
| 141 }); | 129 d.delete().then((ignore) { |
| 142 d.deleteRecursively(() { | 130 setupFutureHandlers(d.delete()); |
| 143 Expect.fail("Deletion of non-existing directory should fail"); | 131 setupFutureHandlers(d.deleteRecursively()); |
| 144 }); | |
| 145 }); | 132 }); |
| 146 }); | 133 }); |
| 147 } | 134 } |
| 148 | 135 |
| 149 static void testDeleteTooLongName() { | 136 static void testDeleteTooLongName() { |
| 150 Directory d = new Directory(""); | 137 var port = new ReceivePort(); |
| 151 d.onError = (e) { | 138 new Directory("").createTemp().then((d) { |
| 152 Expect.fail("Directory error: $e"); | |
| 153 }; | |
| 154 d.createTemp(() { | |
| 155 var subDirName = 'subdir'; | 139 var subDirName = 'subdir'; |
| 156 var subDir = new Directory("${d.path}/$subDirName"); | 140 var subDir = new Directory("${d.path}/$subDirName"); |
| 157 subDir.onError = (e) { | 141 subDir.create().then((ignore) { |
| 158 Expect.fail("Directory error: $e"); | 142 // Construct a long string of the form |
| 159 }; | 143 // 'tempdir/subdir/../subdir/../subdir'. |
| 160 subDir.create(() { | 144 var buffer = new StringBuffer(); |
| 161 // Construct a long string of the form | 145 buffer.add(subDir.path); |
| 162 // 'tempdir/subdir/../subdir/../subdir'. | 146 for (var i = 0; i < 1000; i++) { |
| 163 var buffer = new StringBuffer(); | 147 buffer.add("/../${subDirName}"); |
| 164 buffer.add(subDir.path); | |
| 165 for (var i = 0; i < 1000; i++) { | |
| 166 buffer.add("/../${subDirName}"); | |
| 167 } | |
| 168 var long = new Directory("${buffer.toString()}"); | |
| 169 var errors = 0; | |
| 170 long.onError = (e) { | |
| 171 Expect.isTrue(e is DirectoryIOException); | |
| 172 if (++errors == 2) { | |
| 173 d.deleteRecursively(() => null); | |
| 174 } | 148 } |
| 175 }; | 149 var long = new Directory("${buffer.toString()}"); |
| 176 long.delete(() { | 150 var errors = 0; |
| 177 Expect.fail("Deletion of a directory with a long name should fail"); | 151 onError(e) { |
| 152 Expect.isTrue(e is DirectoryIOException); | |
| 153 if (++errors == 2) { | |
| 154 d.deleteRecursively().then((ignore) => port.close()); | |
| 155 } | |
| 156 return true; | |
| 157 } | |
| 158 long.delete().handleException(onError); | |
| 159 long.deleteRecursively().handleException(onError); | |
| 178 }); | 160 }); |
| 179 long.deleteRecursively(() { | |
| 180 Expect.fail("Deletion of a directory with a long name should fail"); | |
| 181 }); | |
| 182 }); | |
| 183 }); | 161 }); |
| 184 } | 162 } |
| 185 | 163 |
| 186 static void testDeleteNonExistentSync() { | 164 static void testDeleteNonExistentSync() { |
| 187 Directory d = new Directory(""); | 165 Directory d = new Directory("").createTempSync(); |
| 188 d.createTempSync(); | |
| 189 d.deleteSync(); | 166 d.deleteSync(); |
| 190 Expect.throws(d.deleteSync); | 167 Expect.throws(d.deleteSync); |
| 191 Expect.throws(() => d.deleteRecursivelySync()); | 168 Expect.throws(() => d.deleteRecursivelySync()); |
| 192 } | 169 } |
| 193 | 170 |
| 194 static void testDeleteTooLongNameSync() { | 171 static void testDeleteTooLongNameSync() { |
| 195 Directory d = new Directory(""); | 172 Directory d = new Directory("").createTempSync(); |
| 196 d.createTempSync(); | |
| 197 var subDirName = 'subdir'; | 173 var subDirName = 'subdir'; |
| 198 var subDir = new Directory("${d.path}/$subDirName"); | 174 var subDir = new Directory("${d.path}/$subDirName"); |
| 199 subDir.createSync(); | 175 subDir.createSync(); |
| 200 // Construct a long string of the form | 176 // Construct a long string of the form |
| 201 // 'tempdir/subdir/../subdir/../subdir'. | 177 // 'tempdir/subdir/../subdir/../subdir'. |
| 202 var buffer = new StringBuffer(); | 178 var buffer = new StringBuffer(); |
| 203 buffer.add(subDir.path); | 179 buffer.add(subDir.path); |
| 204 for (var i = 0; i < 1000; i++) { | 180 for (var i = 0; i < 1000; i++) { |
| 205 buffer.add("/../${subDirName}"); | 181 buffer.add("/../${subDirName}"); |
| 206 } | 182 } |
| 207 var long = new Directory("${buffer.toString()}"); | 183 var long = new Directory("${buffer.toString()}"); |
| 208 Expect.throws(long.deleteSync); | 184 Expect.throws(long.deleteSync); |
| 209 Expect.throws(() => long.deleteRecursivelySync()); | 185 Expect.throws(() => long.deleteRecursivelySync()); |
| 210 } | 186 } |
| 211 | 187 |
| 212 static void testExistsCreateDelete() { | 188 static void testExistsCreateDelete() { |
| 213 Directory d = new Directory(""); | 189 new Directory("").createTemp().then((d) { |
| 214 d.createTemp(() { | 190 d.exists().then((bool exists) { |
| 215 d.exists((bool exists) { | |
| 216 Expect.isTrue(exists); | 191 Expect.isTrue(exists); |
| 217 Directory created = new Directory("${d.path}/subdir"); | 192 Directory created = new Directory("${d.path}/subdir"); |
| 218 created.create(() { | 193 created.create().then((ignore) { |
| 219 created.exists((bool exists) { | 194 created.exists().then((bool exists) { |
| 220 Expect.isTrue(exists); | 195 Expect.isTrue(exists); |
| 221 created.delete(() { | 196 created.delete().then((ignore) { |
| 222 created.exists((bool exists) { | 197 created.exists().then((bool exists) { |
| 223 Expect.isFalse(exists); | 198 Expect.isFalse(exists); |
| 224 d.delete(() { | 199 d.delete().then((ignore) { |
| 225 d.exists((bool exists) { | 200 d.exists().then((bool exists) { |
| 226 Expect.isFalse(exists); | 201 Expect.isFalse(exists); |
| 227 }); | 202 }); |
| 228 }); | 203 }); |
| 229 }); | 204 }); |
| 230 }); | 205 }); |
| 231 }); | 206 }); |
| 232 }); | 207 }); |
| 233 }); | 208 }); |
| 234 }); | 209 }); |
| 235 } | 210 } |
| 236 | 211 |
| 237 static void testExistsCreateDeleteSync() { | 212 static void testExistsCreateDeleteSync() { |
| 238 Directory d = new Directory(""); | 213 Directory d = new Directory("").createTempSync(); |
| 239 d.createTempSync(); | |
| 240 Expect.isTrue(d.existsSync()); | 214 Expect.isTrue(d.existsSync()); |
| 241 Directory created = new Directory("${d.path}/subdir"); | 215 Directory created = new Directory("${d.path}/subdir"); |
| 242 created.createSync(); | 216 created.createSync(); |
| 243 Expect.isTrue(created.existsSync()); | 217 Expect.isTrue(created.existsSync()); |
| 244 created.deleteSync(); | 218 created.deleteSync(); |
| 245 Expect.isFalse(created.existsSync()); | 219 Expect.isFalse(created.existsSync()); |
| 246 d.deleteSync(); | 220 d.deleteSync(); |
| 247 Expect.isFalse(d.existsSync()); | 221 Expect.isFalse(d.existsSync()); |
| 248 } | 222 } |
| 249 | 223 |
| 250 static void testCreateTemp() { | 224 static void testCreateTemp() { |
| 251 Directory tempDir1 = new Directory("/tmp/dart_temp_dir_"); | 225 Directory tempDir1; |
| 252 Directory tempDir2 = new Directory("/tmp/dart_temp_dir_"); | 226 Directory tempDir2; |
| 253 bool stage1aDone = false; | 227 bool stage1aDone = false; |
| 254 bool stage1bDone = false; | 228 bool stage1bDone = false; |
| 255 bool emptyTemplateTestRunning = false; | 229 bool emptyTemplateTestRunning = false; |
| 256 | 230 |
| 257 // Stages 0 through 2 run twice, the second time with an empty path. | 231 // Stages 0 through 2 run twice, the second time with an empty path. |
| 258 Function stage0; | 232 Function stage0; |
| 259 Function stage1a; | 233 Function stage1a; |
| 260 Function stage1b; | 234 Function stage1b; |
| 261 Function stage2; | 235 Function stage2; |
| 262 Function stage3; // Loops to stage 0. | 236 Function stage3; // Loops to stage 0. |
| 263 | 237 |
| 264 Function error(e) { | |
| 265 Expect.fail("Directory onError: $e"); | |
| 266 } | |
| 267 | |
| 268 stage0 = () { | 238 stage0 = () { |
| 269 tempDir1.onError = error; | 239 var dir = new Directory("/tmp/dart_temp_dir_"); |
| 270 tempDir1.createTemp(stage1a); | 240 dir.createTemp().then(stage1a); |
| 271 tempDir2.onError = error; | 241 dir.createTemp().then(stage1b); |
| 272 tempDir2.createTemp(stage1b); | |
| 273 }; | 242 }; |
| 274 | 243 |
| 275 stage1a = () { | 244 stage1a = (temp) { |
| 245 tempDir1 = temp; | |
| 276 stage1aDone = true; | 246 stage1aDone = true; |
| 277 Expect.isTrue(tempDir1.existsSync()); | 247 Expect.isTrue(tempDir1.existsSync()); |
| 278 if (stage1bDone) { | 248 if (stage1bDone) { |
| 279 stage2(); | 249 stage2(); |
| 280 } | 250 } |
| 281 }; | 251 }; |
| 282 | 252 |
| 283 stage1b = () { | 253 stage1b = (temp) { |
| 254 tempDir2 = temp; | |
| 284 stage1bDone = true; | 255 stage1bDone = true; |
| 285 Expect.isTrue(tempDir2.existsSync()); | 256 Expect.isTrue(tempDir2.existsSync()); |
| 286 if (stage1aDone) { | 257 if (stage1aDone) { |
| 287 stage2(); | 258 stage2(); |
| 288 } | 259 } |
| 289 }; | 260 }; |
| 290 | 261 |
| 291 stage2 = () { | 262 stage2 = () { |
| 292 Expect.notEquals(tempDir1.path, tempDir2.path); | 263 Expect.notEquals(tempDir1.path, tempDir2.path); |
| 293 tempDir1.deleteSync(); | 264 tempDir1.deleteSync(); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 312 | 283 |
| 313 if (new Directory("/tmp").existsSync()) { | 284 if (new Directory("/tmp").existsSync()) { |
| 314 stage0(); | 285 stage0(); |
| 315 } else { | 286 } else { |
| 316 emptyTemplateTestRunning = true; | 287 emptyTemplateTestRunning = true; |
| 317 stage3(); | 288 stage3(); |
| 318 } | 289 } |
| 319 } | 290 } |
| 320 | 291 |
| 321 static void testCreateDeleteTemp() { | 292 static void testCreateDeleteTemp() { |
| 322 Directory tempDirectory = new Directory(""); | 293 new Directory("").createTemp().then((tempDirectory) { |
| 323 tempDirectory.createTemp(() { | |
| 324 String filename = tempDirectory.path + | 294 String filename = tempDirectory.path + |
| 325 Platform.pathSeparator + "dart_testfile"; | 295 Platform.pathSeparator + "dart_testfile"; |
| 326 File file = new File(filename); | 296 File file = new File(filename); |
| 327 Expect.isFalse(file.existsSync()); | 297 Expect.isFalse(file.existsSync()); |
| 328 file.onError = (e) { | 298 file.create().then((ignore) { |
| 329 Expect.fail("testCreateTemp file.onError called: $e"); | 299 file.exists().then((exists) { |
| 330 }; | |
| 331 file.create(() { | |
| 332 file.exists((bool exists) { | |
| 333 Expect.isTrue(exists); | 300 Expect.isTrue(exists); |
| 334 // Try to delete the directory containing the file - should throw. | 301 // Try to delete the directory containing the file - should throw. |
| 335 Expect.throws(tempDirectory.deleteSync); | 302 Expect.throws(tempDirectory.deleteSync); |
| 336 Expect.isTrue(tempDirectory.existsSync()); | 303 Expect.isTrue(tempDirectory.existsSync()); |
| 337 | 304 |
| 338 // Delete the file, and then delete the directory. | 305 // Delete the file, and then delete the directory. |
| 339 file.delete(() { | 306 file.delete().then((ignore) { |
| 340 tempDirectory.deleteSync(); | 307 tempDirectory.deleteSync(); |
| 341 Expect.isFalse(tempDirectory.existsSync()); | 308 Expect.isFalse(tempDirectory.existsSync()); |
| 342 }); | 309 }); |
| 343 }); | 310 }); |
| 344 }); | 311 }); |
| 345 }); | 312 }); |
| 346 } | 313 } |
| 347 | 314 |
| 348 static void testCurrent() { | 315 static void testCurrent() { |
| 349 Directory current = new Directory.current(); | 316 Directory current = new Directory.current(); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 367 testCurrent(); | 334 testCurrent(); |
| 368 } | 335 } |
| 369 } | 336 } |
| 370 | 337 |
| 371 | 338 |
| 372 class NestedTempDirectoryTest { | 339 class NestedTempDirectoryTest { |
| 373 List<Directory> createdDirectories; | 340 List<Directory> createdDirectories; |
| 374 Directory current; | 341 Directory current; |
| 375 | 342 |
| 376 NestedTempDirectoryTest.run() | 343 NestedTempDirectoryTest.run() |
| 377 : createdDirectories = new List<Directory>(), | 344 : createdDirectories = new List<Directory>() { |
| 378 current = new Directory("") { | 345 new Directory("").createTemp().then(createPhaseCallback); |
| 379 current.onError = errorCallback; | |
| 380 current.createTemp(createPhaseCallback); | |
| 381 } | 346 } |
| 382 | 347 |
| 383 void errorCallback(e) { | 348 void createPhaseCallback(temp) { |
| 384 Expect.fail("Error callback called in NestedTempDirectoryTest: $e"); | 349 createdDirectories.add(temp); |
| 385 } | |
| 386 | |
| 387 void createPhaseCallback() { | |
| 388 createdDirectories.add(current); | |
| 389 int nestingDepth = 6; | 350 int nestingDepth = 6; |
| 390 var os = Platform.operatingSystem; | 351 var os = Platform.operatingSystem; |
| 391 if (os == "windows") nestingDepth = 2; | 352 if (os == "windows") nestingDepth = 2; |
| 392 if (createdDirectories.length < nestingDepth) { | 353 if (createdDirectories.length < nestingDepth) { |
| 393 current = new Directory( | 354 temp = new Directory( |
| 394 current.path + "/nested_temp_dir_${createdDirectories.length}_"); | 355 temp.path + "/nested_temp_dir_${createdDirectories.length}_"); |
|
ricow1
2012/05/10 11:48:01
"${temp.path/nest..." instead?
Mads Ager (google)
2012/05/10 12:42:38
'${temp.path}/nest...'
Done.
| |
| 395 current.onError = errorCallback; | 356 temp.createTemp().then(createPhaseCallback); |
| 396 current.createTemp(createPhaseCallback); | |
| 397 } else { | 357 } else { |
| 398 deletePhaseCallback(); | 358 deletePhaseCallback(); |
| 399 } | 359 } |
| 400 } | 360 } |
| 401 | 361 |
| 402 void deletePhaseCallback() { | 362 void deletePhaseCallback() { |
| 403 if (!createdDirectories.isEmpty()) { | 363 if (!createdDirectories.isEmpty()) { |
| 404 current = createdDirectories.removeLast(); | 364 current = createdDirectories.removeLast(); |
| 405 current.deleteSync(); | 365 current.deleteSync(); |
| 406 deletePhaseCallback(); | 366 deletePhaseCallback(); |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 433 Expect.throws(new Directory(location).createTempSync, | 393 Expect.throws(new Directory(location).createTempSync, |
| 434 (e) => e is DirectoryIOException); | 394 (e) => e is DirectoryIOException); |
| 435 } | 395 } |
| 436 } | 396 } |
| 437 | 397 |
| 438 | 398 |
| 439 testCreateTempError() { | 399 testCreateTempError() { |
| 440 var location = illegalTempDirectoryLocation(); | 400 var location = illegalTempDirectoryLocation(); |
| 441 if (location == null) return; | 401 if (location == null) return; |
| 442 | 402 |
| 443 var resultPort = new ReceivePort(); | 403 var port = new ReceivePort(); |
| 444 resultPort.receive((String message, ignored) { | 404 var future = new Directory(location).createTemp(); |
| 445 resultPort.close(); | 405 future.handleException((e) => port.close()); |
| 446 Expect.equals("error", message); | |
| 447 }); | |
| 448 | |
| 449 Directory dir = new Directory(location); | |
| 450 dir.onError = (e) { resultPort.toSendPort().send("error"); }; | |
| 451 dir.createTemp(() => resultPort.toSendPort().send("success")); | |
| 452 } | 406 } |
| 453 | 407 |
| 454 | 408 |
| 455 main() { | 409 main() { |
| 456 DirectoryTest.testMain(); | 410 DirectoryTest.testMain(); |
| 457 NestedTempDirectoryTest.testMain(); | 411 NestedTempDirectoryTest.testMain(); |
| 458 testCreateTempErrorSync(); | 412 testCreateTempErrorSync(); |
| 459 testCreateTempError(); | 413 testCreateTempError(); |
| 460 } | 414 } |
| OLD | NEW |