Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(631)

Side by Side Diff: tests/standalone/io/file_error_test.dart

Issue 23886004: Update dart:io tests to use asyncStart/asyncEnd (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/standalone/io/directory_test.dart ('k') | tests/standalone/io/file_fuzz_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 // Dart test program for testing error handling in file I/O. 5 // Dart test program for testing error handling in file I/O.
6 6
7 import "package:expect/expect.dart";
8 import "dart:convert"; 7 import "dart:convert";
9 import "dart:io"; 8 import "dart:io";
10 import "dart:isolate"; 9
10 import "package:async_helper/async_helper.dart";
11 import "package:expect/expect.dart";
11 12
12 Directory tempDir() { 13 Directory tempDir() {
13 return new Directory('').createTempSync(); 14 return new Directory('').createTempSync();
14 } 15 }
15 16
16 17
17 bool checkNonExistentFileException(e, str) { 18 bool checkNonExistentFileException(e, str) {
18 Expect.isTrue(e is FileException); 19 Expect.isTrue(e is FileException);
19 Expect.isTrue(e.osError != null); 20 Expect.isTrue(e.osError != null);
20 Expect.isTrue(e.toString().indexOf(str) != -1); 21 Expect.isTrue(e.toString().indexOf(str) != -1);
(...skipping 12 matching lines...) Expand all
33 return checkNonExistentFileException(e, "Cannot delete file"); 34 return checkNonExistentFileException(e, "Cannot delete file");
34 } 35 }
35 36
36 37
37 bool checkLengthNonExistentFileException(e) { 38 bool checkLengthNonExistentFileException(e) {
38 return checkNonExistentFileException(e, "Cannot retrieve length of file"); 39 return checkNonExistentFileException(e, "Cannot retrieve length of file");
39 } 40 }
40 41
41 42
42 void testOpenNonExistent() { 43 void testOpenNonExistent() {
44 asyncStart();
43 Directory temp = tempDir(); 45 Directory temp = tempDir();
44 ReceivePort p = new ReceivePort();
45 p.receive((x, y) {
46 p.close();
47 temp.deleteSync(recursive: true);
48 });
49 var file = new File("${temp.path}/nonExistentFile"); 46 var file = new File("${temp.path}/nonExistentFile");
50 47
51 // Non-existing file should throw exception. 48 // Non-existing file should throw exception.
52 Expect.throws(() => file.openSync(), 49 Expect.throws(() => file.openSync(),
53 (e) => checkOpenNonExistentFileException(e)); 50 (e) => checkOpenNonExistentFileException(e));
54 51
55 var openFuture = file.open(mode: FileMode.READ); 52 var openFuture = file.open(mode: FileMode.READ);
56 openFuture.then((raf) => Expect.fail("Unreachable code")) 53 openFuture.then((raf) => Expect.fail("Unreachable code"))
57 .catchError((error) { 54 .catchError((error) {
58 checkOpenNonExistentFileException(error); 55 checkOpenNonExistentFileException(error);
59 p.toSendPort().send(null); 56 temp.deleteSync(recursive: true);
57 asyncEnd();
60 }); 58 });
61 } 59 }
62 60
63 61
64 void testDeleteNonExistent() { 62 void testDeleteNonExistent() {
63 asyncStart();
65 Directory temp = tempDir(); 64 Directory temp = tempDir();
66 ReceivePort p = new ReceivePort();
67 p.receive((x, y) {
68 p.close();
69 temp.deleteSync(recursive: true);
70 });
71 var file = new File("${temp.path}/nonExistentFile"); 65 var file = new File("${temp.path}/nonExistentFile");
72 66
73 // Non-existing file should throw exception. 67 // Non-existing file should throw exception.
74 Expect.throws(() => file.deleteSync(), 68 Expect.throws(() => file.deleteSync(),
75 (e) => checkDeleteNonExistentFileException(e)); 69 (e) => checkDeleteNonExistentFileException(e));
76 70
77 var delete = file.delete(); 71 var delete = file.delete();
78 delete.then((ignore) => Expect.fail("Unreachable code")) 72 delete.then((ignore) => Expect.fail("Unreachable code"))
79 .catchError((error) { 73 .catchError((error) {
80 checkDeleteNonExistentFileException(error); 74 checkDeleteNonExistentFileException(error);
81 p.toSendPort().send(null); 75 temp.deleteSync(recursive: true);
76 asyncEnd();
82 }); 77 });
83 } 78 }
84 79
85 80
86 void testLengthNonExistent() { 81 void testLengthNonExistent() {
82 asyncStart();
87 Directory temp = tempDir(); 83 Directory temp = tempDir();
88 ReceivePort p = new ReceivePort();
89 p.receive((x, y) {
90 p.close();
91 temp.deleteSync(recursive: true);
92 });
93 var file = new File("${temp.path}/nonExistentFile"); 84 var file = new File("${temp.path}/nonExistentFile");
94 85
95 // Non-existing file should throw exception. 86 // Non-existing file should throw exception.
96 Expect.throws(() => file.lengthSync(), 87 Expect.throws(() => file.lengthSync(),
97 (e) => checkLengthNonExistentFileException(e)); 88 (e) => checkLengthNonExistentFileException(e));
98 89
99 var lenFuture = file.length(); 90 var lenFuture = file.length();
100 lenFuture.then((len) => Expect.fail("Unreachable code")) 91 lenFuture.then((len) => Expect.fail("Unreachable code"))
101 .catchError((error) { 92 .catchError((error) {
102 checkLengthNonExistentFileException(error); 93 checkLengthNonExistentFileException(error);
103 p.toSendPort().send(null); 94 temp.deleteSync(recursive: true);
95 asyncEnd();
104 }); 96 });
105 } 97 }
106 98
107 99
108 bool checkCreateInNonExistentDirectoryException(e) { 100 bool checkCreateInNonExistentDirectoryException(e) {
109 Expect.isTrue(e is FileException); 101 Expect.isTrue(e is FileException);
110 Expect.isTrue(e.osError != null); 102 Expect.isTrue(e.osError != null);
111 Expect.isTrue(e.toString().indexOf("Cannot create file") != -1); 103 Expect.isTrue(e.toString().indexOf("Cannot create file") != -1);
112 if (Platform.operatingSystem == "linux") { 104 if (Platform.operatingSystem == "linux") {
113 Expect.equals(2, e.osError.errorCode); 105 Expect.equals(2, e.osError.errorCode);
114 } else if (Platform.operatingSystem == "macos") { 106 } else if (Platform.operatingSystem == "macos") {
115 Expect.equals(2, e.osError.errorCode); 107 Expect.equals(2, e.osError.errorCode);
116 } else if (Platform.operatingSystem == "windows") { 108 } else if (Platform.operatingSystem == "windows") {
117 Expect.equals(3, e.osError.errorCode); 109 Expect.equals(3, e.osError.errorCode);
118 } 110 }
119 111
120 return true; 112 return true;
121 } 113 }
122 114
123 void testCreateInNonExistentDirectory() { 115 void testCreateInNonExistentDirectory() {
116 asyncStart();
124 Directory temp = tempDir(); 117 Directory temp = tempDir();
125 ReceivePort p = new ReceivePort();
126 p.receive((x, y) {
127 p.close();
128 temp.deleteSync(recursive: true);
129 });
130 var file = new File("${temp.path}/nonExistentDirectory/newFile"); 118 var file = new File("${temp.path}/nonExistentDirectory/newFile");
131 119
132 // Create in non-existent directory should throw exception. 120 // Create in non-existent directory should throw exception.
133 Expect.throws(() => file.createSync(), 121 Expect.throws(() => file.createSync(),
134 (e) => checkCreateInNonExistentDirectoryException(e)); 122 (e) => checkCreateInNonExistentDirectoryException(e));
135 123
136 var create = file.create(); 124 var create = file.create();
137 create.then((ignore) => Expect.fail("Unreachable code")) 125 create.then((ignore) => Expect.fail("Unreachable code"))
138 .catchError((error) { 126 .catchError((error) {
139 checkCreateInNonExistentDirectoryException(error); 127 checkCreateInNonExistentDirectoryException(error);
140 p.toSendPort().send(null); 128 temp.deleteSync(recursive: true);
129 asyncEnd();
141 }); 130 });
142 } 131 }
143 132
144 bool checkFullPathOnNonExistentDirectoryException(e) { 133 bool checkFullPathOnNonExistentDirectoryException(e) {
145 Expect.isTrue(e is FileException); 134 Expect.isTrue(e is FileException);
146 Expect.isTrue(e.osError != null); 135 Expect.isTrue(e.osError != null);
147 Expect.isTrue(e.toString().indexOf("Cannot retrieve full path") != -1); 136 Expect.isTrue(e.toString().indexOf("Cannot retrieve full path") != -1);
148 // File not not found has error code 2 on all supported platforms. 137 // File not not found has error code 2 on all supported platforms.
149 Expect.equals(2, e.osError.errorCode); 138 Expect.equals(2, e.osError.errorCode);
150 139
151 return true; 140 return true;
152 } 141 }
153 142
154 void testFullPathOnNonExistentDirectory() { 143 void testFullPathOnNonExistentDirectory() {
144 asyncStart();
155 Directory temp = tempDir(); 145 Directory temp = tempDir();
156 ReceivePort p = new ReceivePort();
157 p.receive((x, y) {
158 p.close();
159 temp.deleteSync(recursive: true);
160 });
161 var file = new File("${temp.path}/nonExistentDirectory"); 146 var file = new File("${temp.path}/nonExistentDirectory");
162 147
163 // Full path non-existent directory should throw exception. 148 // Full path non-existent directory should throw exception.
164 Expect.throws(() => file.fullPathSync(), 149 Expect.throws(() => file.fullPathSync(),
165 (e) => checkFullPathOnNonExistentDirectoryException(e)); 150 (e) => checkFullPathOnNonExistentDirectoryException(e));
166 151
167 var fullPathFuture = file.fullPath(); 152 var fullPathFuture = file.fullPath();
168 fullPathFuture.then((path) => Expect.fail("Unreachable code $path")) 153 fullPathFuture.then((path) => Expect.fail("Unreachable code $path"))
169 .catchError((error) { 154 .catchError((error) {
170 checkFullPathOnNonExistentDirectoryException(error); 155 checkFullPathOnNonExistentDirectoryException(error);
171 p.toSendPort().send(null); 156 temp.deleteSync(recursive: true);
157 asyncEnd();
172 }); 158 });
173 } 159 }
174 160
175 void testReadAsBytesNonExistent() { 161 void testReadAsBytesNonExistent() {
162 asyncStart();
176 Directory temp = tempDir(); 163 Directory temp = tempDir();
177 ReceivePort p = new ReceivePort();
178 p.receive((x, y) {
179 p.close();
180 temp.deleteSync(recursive: true);
181 });
182 var file = new File("${temp.path}/nonExistentFile3"); 164 var file = new File("${temp.path}/nonExistentFile3");
183 165
184 // Non-existing file should throw exception. 166 // Non-existing file should throw exception.
185 Expect.throws(() => file.readAsBytesSync(), 167 Expect.throws(() => file.readAsBytesSync(),
186 (e) => checkOpenNonExistentFileException(e)); 168 (e) => checkOpenNonExistentFileException(e));
187 169
188 var readAsBytesFuture = file.readAsBytes(); 170 var readAsBytesFuture = file.readAsBytes();
189 readAsBytesFuture.then((data) => Expect.fail("Unreachable code")) 171 readAsBytesFuture.then((data) => Expect.fail("Unreachable code"))
190 .catchError((error) { 172 .catchError((error) {
191 checkOpenNonExistentFileException(error); 173 checkOpenNonExistentFileException(error);
192 p.toSendPort().send(null); 174 temp.deleteSync(recursive: true);
175 asyncEnd();
193 }); 176 });
194 } 177 }
195 178
196 void testReadAsTextNonExistent() { 179 void testReadAsTextNonExistent() {
180 asyncStart();
197 Directory temp = tempDir(); 181 Directory temp = tempDir();
198 ReceivePort p = new ReceivePort();
199 p.receive((x, y) {
200 p.close();
201 temp.deleteSync(recursive: true);
202 });
203 var file = new File("${temp.path}/nonExistentFile4"); 182 var file = new File("${temp.path}/nonExistentFile4");
204 183
205 // Non-existing file should throw exception. 184 // Non-existing file should throw exception.
206 Expect.throws(() => file.readAsStringSync(), 185 Expect.throws(() => file.readAsStringSync(),
207 (e) => checkOpenNonExistentFileException(e)); 186 (e) => checkOpenNonExistentFileException(e));
208 187
209 var readAsStringFuture = file.readAsString(encoding: ASCII); 188 var readAsStringFuture = file.readAsString(encoding: ASCII);
210 readAsStringFuture.then((data) => Expect.fail("Unreachable code")) 189 readAsStringFuture.then((data) => Expect.fail("Unreachable code"))
211 .catchError((error) { 190 .catchError((error) {
212 checkOpenNonExistentFileException(error); 191 checkOpenNonExistentFileException(error);
213 p.toSendPort().send(null); 192 temp.deleteSync(recursive: true);
193 asyncEnd();
214 }); 194 });
215 } 195 }
216 196
217 testReadAsLinesNonExistent() { 197 testReadAsLinesNonExistent() {
198 asyncStart();
218 Directory temp = tempDir(); 199 Directory temp = tempDir();
219 ReceivePort p = new ReceivePort();
220 p.receive((x, y) {
221 p.close();
222 temp.deleteSync(recursive: true);
223 });
224 var file = new File("${temp.path}/nonExistentFile5"); 200 var file = new File("${temp.path}/nonExistentFile5");
225 201
226 // Non-existing file should throw exception. 202 // Non-existing file should throw exception.
227 Expect.throws(() => file.readAsLinesSync(), 203 Expect.throws(() => file.readAsLinesSync(),
228 (e) => checkOpenNonExistentFileException(e)); 204 (e) => checkOpenNonExistentFileException(e));
229 205
230 var readAsLinesFuture = file.readAsLines(encoding: ASCII); 206 var readAsLinesFuture = file.readAsLines(encoding: ASCII);
231 readAsLinesFuture.then((data) => Expect.fail("Unreachable code")) 207 readAsLinesFuture.then((data) => Expect.fail("Unreachable code"))
232 .catchError((error) { 208 .catchError((error) {
233 checkOpenNonExistentFileException(error); 209 checkOpenNonExistentFileException(error);
234 p.toSendPort().send(null); 210 temp.deleteSync(recursive: true);
211 asyncEnd();
235 }); 212 });
236 } 213 }
237 214
238 bool checkWriteReadOnlyFileException(e) { 215 bool checkWriteReadOnlyFileException(e) {
239 Expect.isTrue(e is FileException); 216 Expect.isTrue(e is FileException);
240 Expect.isTrue(e.osError != null); 217 Expect.isTrue(e.osError != null);
241 Expect.isTrue(e.osError.errorCode != OSError.noErrorCode); 218 Expect.isTrue(e.osError.errorCode != OSError.noErrorCode);
242 return true; 219 return true;
243 } 220 }
244 221
245 222
246 // Create a test file in a temporary directory. Setup a port to signal 223 // Create a test file in a temporary directory. Setup a port to signal
247 // when the temporary directory should be deleted. Pass the file and 224 // when the temporary directory should be deleted. Pass the file and
248 // the port to the callback argument. 225 // the port to the callback argument.
249 createTestFile(callback) { 226 createTestFile(callback) {
227 asyncStart();
250 Directory temp = tempDir(); 228 Directory temp = tempDir();
251 ReceivePort p = new ReceivePort();
252 p.receive((x, y) {
253 p.close();
254 temp.deleteSync(recursive: true);
255 });
256
257 var file = new File("${temp.path}/test_file"); 229 var file = new File("${temp.path}/test_file");
258 file.createSync(); 230 file.createSync();
259 callback(file, p.toSendPort()); 231 callback(file, () {
232 temp.deleteSync(recursive: true);
233 asyncEnd();
234 });
260 } 235 }
261 236
262 237
263 testWriteByteToReadOnlyFile() { 238 testWriteByteToReadOnlyFile() {
264 createTestFile((file, port) { 239 createTestFile((file, done) {
265 var openedFile = file.openSync(mode: FileMode.READ); 240 var openedFile = file.openSync(mode: FileMode.READ);
266 241
267 // Writing to read only file should throw an exception. 242 // Writing to read only file should throw an exception.
268 Expect.throws(() => openedFile.writeByteSync(0), 243 Expect.throws(() => openedFile.writeByteSync(0),
269 (e) => checkWriteReadOnlyFileException(e)); 244 (e) => checkWriteReadOnlyFileException(e));
270 245
271 var writeByteFuture = openedFile.writeByte(0); 246 var writeByteFuture = openedFile.writeByte(0);
272 writeByteFuture.catchError((error) { 247 writeByteFuture.catchError((error) {
273 checkWriteReadOnlyFileException(error); 248 checkWriteReadOnlyFileException(error);
274 openedFile.close().then((ignore) => port.send(null)); 249 openedFile.close().then((_) => done());
275 }); 250 });
276 }); 251 });
277 } 252 }
278 253
279 testWriteFromToReadOnlyFile() { 254 testWriteFromToReadOnlyFile() {
280 createTestFile((file, port) { 255 createTestFile((file, done) {
281 var openedFile = file.openSync(mode: FileMode.READ); 256 var openedFile = file.openSync(mode: FileMode.READ);
282 257
283 List data = [0, 1, 2, 3]; 258 List data = [0, 1, 2, 3];
284 // Writing to read only file should throw an exception. 259 // Writing to read only file should throw an exception.
285 Expect.throws(() => openedFile.writeFromSync(data, 0, data.length), 260 Expect.throws(() => openedFile.writeFromSync(data, 0, data.length),
286 (e) => checkWriteReadOnlyFileException(e)); 261 (e) => checkWriteReadOnlyFileException(e));
287 262
288 var writeFromFuture = openedFile.writeFrom(data, 0, data.length); 263 var writeFromFuture = openedFile.writeFrom(data, 0, data.length);
289 writeFromFuture.catchError((error) { 264 writeFromFuture.catchError((error) {
290 checkWriteReadOnlyFileException(error); 265 checkWriteReadOnlyFileException(error);
291 openedFile.close().then((ignore) => port.send(null)); 266 openedFile.close().then((_) => done());
292 }); 267 });
293 }); 268 });
294 } 269 }
295 270
296 testTruncateReadOnlyFile() { 271 testTruncateReadOnlyFile() {
297 createTestFile((file, port) { 272 createTestFile((file, done) {
298 var openedFile = file.openSync(mode: FileMode.WRITE); 273 var openedFile = file.openSync(mode: FileMode.WRITE);
299 openedFile.writeByteSync(0); 274 openedFile.writeByteSync(0);
300 openedFile.closeSync(); 275 openedFile.closeSync();
301 openedFile = file.openSync(mode: FileMode.READ); 276 openedFile = file.openSync(mode: FileMode.READ);
302 277
303 // Truncating read only file should throw an exception. 278 // Truncating read only file should throw an exception.
304 Expect.throws(() => openedFile.truncateSync(0), 279 Expect.throws(() => openedFile.truncateSync(0),
305 (e) => checkWriteReadOnlyFileException(e)); 280 (e) => checkWriteReadOnlyFileException(e));
306 281
307 var truncateFuture = openedFile.truncate(0); 282 var truncateFuture = openedFile.truncate(0);
308 truncateFuture.then((ignore) => Expect.fail("Unreachable code")) 283 truncateFuture.then((ignore) => Expect.fail("Unreachable code"))
309 .catchError((error) { 284 .catchError((error) {
310 checkWriteReadOnlyFileException(error); 285 checkWriteReadOnlyFileException(error);
311 openedFile.close().then((ignore) => port.send(null)); 286 openedFile.close().then((_) => done());
312 }); 287 });
313 }); 288 });
314 } 289 }
315 290
316 bool checkFileClosedException(e) { 291 bool checkFileClosedException(e) {
317 Expect.isTrue(e is FileException); 292 Expect.isTrue(e is FileException);
318 Expect.isTrue(e.toString().indexOf("File closed") != -1); 293 Expect.isTrue(e.toString().indexOf("File closed") != -1);
319 Expect.isTrue(e.osError == null); 294 Expect.isTrue(e.osError == null);
320 return true; 295 return true;
321 } 296 }
322 297
323 testOperateOnClosedFile() { 298 testOperateOnClosedFile() {
324 createTestFile((file, port) { 299 createTestFile((file, done) {
325 var openedFile = file.openSync(mode: FileMode.READ); 300 var openedFile = file.openSync(mode: FileMode.READ);
326 openedFile.closeSync(); 301 openedFile.closeSync();
327 302
328 List data = [0, 1, 2, 3]; 303 List data = [0, 1, 2, 3];
329 Expect.throws(() => openedFile.readByteSync(), 304 Expect.throws(() => openedFile.readByteSync(),
330 (e) => checkFileClosedException(e)); 305 (e) => checkFileClosedException(e));
331 Expect.throws(() => openedFile.writeByteSync(0), 306 Expect.throws(() => openedFile.writeByteSync(0),
332 (e) => checkFileClosedException(e)); 307 (e) => checkFileClosedException(e));
333 Expect.throws(() => openedFile.writeFromSync(data, 0, data.length), 308 Expect.throws(() => openedFile.writeFromSync(data, 0, data.length),
334 (e) => checkFileClosedException(e)); 309 (e) => checkFileClosedException(e));
(...skipping 10 matching lines...) Expand all
345 Expect.throws(() => openedFile.lengthSync(), 320 Expect.throws(() => openedFile.lengthSync(),
346 (e) => checkFileClosedException(e)); 321 (e) => checkFileClosedException(e));
347 Expect.throws(() => openedFile.flushSync(), 322 Expect.throws(() => openedFile.flushSync(),
348 (e) => checkFileClosedException(e)); 323 (e) => checkFileClosedException(e));
349 324
350 var errorCount = 0; 325 var errorCount = 0;
351 326
352 _errorHandler(error) { 327 _errorHandler(error) {
353 checkFileClosedException(error); 328 checkFileClosedException(error);
354 if (--errorCount == 0) { 329 if (--errorCount == 0) {
355 port.send(null); 330 done();
356 } 331 }
357 } 332 }
358 333
359 var readByteFuture = openedFile.readByte(); 334 var readByteFuture = openedFile.readByte();
360 readByteFuture.then((byte) => Expect.fail("Unreachable code")) 335 readByteFuture.then((byte) => Expect.fail("Unreachable code"))
361 .catchError(_errorHandler); 336 .catchError(_errorHandler);
362 errorCount++; 337 errorCount++;
363 var writeByteFuture = openedFile.writeByte(0); 338 var writeByteFuture = openedFile.writeByte(0);
364 writeByteFuture.then((ignore) => Expect.fail("Unreachable code")) 339 writeByteFuture.then((ignore) => Expect.fail("Unreachable code"))
365 .catchError(_errorHandler); 340 .catchError(_errorHandler);
(...skipping 27 matching lines...) Expand all
393 .catchError(_errorHandler); 368 .catchError(_errorHandler);
394 errorCount++; 369 errorCount++;
395 var flushFuture = openedFile.flush(); 370 var flushFuture = openedFile.flush();
396 flushFuture.then((ignore) => Expect.fail("Unreachable code")) 371 flushFuture.then((ignore) => Expect.fail("Unreachable code"))
397 .catchError(_errorHandler); 372 .catchError(_errorHandler);
398 errorCount++; 373 errorCount++;
399 }); 374 });
400 } 375 }
401 376
402 testRepeatedlyCloseFile() { 377 testRepeatedlyCloseFile() {
403 createTestFile((file, port) { 378 createTestFile((file, done) {
404 var openedFile = file.openSync(); 379 var openedFile = file.openSync();
405 openedFile.close().then((ignore) { 380 openedFile.close().then((ignore) {
406 var closeFuture = openedFile.close(); 381 var closeFuture = openedFile.close();
407 closeFuture.then((ignore) => null) 382 closeFuture.then((ignore) => null)
408 .catchError((error) { 383 .catchError((error) {
409 Expect.isTrue(error is FileException); 384 Expect.isTrue(error is FileException);
410 port.send(null); 385 done();
411 }); 386 });
412 }); 387 });
413 }); 388 });
414 } 389 }
415 390
416 testRepeatedlyCloseFileSync() { 391 testRepeatedlyCloseFileSync() {
417 createTestFile((file, port) { 392 createTestFile((file, done) {
418 var openedFile = file.openSync(); 393 var openedFile = file.openSync();
419 openedFile.closeSync(); 394 openedFile.closeSync();
420 Expect.throws(openedFile.closeSync, 395 Expect.throws(openedFile.closeSync,
421 (e) => e is FileException); 396 (e) => e is FileException);
422 port.send(null); 397 done();
423 }); 398 });
424 } 399 }
425 400
426 testReadSyncBigInt() { 401 testReadSyncBigInt() {
427 createTestFile((file, port) { 402 createTestFile((file, done) {
428 var bigint = 100000000000000000000000000000000000000000; 403 var bigint = 100000000000000000000000000000000000000000;
429 var openedFile = file.openSync(); 404 var openedFile = file.openSync();
430 Expect.throws(() => openedFile.readSync(bigint), 405 Expect.throws(() => openedFile.readSync(bigint),
431 (e) => e is FileException); 406 (e) => e is FileException);
432 openedFile.closeSync(); 407 openedFile.closeSync();
433 port.send(null); 408 done();
434 }); 409 });
435 } 410 }
436 411
437 testReadSyncClosedFile() { 412 testReadSyncClosedFile() {
438 createTestFile((file, port) { 413 createTestFile((file, done) {
439 var openedFile = file.openSync(); 414 var openedFile = file.openSync();
440 openedFile.closeSync(); 415 openedFile.closeSync();
441 Expect.throws(() => openedFile.readSync(1), 416 Expect.throws(() => openedFile.readSync(1),
442 (e) => e is FileException); 417 (e) => e is FileException);
443 port.send(null); 418 done();
444 }); 419 });
445 } 420 }
446 421
447 main() { 422 main() {
448 testOpenNonExistent(); 423 testOpenNonExistent();
449 testDeleteNonExistent(); 424 testDeleteNonExistent();
450 testLengthNonExistent(); 425 testLengthNonExistent();
451 testCreateInNonExistentDirectory(); 426 testCreateInNonExistentDirectory();
452 testFullPathOnNonExistentDirectory(); 427 testFullPathOnNonExistentDirectory();
453 testReadAsBytesNonExistent(); 428 testReadAsBytesNonExistent();
454 testReadAsTextNonExistent(); 429 testReadAsTextNonExistent();
455 testReadAsLinesNonExistent(); 430 testReadAsLinesNonExistent();
456 testWriteByteToReadOnlyFile(); 431 testWriteByteToReadOnlyFile();
457 testWriteFromToReadOnlyFile(); 432 testWriteFromToReadOnlyFile();
458 testTruncateReadOnlyFile(); 433 testTruncateReadOnlyFile();
459 testOperateOnClosedFile(); 434 testOperateOnClosedFile();
460 testRepeatedlyCloseFile(); 435 testRepeatedlyCloseFile();
461 testRepeatedlyCloseFileSync(); 436 testRepeatedlyCloseFileSync();
462 testReadSyncBigInt(); 437 testReadSyncBigInt();
463 testReadSyncClosedFile(); 438 testReadSyncClosedFile();
464 } 439 }
OLDNEW
« no previous file with comments | « tests/standalone/io/directory_test.dart ('k') | tests/standalone/io/file_fuzz_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698