Chromium Code Reviews| Index: tests/standalone/src/io/FileErrorTest.dart |
| diff --git a/tests/standalone/src/io/FileErrorTest.dart b/tests/standalone/src/io/FileErrorTest.dart |
| index e85bfb0d69f28467e26c5d5225410a38b20766c5..63648fbf8130e79d273a050bcb12f29dddba10f7 100644 |
| --- a/tests/standalone/src/io/FileErrorTest.dart |
| +++ b/tests/standalone/src/io/FileErrorTest.dart |
| @@ -35,14 +35,23 @@ bool checkOpenNonExistentFileException(e) { |
| } |
| void testOpenNonExistent() { |
| - var file = new File("${tempDir().path}/nonExistentFile"); |
| + Directory temp = tempDir(); |
|
floitsch
2012/04/04 15:59:06
I would prefer:
File createFileInTemporaryDirector
Bill Hesse
2012/04/04 16:11:06
There are some cases below where the onError handl
|
| + ReceivePort p = new ReceivePort(); |
| + p.receive((x,y) { |
| + p.close(); |
| + temp.deleteRecursivelySync(); |
| + }); |
| + var file = new File("${temp.path}/nonExistentFile"); |
| // Non-existing file should throw exception. |
| Expect.throws(() => file.openSync(), |
| (e) => checkOpenNonExistentFileException(e)); |
| file.open(FileMode.READ, (raf) => Expect.fail("Unreachable code")); |
| - file.onError = (e) => checkOpenNonExistentFileException(e); |
| + file.onError = (e) { |
| + checkOpenNonExistentFileException(e); |
| + p.toSendPort().send(null); |
| + }; |
| } |
| bool checkDeleteNonExistentFileException(e) { |
| @@ -66,14 +75,23 @@ bool checkDeleteNonExistentFileException(e) { |
| } |
| void testDeleteNonExistent() { |
| - var file = new File("${tempDir().path}/nonExistentFile"); |
| + Directory temp = tempDir(); |
| + ReceivePort p = new ReceivePort(); |
| + p.receive((x,y) { |
| + p.close(); |
| + temp.deleteRecursivelySync(); |
| + }); |
| + var file = new File("${temp.path}/nonExistentFile"); |
| // Non-existing file should throw exception. |
| Expect.throws(() => file.deleteSync(), |
| (e) => checkDeleteNonExistentFileException(e)); |
| file.delete(() => Expect.fail("Unreachable code")); |
| - file.onError = (e) => checkDeleteNonExistentFileException(e); |
| + file.onError = (e) { |
| + checkDeleteNonExistentFileException(e); |
| + p.toSendPort().send(null); |
| + }; |
| } |
| bool checkCreateInNonExistentDirectoryException(e) { |
| @@ -98,14 +116,23 @@ bool checkCreateInNonExistentDirectoryException(e) { |
| } |
| void testCreateInNonExistentDirectory() { |
| - var file = new File("${tempDir().path}/nonExistentDirectory/newFile"); |
| + Directory temp = tempDir(); |
| + ReceivePort p = new ReceivePort(); |
| + p.receive((x,y) { |
| + p.close(); |
| + temp.deleteRecursivelySync(); |
| + }); |
| + var file = new File("${temp.path}/nonExistentDirectory/newFile"); |
| // Create in non-existent directory should throw exception. |
| Expect.throws(() => file.createSync(), |
| (e) => checkCreateInNonExistentDirectoryException(e)); |
| file.create(() => Expect.fail("Unreachable code")); |
| - file.onError = (e) => checkCreateInNonExistentDirectoryException(e); |
| + file.onError = (e) { |
| + checkCreateInNonExistentDirectoryException(e); |
| + p.toSendPort().send(null); |
| + }; |
| } |
| bool checkFullPathOnNonExistentDirectoryException(e) { |
| @@ -129,14 +156,23 @@ bool checkFullPathOnNonExistentDirectoryException(e) { |
| } |
| void testFullPathOnNonExistentDirectory() { |
| - var file = new File("${tempDir().path}/nonExistentDirectory"); |
| + Directory temp = tempDir(); |
| + ReceivePort p = new ReceivePort(); |
| + p.receive((x,y) { |
| + p.close(); |
| + temp.deleteRecursivelySync(); |
| + }); |
| + var file = new File("${temp.path}/nonExistentDirectory"); |
| // Full path non-existent directory should throw exception. |
| Expect.throws(() => file.fullPathSync(), |
| (e) => checkFullPathOnNonExistentDirectoryException(e)); |
| file.fullPath((path) => Expect.fail("Unreachable code $path")); |
| - file.onError = (e) => checkFullPathOnNonExistentDirectoryException(e); |
| + file.onError = (e) { |
| + checkFullPathOnNonExistentDirectoryException(e); |
| + p.toSendPort().send(null); |
| + }; |
| } |
| bool checkDirectoryInNonExistentDirectoryException(e) { |
| @@ -161,47 +197,83 @@ bool checkDirectoryInNonExistentDirectoryException(e) { |
| } |
| void testDirectoryInNonExistentDirectory() { |
| - var file = new File("${tempDir().path}/nonExistentDirectory/newFile"); |
| + Directory temp = tempDir(); |
| + ReceivePort p = new ReceivePort(); |
| + p.receive((x,y) { |
| + p.close(); |
| + temp.deleteRecursivelySync(); |
| + }); |
| + var file = new File("${temp.path}/nonExistentDirectory/newFile"); |
| // Create in non-existent directory should throw exception. |
| Expect.throws(() => file.directorySync(), |
| (e) => checkDirectoryInNonExistentDirectoryException(e)); |
| file.directory((directory) => Expect.fail("Unreachable code")); |
| - file.onError = (e) => checkDirectoryInNonExistentDirectoryException(e); |
| + file.onError = (e) { |
| + checkDirectoryInNonExistentDirectoryException(e); |
| + p.toSendPort().send(null); |
| + }; |
| } |
| void testReadAsBytesNonExistent() { |
| - var file = new File("${tempDir().path}/nonExistentFile3"); |
| + Directory temp = tempDir(); |
| + ReceivePort p = new ReceivePort(); |
| + p.receive((x,y) { |
| + p.close(); |
| + temp.deleteRecursivelySync(); |
| + }); |
| + var file = new File("${temp.path}/nonExistentFile3"); |
| // Non-existing file should throw exception. |
| Expect.throws(() => file.readAsBytesSync(), |
| (e) => checkOpenNonExistentFileException(e)); |
| file.readAsBytes((data) => Expect.fail("Unreachable code")); |
| - file.onError = (e) => checkOpenNonExistentFileException(e); |
| + file.onError = (e) { |
| + checkOpenNonExistentFileException(e); |
| + p.toSendPort().send(null); |
| + }; |
| } |
| void testReadAsTextNonExistent() { |
| - var file = new File("${tempDir().path}/nonExistentFile4"); |
| + Directory temp = tempDir(); |
| + ReceivePort p = new ReceivePort(); |
| + p.receive((x,y) { |
| + p.close(); |
| + temp.deleteRecursivelySync(); |
| + }); |
| + var file = new File("${temp.path}/nonExistentFile4"); |
| // Non-existing file should throw exception. |
| Expect.throws(() => file.readAsTextSync(), |
| (e) => checkOpenNonExistentFileException(e)); |
| file.readAsText(Encoding.ASCII, (data) => Expect.fail("Unreachable code")); |
| - file.onError = (e) => checkOpenNonExistentFileException(e); |
| + file.onError = (e) { |
| + checkOpenNonExistentFileException(e); |
| + p.toSendPort().send(null); |
| + }; |
| } |
| -void testReadAsLinesNonExistent() { |
| - var file = new File("${tempDir().path}/nonExistentFile5"); |
| +testReadAsLinesNonExistent() { |
| + Directory temp = tempDir(); |
| + ReceivePort p = new ReceivePort(); |
| + p.receive((x,y) { |
| + p.close(); |
| + temp.deleteRecursivelySync(); |
| + }); |
| + var file = new File("${temp.path}/nonExistentFile5"); |
| // Non-existing file should throw exception. |
| Expect.throws(() => file.readAsLinesSync(), |
| (e) => checkOpenNonExistentFileException(e)); |
| file.readAsLines(Encoding.ASCII, (data) => Expect.fail("Unreachable code")); |
| - file.onError = (e) => checkOpenNonExistentFileException(e); |
| + file.onError = (e) { |
| + checkOpenNonExistentFileException(e); |
| + p.toSendPort().send(null); |
| + }; |
| } |
| bool checkWriteReadOnlyFileException(e) { |
| @@ -299,7 +371,7 @@ testOperateOnClosedFile() { |
| temp.deleteRecursivelySync(); |
| }); |
| - var file = new File("${tempDir().path}/test_file"); |
| + var file = new File("${temp.path}/test_file"); |
| file.createSync(); |
| var openedFile = file.openSync(FileMode.READ); |
| openedFile.closeSync(); |