| Index: tests/standalone/io/file_error_test.dart
|
| diff --git a/tests/standalone/io/file_error_test.dart b/tests/standalone/io/file_error_test.dart
|
| index 6aef13af9f7691a865fb769ae31775e01c5c42b5..57ffce261c46cbcddc09401b4d54fd498446d42f 100644
|
| --- a/tests/standalone/io/file_error_test.dart
|
| +++ b/tests/standalone/io/file_error_test.dart
|
| @@ -8,9 +8,7 @@
|
| #import("dart:isolate");
|
|
|
| Directory tempDir() {
|
| - var d = new Directory('');
|
| - d.createTempSync();
|
| - return d;
|
| + return new Directory('').createTempSync();
|
| }
|
|
|
|
|
| @@ -62,11 +60,13 @@ void testOpenNonExistent() {
|
| Expect.throws(() => file.openSync(),
|
| (e) => checkOpenNonExistentFileException(e));
|
|
|
| - file.open(FileMode.READ, (raf) => Expect.fail("Unreachable code"));
|
| - file.onError = (e) {
|
| + var openFuture = file.open(FileMode.READ);
|
| + openFuture.then((raf) => Expect.fail("Unreachable code"));
|
| + openFuture.handleException((e) {
|
| checkOpenNonExistentFileException(e);
|
| p.toSendPort().send(null);
|
| - };
|
| + return true;
|
| + });
|
| }
|
|
|
|
|
| @@ -83,11 +83,13 @@ void testDeleteNonExistent() {
|
| Expect.throws(() => file.deleteSync(),
|
| (e) => checkDeleteNonExistentFileException(e));
|
|
|
| - file.delete(() => Expect.fail("Unreachable code"));
|
| - file.onError = (e) {
|
| + var delete = file.delete();
|
| + delete.then((ignore) => Expect.fail("Unreachable code"));
|
| + delete.handleException((e) {
|
| checkDeleteNonExistentFileException(e);
|
| p.toSendPort().send(null);
|
| - };
|
| + return true;
|
| + });
|
| }
|
|
|
|
|
| @@ -104,11 +106,13 @@ void testLengthNonExistent() {
|
| Expect.throws(() => file.lengthSync(),
|
| (e) => checkLengthNonExistentFileException(e));
|
|
|
| - file.length((len) => Expect.fail("Unreachable code"));
|
| - file.onError = (e) {
|
| + var lenFuture = file.length();
|
| + lenFuture.then((len) => Expect.fail("Unreachable code"));
|
| + lenFuture.handleException((e) {
|
| checkLengthNonExistentFileException(e);
|
| p.toSendPort().send(null);
|
| - };
|
| + return true;
|
| + });
|
| }
|
|
|
|
|
| @@ -145,11 +149,13 @@ void testCreateInNonExistentDirectory() {
|
| Expect.throws(() => file.createSync(),
|
| (e) => checkCreateInNonExistentDirectoryException(e));
|
|
|
| - file.create(() => Expect.fail("Unreachable code"));
|
| - file.onError = (e) {
|
| + var create = file.create();
|
| + create.then((ignore) => Expect.fail("Unreachable code"));
|
| + create.handleException((e) {
|
| checkCreateInNonExistentDirectoryException(e);
|
| p.toSendPort().send(null);
|
| - };
|
| + return true;
|
| + });
|
| }
|
|
|
| bool checkFullPathOnNonExistentDirectoryException(e) {
|
| @@ -184,11 +190,13 @@ void testFullPathOnNonExistentDirectory() {
|
| Expect.throws(() => file.fullPathSync(),
|
| (e) => checkFullPathOnNonExistentDirectoryException(e));
|
|
|
| - file.fullPath((path) => Expect.fail("Unreachable code $path"));
|
| - file.onError = (e) {
|
| + var fullPathFuture = file.fullPath();
|
| + fullPathFuture.then((path) => Expect.fail("Unreachable code $path"));
|
| + fullPathFuture.handleException((e) {
|
| checkFullPathOnNonExistentDirectoryException(e);
|
| p.toSendPort().send(null);
|
| - };
|
| + return true;
|
| + });
|
| }
|
|
|
| bool checkDirectoryInNonExistentDirectoryException(e) {
|
| @@ -224,11 +232,13 @@ void testDirectoryInNonExistentDirectory() {
|
| Expect.throws(() => file.directorySync(),
|
| (e) => checkDirectoryInNonExistentDirectoryException(e));
|
|
|
| - file.directory((directory) => Expect.fail("Unreachable code"));
|
| - file.onError = (e) {
|
| + var dirFuture = file.directory();
|
| + dirFuture.then((directory) => Expect.fail("Unreachable code"));
|
| + dirFuture.handleException((e) {
|
| checkDirectoryInNonExistentDirectoryException(e);
|
| p.toSendPort().send(null);
|
| - };
|
| + return true;
|
| + });
|
| }
|
|
|
| void testReadAsBytesNonExistent() {
|
| @@ -244,11 +254,13 @@ void testReadAsBytesNonExistent() {
|
| Expect.throws(() => file.readAsBytesSync(),
|
| (e) => checkOpenNonExistentFileException(e));
|
|
|
| - file.readAsBytes((data) => Expect.fail("Unreachable code"));
|
| - file.onError = (e) {
|
| + var readAsBytesFuture = file.readAsBytes();
|
| + readAsBytesFuture.then((data) => Expect.fail("Unreachable code"));
|
| + readAsBytesFuture.handleException((e) {
|
| checkOpenNonExistentFileException(e);
|
| p.toSendPort().send(null);
|
| - };
|
| + return true;
|
| + });
|
| }
|
|
|
| void testReadAsTextNonExistent() {
|
| @@ -264,11 +276,13 @@ void testReadAsTextNonExistent() {
|
| Expect.throws(() => file.readAsTextSync(),
|
| (e) => checkOpenNonExistentFileException(e));
|
|
|
| - file.readAsText(Encoding.ASCII, (data) => Expect.fail("Unreachable code"));
|
| - file.onError = (e) {
|
| + var readAsTextFuture = file.readAsText(Encoding.ASCII);
|
| + readAsTextFuture.then((data) => Expect.fail("Unreachable code"));
|
| + readAsTextFuture.handleException((e) {
|
| checkOpenNonExistentFileException(e);
|
| p.toSendPort().send(null);
|
| - };
|
| + return true;
|
| + });
|
| }
|
|
|
| testReadAsLinesNonExistent() {
|
| @@ -284,11 +298,13 @@ testReadAsLinesNonExistent() {
|
| Expect.throws(() => file.readAsLinesSync(),
|
| (e) => checkOpenNonExistentFileException(e));
|
|
|
| - file.readAsLines(Encoding.ASCII, (data) => Expect.fail("Unreachable code"));
|
| - file.onError = (e) {
|
| + var readAsLinesFuture = file.readAsLines(Encoding.ASCII);
|
| + readAsLinesFuture.then((data) => Expect.fail("Unreachable code"));
|
| + readAsLinesFuture.handleException((e) {
|
| checkOpenNonExistentFileException(e);
|
| p.toSendPort().send(null);
|
| - };
|
| + return true;
|
| + });
|
| }
|
|
|
| bool checkWriteReadOnlyFileException(e) {
|
| @@ -318,17 +334,18 @@ createTestFile(callback) {
|
|
|
| testWriteByteToReadOnlyFile() {
|
| createTestFile((file, port) {
|
| - var openedFile = file.openSync(FileMode.READ);
|
| + var openedFile = file.openSync(FileMode.READ);
|
|
|
| - // Writing to read only file should throw an exception.
|
| - Expect.throws(() => openedFile.writeByteSync(0),
|
| - (e) => checkWriteReadOnlyFileException(e));
|
| + // Writing to read only file should throw an exception.
|
| + Expect.throws(() => openedFile.writeByteSync(0),
|
| + (e) => checkWriteReadOnlyFileException(e));
|
|
|
| - openedFile.writeByte(0);
|
| - openedFile.onError = (e) {
|
| - checkWriteReadOnlyFileException(e);
|
| - openedFile.close(() => port.send(null));
|
| - };
|
| + var writeByteFuture = openedFile.writeByte(0);
|
| + writeByteFuture.handleException((e) {
|
| + checkWriteReadOnlyFileException(e);
|
| + openedFile.close().then((ignore) => port.send(null));
|
| + return true;
|
| + });
|
| });
|
| }
|
|
|
| @@ -341,11 +358,12 @@ testWriteListToReadOnlyFile() {
|
| Expect.throws(() => openedFile.writeListSync(data, 0, data.length),
|
| (e) => checkWriteReadOnlyFileException(e));
|
|
|
| - openedFile.writeList(data, 0, data.length);
|
| - openedFile.onError = (e) {
|
| + var writeListFuture = openedFile.writeList(data, 0, data.length);
|
| + writeListFuture.handleException((e) {
|
| checkWriteReadOnlyFileException(e);
|
| - openedFile.close(() => port.send(null));
|
| - };
|
| + openedFile.close().then((ignore) => port.send(null));
|
| + return true;
|
| + });
|
| });
|
| }
|
|
|
| @@ -360,11 +378,13 @@ testTruncateReadOnlyFile() {
|
| Expect.throws(() => openedFile.truncateSync(0),
|
| (e) => checkWriteReadOnlyFileException(e));
|
|
|
| - openedFile.truncate(0, () => Expect.fail("Unreachable code"));
|
| - openedFile.onError = (e) {
|
| + var truncateFuture = openedFile.truncate(0);
|
| + truncateFuture.then((ignore) => Expect.fail("Unreachable code"));
|
| + truncateFuture.handleException((e) {
|
| checkWriteReadOnlyFileException(e);
|
| - openedFile.close(() => port.send(null));
|
| - };
|
| + openedFile.close().then((ignore) => port.send(null));
|
| + return true;
|
| + });
|
| });
|
| }
|
|
|
| @@ -403,46 +423,69 @@ testOperateOnClosedFile() {
|
| (e) => checkFileClosedException(e));
|
|
|
| var errorCount = 0;
|
| - openedFile.readByte((byte) => Expect.fail("Unreachable code"));
|
| +
|
| + _errorHandler(e) {
|
| + checkFileClosedException(e);
|
| + if (--errorCount == 0) {
|
| + port.send(null);
|
| + }
|
| + return true;
|
| + }
|
| +
|
| + var readByteFuture = openedFile.readByte();
|
| + readByteFuture.then((byte) => Expect.fail("Unreachable code"));
|
| + readByteFuture.handleException(_errorHandler);
|
| errorCount++;
|
| - openedFile.writeByte(0);
|
| + var writeByteFuture = openedFile.writeByte(0);
|
| + writeByteFuture.then((ignore) => Expect.fail("Unreachable code"));
|
| + writeByteFuture.handleException(_errorHandler);
|
| errorCount++;
|
| - openedFile.readList(
|
| - data, 0, data.length, (bytesRead) => Expect.fail("Unreachable code"));
|
| + var readListFuture = openedFile.readList(data, 0, data.length);
|
| + readListFuture.then((bytesRead) => Expect.fail("Unreachable code"));
|
| + readListFuture.handleException(_errorHandler);
|
| errorCount++;
|
| - openedFile.writeList(data, 0, data.length);
|
| + var writeListFuture = openedFile.writeList(data, 0, data.length);
|
| + writeListFuture.then((ignore) => Expect.fail("Unreachable code"));
|
| + writeListFuture.handleException(_errorHandler);
|
| errorCount++;
|
| - openedFile.writeString("Hello");
|
| + var writeStringFuture = openedFile.writeString("Hello");
|
| + writeStringFuture.then((ignore) => Expect.fail("Unreachable code"));
|
| + writeStringFuture.handleException(_errorHandler);
|
| errorCount++;
|
| - openedFile.position((position) => Expect.fail("Unreachable code"));
|
| + var positionFuture = openedFile.position();
|
| + positionFuture.then((position) => Expect.fail("Unreachable code"));
|
| + positionFuture.handleException(_errorHandler);
|
| errorCount++;
|
| - openedFile.setPosition(0, () => Expect.fail("Unreachable code"));
|
| + var setPositionFuture = openedFile.setPosition(0);
|
| + setPositionFuture.then((ignore) => Expect.fail("Unreachable code"));
|
| + setPositionFuture.handleException(_errorHandler);
|
| errorCount++;
|
| - openedFile.truncate(0, () => Expect.fail("Unreachable code"));
|
| + var truncateFuture = openedFile.truncate(0);
|
| + truncateFuture.then((ignore) => Expect.fail("Unreachable code"));
|
| + truncateFuture.handleException(_errorHandler);
|
| errorCount++;
|
| - openedFile.length((length) => Expect.fail("Unreachable code"));
|
| + var lenFuture = openedFile.length();
|
| + lenFuture.then((length) => Expect.fail("Unreachable code"));
|
| + lenFuture.handleException(_errorHandler);
|
| errorCount++;
|
| - openedFile.flush(() => Expect.fail("Unreachable code"));
|
| + var flushFuture = openedFile.flush();
|
| + flushFuture.then((ignore) => Expect.fail("Unreachable code"));
|
| + flushFuture.handleException(_errorHandler);
|
| errorCount++;
|
| -
|
| - openedFile.onError = (e) {
|
| - checkFileClosedException(e);
|
| - if (--errorCount == 0) {
|
| - port.send(null);
|
| - }
|
| - };
|
| });
|
| }
|
|
|
| testRepeatedlyCloseFile() {
|
| createTestFile((file, port) {
|
| var openedFile = file.openSync();
|
| - openedFile.close(() {
|
| - openedFile.onError = (e) {
|
| + openedFile.close().then((ignore) {
|
| + var closeFuture = openedFile.close();
|
| + closeFuture.handleException((e) {
|
| Expect.isTrue(e is FileIOException);
|
| port.send(null);
|
| - };
|
| - openedFile.close(() => null);
|
| + return true;
|
| + });
|
| + closeFuture.then((ignore) => null);
|
| });
|
| });
|
| }
|
|
|