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

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

Issue 25471003: Modify tests to use Directory.systemTemp (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebase Created 7 years, 2 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
OLDNEW
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:async";
8 import "dart:io"; 8 import "dart:io";
9 9
10 import "package:async_helper/async_helper.dart"; 10 import "package:async_helper/async_helper.dart";
11 import "package:expect/expect.dart"; 11 import "package:expect/expect.dart";
12 12
13 Directory tempDir() { 13 Directory tempDir() {
14 return new Directory('').createTempSync(); 14 return Directory.systemTemp.createTempSync('dart_directory_error');
15 } 15 }
16 16
17 17
18 bool checkCreateInNonExistentFileException(e) { 18 bool checkCreateInNonExistentFileException(e) {
19 Expect.isTrue(e is DirectoryException); 19 Expect.isTrue(e is DirectoryException);
20 Expect.isTrue(e.osError != null); 20 Expect.isTrue(e.osError != null);
21 Expect.isTrue(e.toString().indexOf("Creation failed") != -1); 21 Expect.isTrue(e.toString().indexOf("Creation failed") != -1);
22 if (Platform.operatingSystem == "linux") { 22 if (Platform.operatingSystem == "linux") {
23 Expect.equals(2, e.osError.errorCode); 23 Expect.equals(2, e.osError.errorCode);
24 } else if (Platform.operatingSystem == "macos") { 24 } else if (Platform.operatingSystem == "macos") {
(...skipping 28 matching lines...) Expand all
53 } else if (Platform.operatingSystem == "windows") { 53 } else if (Platform.operatingSystem == "windows") {
54 Expect.equals(3, e.osError.errorCode); 54 Expect.equals(3, e.osError.errorCode);
55 } 55 }
56 56
57 return true; 57 return true;
58 } 58 }
59 59
60 60
61 void testCreateTempInNonExistent(Directory temp, Function done) { 61 void testCreateTempInNonExistent(Directory temp, Function done) {
62 Directory nonExistent = new Directory("${temp.path}/nonExistent/xxx"); 62 Directory nonExistent = new Directory("${temp.path}/nonExistent/xxx");
63 Expect.throws(() => nonExistent.createTempSync(), 63 Expect.throws(() => nonExistent.createTempSync('tempdir'),
64 (e) => checkCreateTempInNonExistentFileException(e)); 64 (e) => checkCreateTempInNonExistentFileException(e));
65 65
66 nonExistent.createTemp().catchError((error) { 66 nonExistent.createTemp('tempdir').catchError((error) {
67 checkCreateTempInNonExistentFileException(error); 67 checkCreateTempInNonExistentFileException(error);
68 done(); 68 done();
69 }); 69 });
70 } 70 }
71 71
72 72
73 bool checkDeleteNonExistentFileException(e) { 73 bool checkDeleteNonExistentFileException(e) {
74 Expect.isTrue(e is DirectoryException); 74 Expect.isTrue(e is DirectoryException);
75 Expect.isTrue(e.osError != null); 75 Expect.isTrue(e.osError != null);
76 // File not not found has error code 2 on all supported platforms. 76 // File not not found has error code 2 on all supported platforms.
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 var renameDone = d.rename(newPath); 172 var renameDone = d.rename(newPath);
173 renameDone.then((ignore) => Expect.fail('rename file as directory')) 173 renameDone.then((ignore) => Expect.fail('rename file as directory'))
174 .catchError((error) { 174 .catchError((error) {
175 Expect.isTrue(error is DirectoryException); 175 Expect.isTrue(error is DirectoryException);
176 done(); 176 done();
177 }); 177 });
178 } 178 }
179 179
180 180
181 testRenameOverwriteFile(Directory temp, Function done) { 181 testRenameOverwriteFile(Directory temp, Function done) {
182 var d = new Directory(''); 182 var temp1 = Directory.systemTemp.createTempSync('dart_directory_error');
183 var temp1 = d.createTempSync();
184 var fileName = '${temp.path}/x'; 183 var fileName = '${temp.path}/x';
185 new File(fileName).createSync(); 184 new File(fileName).createSync();
186 Expect.throws(() => temp1.renameSync(fileName), 185 Expect.throws(() => temp1.renameSync(fileName),
187 (e) => e is DirectoryException); 186 (e) => e is DirectoryException);
188 var renameDone = temp1.rename(fileName); 187 var renameDone = temp1.rename(fileName);
189 renameDone.then((ignore) => Expect.fail('rename dir overwrite file')) 188 renameDone.then((ignore) => Expect.fail('rename dir overwrite file'))
190 .catchError((error) { 189 .catchError((error) {
191 Expect.isTrue(error is DirectoryException); 190 Expect.isTrue(error is DirectoryException);
192 temp1.deleteSync(recursive: true); 191 temp1.deleteSync(recursive: true);
193 done(); 192 done();
194 }); 193 });
195 } 194 }
196 195
197 196
198 void runTest(Function test) { 197 void runTest(Function test) {
199 // Create a temporary directory for the test. 198 // Create a temporary directory for the test.
200 var temp = new Directory('').createTempSync(); 199 var temp = Directory.systemTemp.createTempSync('dart_directory_error');
201 200
202 // Wait for the test to finish and delete the temporary directory. 201 // Wait for the test to finish and delete the temporary directory.
203 asyncStart(); 202 asyncStart();
204 203
205 // Run the test. 204 // Run the test.
206 test(temp, () { 205 test(temp, () {
207 temp.deleteSync(recursive: true); 206 temp.deleteSync(recursive: true);
208 asyncEnd(); 207 asyncEnd();
209 }); 208 });
210 } 209 }
211 210
212 211
213 main() { 212 main() {
214 runTest(testCreateInNonExistent); 213 runTest(testCreateInNonExistent);
215 runTest(testCreateTempInNonExistent); 214 runTest(testCreateTempInNonExistent);
216 runTest(testDeleteNonExistent); 215 runTest(testDeleteNonExistent);
217 runTest(testDeleteRecursivelyNonExistent); 216 runTest(testDeleteRecursivelyNonExistent);
218 runTest(testListNonExistent); 217 runTest(testListNonExistent);
219 runTest(testRenameNonExistent); 218 runTest(testRenameNonExistent);
220 runTest(testRenameFileAsDirectory); 219 runTest(testRenameFileAsDirectory);
221 runTest(testRenameOverwriteFile); 220 runTest(testRenameOverwriteFile);
222 } 221 }
OLDNEW
« no previous file with comments | « tests/standalone/io/directory_create_race_test.dart ('k') | tests/standalone/io/directory_fuzz_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698