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