| 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 713ac581c74ec36cbd0373279e1fd9b96d0d9498..84ba44c27059b36b4a216914e9a86db1ba5d14a6 100644
|
| --- a/tests/standalone/io/file_error_test.dart
|
| +++ b/tests/standalone/io/file_error_test.dart
|
| @@ -14,7 +14,6 @@ Directory tempDir() {
|
| return Directory.systemTemp.createTempSync('dart_file_error');
|
| }
|
|
|
| -
|
| bool checkNonExistentFileSystemException(e, str) {
|
| Expect.isTrue(e is FileSystemException);
|
| Expect.isTrue(e.osError != null);
|
| @@ -24,41 +23,36 @@ bool checkNonExistentFileSystemException(e, str) {
|
| return true;
|
| }
|
|
|
| -
|
| bool checkOpenNonExistentFileSystemException(e) {
|
| return checkNonExistentFileSystemException(e, "Cannot open file");
|
| }
|
|
|
| -
|
| bool checkDeleteNonExistentFileSystemException(e) {
|
| return checkNonExistentFileSystemException(e, "Cannot delete file");
|
| }
|
|
|
| -
|
| bool checkLengthNonExistentFileSystemException(e) {
|
| - return checkNonExistentFileSystemException(e, "Cannot retrieve length of file");
|
| + return checkNonExistentFileSystemException(
|
| + e, "Cannot retrieve length of file");
|
| }
|
|
|
| -
|
| void testOpenNonExistent() {
|
| asyncStart();
|
| Directory temp = tempDir();
|
| var file = new File("${temp.path}/nonExistentFile");
|
|
|
| // Non-existing file should throw exception.
|
| - Expect.throws(() => file.openSync(),
|
| - (e) => checkOpenNonExistentFileSystemException(e));
|
| + Expect.throws(
|
| + () => file.openSync(), (e) => checkOpenNonExistentFileSystemException(e));
|
|
|
| var openFuture = file.open(mode: FileMode.READ);
|
| - openFuture.then((raf) => Expect.fail("Unreachable code"))
|
| - .catchError((error) {
|
| - checkOpenNonExistentFileSystemException(error);
|
| - temp.deleteSync(recursive: true);
|
| - asyncEnd();
|
| - });
|
| + openFuture.then((raf) => Expect.fail("Unreachable code")).catchError((error) {
|
| + checkOpenNonExistentFileSystemException(error);
|
| + temp.deleteSync(recursive: true);
|
| + asyncEnd();
|
| + });
|
| }
|
|
|
| -
|
| void testDeleteNonExistent() {
|
| asyncStart();
|
| Directory temp = tempDir();
|
| @@ -66,18 +60,16 @@ void testDeleteNonExistent() {
|
|
|
| // Non-existing file should throw exception.
|
| Expect.throws(() => file.deleteSync(),
|
| - (e) => checkDeleteNonExistentFileSystemException(e));
|
| + (e) => checkDeleteNonExistentFileSystemException(e));
|
|
|
| var delete = file.delete();
|
| - delete.then((ignore) => Expect.fail("Unreachable code"))
|
| - .catchError((error) {
|
| - checkDeleteNonExistentFileSystemException(error);
|
| - temp.deleteSync(recursive: true);
|
| - asyncEnd();
|
| - });
|
| + delete.then((ignore) => Expect.fail("Unreachable code")).catchError((error) {
|
| + checkDeleteNonExistentFileSystemException(error);
|
| + temp.deleteSync(recursive: true);
|
| + asyncEnd();
|
| + });
|
| }
|
|
|
| -
|
| void testLengthNonExistent() {
|
| asyncStart();
|
| Directory temp = tempDir();
|
| @@ -85,18 +77,16 @@ void testLengthNonExistent() {
|
|
|
| // Non-existing file should throw exception.
|
| Expect.throws(() => file.lengthSync(),
|
| - (e) => checkLengthNonExistentFileSystemException(e));
|
| + (e) => checkLengthNonExistentFileSystemException(e));
|
|
|
| var lenFuture = file.length();
|
| - lenFuture.then((len) => Expect.fail("Unreachable code"))
|
| - .catchError((error) {
|
| - checkLengthNonExistentFileSystemException(error);
|
| - temp.deleteSync(recursive: true);
|
| - asyncEnd();
|
| - });
|
| + lenFuture.then((len) => Expect.fail("Unreachable code")).catchError((error) {
|
| + checkLengthNonExistentFileSystemException(error);
|
| + temp.deleteSync(recursive: true);
|
| + asyncEnd();
|
| + });
|
| }
|
|
|
| -
|
| bool checkCreateInNonExistentFileSystemException(e) {
|
| Expect.isTrue(e is FileSystemException);
|
| Expect.isTrue(e.osError != null);
|
| @@ -119,11 +109,10 @@ void testCreateInNonExistentDirectory() {
|
|
|
| // Create in non-existent directory should throw exception.
|
| Expect.throws(() => file.createSync(),
|
| - (e) => checkCreateInNonExistentFileSystemException(e));
|
| + (e) => checkCreateInNonExistentFileSystemException(e));
|
|
|
| var create = file.create();
|
| - create.then((ignore) => Expect.fail("Unreachable code"))
|
| - .catchError((error) {
|
| + create.then((ignore) => Expect.fail("Unreachable code")).catchError((error) {
|
| checkCreateInNonExistentFileSystemException(error);
|
| temp.deleteSync(recursive: true);
|
| asyncEnd();
|
| @@ -150,8 +139,9 @@ void testResolveSymbolicLinksOnNonExistentDirectory() {
|
| (e) => checkResolveSymbolicLinksOnNonExistentFileSystemException(e));
|
|
|
| var resolvedFuture = file.resolveSymbolicLinks();
|
| - resolvedFuture.then((path) => Expect.fail("Unreachable code $path"))
|
| - .catchError((error) {
|
| + resolvedFuture
|
| + .then((path) => Expect.fail("Unreachable code $path"))
|
| + .catchError((error) {
|
| checkResolveSymbolicLinksOnNonExistentFileSystemException(error);
|
| temp.deleteSync(recursive: true);
|
| asyncEnd();
|
| @@ -165,11 +155,12 @@ void testReadAsBytesNonExistent() {
|
|
|
| // Non-existing file should throw exception.
|
| Expect.throws(() => file.readAsBytesSync(),
|
| - (e) => checkOpenNonExistentFileSystemException(e));
|
| + (e) => checkOpenNonExistentFileSystemException(e));
|
|
|
| var readAsBytesFuture = file.readAsBytes();
|
| - readAsBytesFuture.then((data) => Expect.fail("Unreachable code"))
|
| - .catchError((error) {
|
| + readAsBytesFuture
|
| + .then((data) => Expect.fail("Unreachable code"))
|
| + .catchError((error) {
|
| checkOpenNonExistentFileSystemException(error);
|
| temp.deleteSync(recursive: true);
|
| asyncEnd();
|
| @@ -183,11 +174,12 @@ void testReadAsTextNonExistent() {
|
|
|
| // Non-existing file should throw exception.
|
| Expect.throws(() => file.readAsStringSync(),
|
| - (e) => checkOpenNonExistentFileSystemException(e));
|
| + (e) => checkOpenNonExistentFileSystemException(e));
|
|
|
| var readAsStringFuture = file.readAsString(encoding: ASCII);
|
| - readAsStringFuture.then((data) => Expect.fail("Unreachable code"))
|
| - .catchError((error) {
|
| + readAsStringFuture
|
| + .then((data) => Expect.fail("Unreachable code"))
|
| + .catchError((error) {
|
| checkOpenNonExistentFileSystemException(error);
|
| temp.deleteSync(recursive: true);
|
| asyncEnd();
|
| @@ -201,11 +193,12 @@ testReadAsLinesNonExistent() {
|
|
|
| // Non-existing file should throw exception.
|
| Expect.throws(() => file.readAsLinesSync(),
|
| - (e) => checkOpenNonExistentFileSystemException(e));
|
| + (e) => checkOpenNonExistentFileSystemException(e));
|
|
|
| var readAsLinesFuture = file.readAsLines(encoding: ASCII);
|
| - readAsLinesFuture.then((data) => Expect.fail("Unreachable code"))
|
| - .catchError((error) {
|
| + readAsLinesFuture
|
| + .then((data) => Expect.fail("Unreachable code"))
|
| + .catchError((error) {
|
| checkOpenNonExistentFileSystemException(error);
|
| temp.deleteSync(recursive: true);
|
| asyncEnd();
|
| @@ -219,7 +212,6 @@ bool checkWriteReadOnlyFileSystemException(e) {
|
| return true;
|
| }
|
|
|
| -
|
| // Create a test file in a temporary directory. Setup a port to signal
|
| // when the temporary directory should be deleted. Pass the file and
|
| // the port to the callback argument.
|
| @@ -234,14 +226,13 @@ createTestFile(callback) {
|
| });
|
| }
|
|
|
| -
|
| testWriteByteToReadOnlyFile() {
|
| createTestFile((file, done) {
|
| var openedFile = file.openSync(mode: FileMode.READ);
|
|
|
| // Writing to read only file should throw an exception.
|
| Expect.throws(() => openedFile.writeByteSync(0),
|
| - (e) => checkWriteReadOnlyFileSystemException(e));
|
| + (e) => checkWriteReadOnlyFileSystemException(e));
|
|
|
| var writeByteFuture = openedFile.writeByte(0);
|
| writeByteFuture.catchError((error) {
|
| @@ -258,7 +249,7 @@ testWriteFromToReadOnlyFile() {
|
| List data = [0, 1, 2, 3];
|
| // Writing to read only file should throw an exception.
|
| Expect.throws(() => openedFile.writeFromSync(data, 0, data.length),
|
| - (e) => checkWriteReadOnlyFileSystemException(e));
|
| + (e) => checkWriteReadOnlyFileSystemException(e));
|
|
|
| var writeFromFuture = openedFile.writeFrom(data, 0, data.length);
|
| writeFromFuture.catchError((error) {
|
| @@ -277,11 +268,12 @@ testTruncateReadOnlyFile() {
|
|
|
| // Truncating read only file should throw an exception.
|
| Expect.throws(() => openedFile.truncateSync(0),
|
| - (e) => checkWriteReadOnlyFileSystemException(e));
|
| + (e) => checkWriteReadOnlyFileSystemException(e));
|
|
|
| var truncateFuture = openedFile.truncate(0);
|
| - truncateFuture.then((ignore) => Expect.fail("Unreachable code"))
|
| - .catchError((error) {
|
| + truncateFuture
|
| + .then((ignore) => Expect.fail("Unreachable code"))
|
| + .catchError((error) {
|
| checkWriteReadOnlyFileSystemException(error);
|
| openedFile.close().then((_) => done());
|
| });
|
| @@ -301,26 +293,26 @@ testOperateOnClosedFile() {
|
| openedFile.closeSync();
|
|
|
| List data = [0, 1, 2, 3];
|
| - Expect.throws(() => openedFile.readByteSync(),
|
| - (e) => checkFileClosedException(e));
|
| - Expect.throws(() => openedFile.writeByteSync(0),
|
| - (e) => checkFileClosedException(e));
|
| + Expect.throws(
|
| + () => openedFile.readByteSync(), (e) => checkFileClosedException(e));
|
| + Expect.throws(
|
| + () => openedFile.writeByteSync(0), (e) => checkFileClosedException(e));
|
| Expect.throws(() => openedFile.writeFromSync(data, 0, data.length),
|
| - (e) => checkFileClosedException(e));
|
| + (e) => checkFileClosedException(e));
|
| Expect.throws(() => openedFile.readIntoSync(data, 0, data.length),
|
| - (e) => checkFileClosedException(e));
|
| + (e) => checkFileClosedException(e));
|
| Expect.throws(() => openedFile.writeStringSync("Hello"),
|
| - (e) => checkFileClosedException(e));
|
| - Expect.throws(() => openedFile.positionSync(),
|
| - (e) => checkFileClosedException(e));
|
| + (e) => checkFileClosedException(e));
|
| + Expect.throws(
|
| + () => openedFile.positionSync(), (e) => checkFileClosedException(e));
|
| Expect.throws(() => openedFile.setPositionSync(0),
|
| - (e) => checkFileClosedException(e));
|
| - Expect.throws(() => openedFile.truncateSync(0),
|
| - (e) => checkFileClosedException(e));
|
| - Expect.throws(() => openedFile.lengthSync(),
|
| - (e) => checkFileClosedException(e));
|
| - Expect.throws(() => openedFile.flushSync(),
|
| - (e) => checkFileClosedException(e));
|
| + (e) => checkFileClosedException(e));
|
| + Expect.throws(
|
| + () => openedFile.truncateSync(0), (e) => checkFileClosedException(e));
|
| + Expect.throws(
|
| + () => openedFile.lengthSync(), (e) => checkFileClosedException(e));
|
| + Expect.throws(
|
| + () => openedFile.flushSync(), (e) => checkFileClosedException(e));
|
|
|
| var errorCount = 0;
|
|
|
| @@ -332,46 +324,56 @@ testOperateOnClosedFile() {
|
| }
|
|
|
| var readByteFuture = openedFile.readByte();
|
| - readByteFuture.then((byte) => Expect.fail("Unreachable code"))
|
| - .catchError(_errorHandler);
|
| + readByteFuture
|
| + .then((byte) => Expect.fail("Unreachable code"))
|
| + .catchError(_errorHandler);
|
| errorCount++;
|
| var writeByteFuture = openedFile.writeByte(0);
|
| - writeByteFuture.then((ignore) => Expect.fail("Unreachable code"))
|
| - .catchError(_errorHandler);
|
| + writeByteFuture
|
| + .then((ignore) => Expect.fail("Unreachable code"))
|
| + .catchError(_errorHandler);
|
| errorCount++;
|
| var readIntoFuture = openedFile.readInto(data, 0, data.length);
|
| - readIntoFuture.then((bytesRead) => Expect.fail("Unreachable code"))
|
| - .catchError(_errorHandler);
|
| + readIntoFuture
|
| + .then((bytesRead) => Expect.fail("Unreachable code"))
|
| + .catchError(_errorHandler);
|
| errorCount++;
|
| var writeFromFuture = openedFile.writeFrom(data, 0, data.length);
|
| - writeFromFuture.then((ignore) => Expect.fail("Unreachable code"))
|
| - .catchError(_errorHandler);
|
| + writeFromFuture
|
| + .then((ignore) => Expect.fail("Unreachable code"))
|
| + .catchError(_errorHandler);
|
| errorCount++;
|
| var writeStringFuture = openedFile.writeString("Hello");
|
| - writeStringFuture.then((ignore) => Expect.fail("Unreachable code"))
|
| - .catchError(_errorHandler);
|
| + writeStringFuture
|
| + .then((ignore) => Expect.fail("Unreachable code"))
|
| + .catchError(_errorHandler);
|
| errorCount++;
|
| var positionFuture = openedFile.position();
|
| - positionFuture.then((position) => Expect.fail("Unreachable code"))
|
| - .catchError(_errorHandler);
|
| + positionFuture
|
| + .then((position) => Expect.fail("Unreachable code"))
|
| + .catchError(_errorHandler);
|
| errorCount++;
|
| var setPositionFuture = openedFile.setPosition(0);
|
| - setPositionFuture.then((ignore) => Expect.fail("Unreachable code"))
|
| - .catchError(_errorHandler);
|
| + setPositionFuture
|
| + .then((ignore) => Expect.fail("Unreachable code"))
|
| + .catchError(_errorHandler);
|
| errorCount++;
|
| var truncateFuture = openedFile.truncate(0);
|
| - truncateFuture.then((ignore) => Expect.fail("Unreachable code"))
|
| - .catchError(_errorHandler);
|
| + truncateFuture
|
| + .then((ignore) => Expect.fail("Unreachable code"))
|
| + .catchError(_errorHandler);
|
| errorCount++;
|
| var lenFuture = openedFile.length();
|
| - lenFuture.then((length) => Expect.fail("Unreachable code"))
|
| - .catchError(_errorHandler);
|
| + lenFuture
|
| + .then((length) => Expect.fail("Unreachable code"))
|
| + .catchError(_errorHandler);
|
| errorCount++;
|
| var flushFuture = openedFile.flush();
|
| - flushFuture.then((ignore) => Expect.fail("Unreachable code"))
|
| - .catchError(_errorHandler);
|
| + flushFuture
|
| + .then((ignore) => Expect.fail("Unreachable code"))
|
| + .catchError(_errorHandler);
|
| errorCount++;
|
| -});
|
| + });
|
| }
|
|
|
| testRepeatedlyCloseFile() {
|
| @@ -379,8 +381,7 @@ testRepeatedlyCloseFile() {
|
| var openedFile = file.openSync();
|
| openedFile.close().then((ignore) {
|
| var closeFuture = openedFile.close();
|
| - closeFuture.then((ignore) => null)
|
| - .catchError((error) {
|
| + closeFuture.then((ignore) => null).catchError((error) {
|
| Expect.isTrue(error is FileSystemException);
|
| done();
|
| });
|
| @@ -392,8 +393,7 @@ testRepeatedlyCloseFileSync() {
|
| createTestFile((file, done) {
|
| var openedFile = file.openSync();
|
| openedFile.closeSync();
|
| - Expect.throws(openedFile.closeSync,
|
| - (e) => e is FileSystemException);
|
| + Expect.throws(openedFile.closeSync, (e) => e is FileSystemException);
|
| done();
|
| });
|
| }
|
| @@ -402,8 +402,8 @@ testReadSyncBigInt() {
|
| createTestFile((file, done) {
|
| var bigint = 100000000000000000000000000000000000000000;
|
| var openedFile = file.openSync();
|
| - Expect.throws(() => openedFile.readSync(bigint),
|
| - (e) => e is FileSystemException);
|
| + Expect.throws(
|
| + () => openedFile.readSync(bigint), (e) => e is FileSystemException);
|
| openedFile.closeSync();
|
| done();
|
| });
|
| @@ -413,8 +413,8 @@ testReadSyncClosedFile() {
|
| createTestFile((file, done) {
|
| var openedFile = file.openSync();
|
| openedFile.closeSync();
|
| - Expect.throws(() => openedFile.readSync(1),
|
| - (e) => e is FileSystemException);
|
| + Expect.throws(
|
| + () => openedFile.readSync(1), (e) => e is FileSystemException);
|
| done();
|
| });
|
| }
|
|
|