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 // Dart test program for testing error handling in directory I/O. | 5 // Dart test program for testing error handling in directory I/O. |
6 | 6 |
| 7 import "dart:async"; |
7 import "dart:io"; | 8 import "dart:io"; |
8 import "dart:isolate"; | 9 import "dart:isolate"; |
9 | 10 |
10 Directory tempDir() { | 11 Directory tempDir() { |
11 return new Directory('').createTempSync(); | 12 return new Directory('').createTempSync(); |
12 } | 13 } |
13 | 14 |
14 | 15 |
15 bool checkCreateInNonExistentFileException(e) { | 16 bool checkCreateInNonExistentFileException(e) { |
16 Expect.isTrue(e is DirectoryIOException); | 17 Expect.isTrue(e is DirectoryIOException); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 } else if (Platform.operatingSystem == "macos") { | 127 } else if (Platform.operatingSystem == "macos") { |
127 Expect.equals(2, e.osError.errorCode); | 128 Expect.equals(2, e.osError.errorCode); |
128 } else if (Platform.operatingSystem == "windows") { | 129 } else if (Platform.operatingSystem == "windows") { |
129 Expect.equals(3, e.osError.errorCode); | 130 Expect.equals(3, e.osError.errorCode); |
130 } | 131 } |
131 | 132 |
132 return true; | 133 return true; |
133 } | 134 } |
134 | 135 |
135 | 136 |
| 137 bool checkAsyncListNonExistentFileException(e) { |
| 138 Expect.isTrue(e is AsyncError); |
| 139 return checkListNonExistentFileException(e.error); |
| 140 } |
| 141 |
| 142 |
136 void testListNonExistent(Directory temp, Function done) { | 143 void testListNonExistent(Directory temp, Function done) { |
137 Directory nonExistent = new Directory("${temp.path}/nonExistent"); | 144 Directory nonExistent = new Directory("${temp.path}/nonExistent"); |
138 Expect.throws(() => nonExistent.listSync(), (e) => e is DirectoryIOException); | 145 Expect.throws(() => nonExistent.listSync(), (e) => e is DirectoryIOException); |
139 var lister = nonExistent.list(); | 146 nonExistent.list().listen( |
140 lister.onError = (e) { | 147 (_) => Expect.fail("listing should not succeed"), |
141 checkListNonExistentFileException(e); | 148 onError: (e) { |
142 done(); | 149 checkAsyncListNonExistentFileException(e); |
143 }; | 150 done(); |
| 151 }); |
144 } | 152 } |
145 | 153 |
146 | 154 |
147 void testRenameNonExistent(Directory temp, Function done) { | 155 void testRenameNonExistent(Directory temp, Function done) { |
148 Directory nonExistent = new Directory("${temp.path}/nonExistent"); | 156 Directory nonExistent = new Directory("${temp.path}/nonExistent"); |
149 var newPath = "${temp.path}/nonExistent2"; | 157 var newPath = "${temp.path}/nonExistent2"; |
150 Expect.throws(() => nonExistent.renameSync(newPath), | 158 Expect.throws(() => nonExistent.renameSync(newPath), |
151 (e) => e is DirectoryIOException); | 159 (e) => e is DirectoryIOException); |
152 var renameDone = nonExistent.rename(newPath); | 160 var renameDone = nonExistent.rename(newPath); |
153 renameDone.then((ignore) => Expect.fail('rename non existent')) | 161 renameDone.then((ignore) => Expect.fail('rename non existent')) |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 main() { | 218 main() { |
211 runTest(testCreateInNonExistent); | 219 runTest(testCreateInNonExistent); |
212 runTest(testCreateTempInNonExistent); | 220 runTest(testCreateTempInNonExistent); |
213 runTest(testDeleteNonExistent); | 221 runTest(testDeleteNonExistent); |
214 runTest(testDeleteRecursivelyNonExistent); | 222 runTest(testDeleteRecursivelyNonExistent); |
215 runTest(testListNonExistent); | 223 runTest(testListNonExistent); |
216 runTest(testRenameNonExistent); | 224 runTest(testRenameNonExistent); |
217 runTest(testRenameFileAsDirectory); | 225 runTest(testRenameFileAsDirectory); |
218 runTest(testRenameOverwriteFile); | 226 runTest(testRenameOverwriteFile); |
219 } | 227 } |
OLD | NEW |