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

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

Issue 26968003: Remove DirectoryException and LinkException from dart:io and use FileException instaed. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Merge with master. Created 7 years, 1 month 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 // Directory listing test. 5 // Directory listing test.
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";
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 subDirectory.list().listen(test, onDone: () { 104 subDirectory.list().listen(test, onDone: () {
105 directory.deleteSync(recursive: true); 105 directory.deleteSync(recursive: true);
106 }); 106 });
107 } 107 }
108 108
109 static void testListNonExistent() { 109 static void testListNonExistent() {
110 setupListerHandlers(Stream<FileSystemEntity> stream) { 110 setupListerHandlers(Stream<FileSystemEntity> stream) {
111 stream.listen( 111 stream.listen(
112 (_) => Expect.fail("Listing of non-existing directory should fail"), 112 (_) => Expect.fail("Listing of non-existing directory should fail"),
113 onError: (error) { 113 onError: (error) {
114 Expect.isTrue(error is DirectoryException); 114 Expect.isTrue(error is FileSystemException);
115 }); 115 });
116 } 116 }
117 Directory.systemTemp.createTemp('dart_directory').then((d) { 117 Directory.systemTemp.createTemp('dart_directory').then((d) {
118 d.delete().then((ignore) { 118 d.delete().then((ignore) {
119 setupListerHandlers(d.list()); 119 setupListerHandlers(d.list());
120 setupListerHandlers(d.list(recursive: true)); 120 setupListerHandlers(d.list(recursive: true));
121 }); 121 });
122 }); 122 });
123 } 123 }
124 124
125 static void testListTooLongName() { 125 static void testListTooLongName() {
126 Directory.systemTemp.createTemp('dart_directory').then((d) { 126 Directory.systemTemp.createTemp('dart_directory').then((d) {
127 var errors = 0; 127 var errors = 0;
128 asyncStart(); 128 asyncStart();
129 setupListHandlers(Stream<FileSystemEntity> stream) { 129 setupListHandlers(Stream<FileSystemEntity> stream) {
130 stream.listen( 130 stream.listen(
131 (_) => Expect.fail("Listing of non-existing directory should fail"), 131 (_) => Expect.fail("Listing of non-existing directory should fail"),
132 onError: (error) { 132 onError: (error) {
133 Expect.isTrue(error is DirectoryException); 133 Expect.isTrue(error is FileSystemException);
134 if (++errors == 2) { 134 if (++errors == 2) {
135 d.delete(recursive: true).then((_) { 135 d.delete(recursive: true).then((_) {
136 asyncEnd(); 136 asyncEnd();
137 }); 137 });
138 } 138 }
139 }); 139 });
140 } 140 }
141 var subDirName = 'subdir'; 141 var subDirName = 'subdir';
142 var subDir = new Directory("${d.path}/$subDirName"); 142 var subDir = new Directory("${d.path}/$subDirName");
143 subDir.create().then((ignore) { 143 subDir.create().then((ignore) {
(...skipping 10 matching lines...) Expand all
154 }); 154 });
155 }); 155 });
156 } 156 }
157 157
158 static void testDeleteNonExistent() { 158 static void testDeleteNonExistent() {
159 // Test that deleting a non-existing directory fails. 159 // Test that deleting a non-existing directory fails.
160 setupFutureHandlers(future) { 160 setupFutureHandlers(future) {
161 future.then((ignore) { 161 future.then((ignore) {
162 Expect.fail("Deletion of non-existing directory should fail"); 162 Expect.fail("Deletion of non-existing directory should fail");
163 }).catchError((error) { 163 }).catchError((error) {
164 Expect.isTrue(error is DirectoryException); 164 Expect.isTrue(error is FileSystemException);
165 }); 165 });
166 } 166 }
167 167
168 Directory.systemTemp.createTemp('dart_directory').then((d) { 168 Directory.systemTemp.createTemp('dart_directory').then((d) {
169 d.delete().then((ignore) { 169 d.delete().then((ignore) {
170 setupFutureHandlers(d.delete()); 170 setupFutureHandlers(d.delete());
171 setupFutureHandlers(d.delete(recursive: true)); 171 setupFutureHandlers(d.delete(recursive: true));
172 }); 172 });
173 }); 173 });
174 } 174 }
175 175
176 static void testDeleteTooLongName() { 176 static void testDeleteTooLongName() {
177 asyncStart(); 177 asyncStart();
178 Directory.systemTemp.createTemp('dart_directory').then((d) { 178 Directory.systemTemp.createTemp('dart_directory').then((d) {
179 var subDirName = 'subdir'; 179 var subDirName = 'subdir';
180 var subDir = new Directory("${d.path}/$subDirName"); 180 var subDir = new Directory("${d.path}/$subDirName");
181 subDir.create().then((ignore) { 181 subDir.create().then((ignore) {
182 // Construct a long string of the form 182 // Construct a long string of the form
183 // 'tempdir/subdir/../subdir/../subdir'. 183 // 'tempdir/subdir/../subdir/../subdir'.
184 var buffer = new StringBuffer(); 184 var buffer = new StringBuffer();
185 buffer.write(subDir.path); 185 buffer.write(subDir.path);
186 for (var i = 0; i < 1000; i++) { 186 for (var i = 0; i < 1000; i++) {
187 buffer.write("/../${subDirName}"); 187 buffer.write("/../${subDirName}");
188 } 188 }
189 var long = new Directory("${buffer.toString()}"); 189 var long = new Directory("${buffer.toString()}");
190 var errors = 0; 190 var errors = 0;
191 onError(error) { 191 onError(error) {
192 Expect.isTrue(error is DirectoryException); 192 Expect.isTrue(error is FileSystemException);
193 if (++errors == 2) { 193 if (++errors == 2) {
194 d.delete(recursive: true).then((_) => asyncEnd()); 194 d.delete(recursive: true).then((_) => asyncEnd());
195 } 195 }
196 return true; 196 return true;
197 } 197 }
198 long.delete().catchError(onError); 198 long.delete().catchError(onError);
199 long.delete(recursive: true).catchError(onError); 199 long.delete(recursive: true).catchError(onError);
200 }); 200 });
201 }); 201 });
202 } 202 }
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 return "*"; 500 return "*";
501 } 501 }
502 return null; 502 return null;
503 } 503 }
504 504
505 505
506 testCreateTempErrorSync() { 506 testCreateTempErrorSync() {
507 var location = illegalTempDirectoryLocation(); 507 var location = illegalTempDirectoryLocation();
508 if (location != null) { 508 if (location != null) {
509 Expect.throws(() => new Directory(location).createTempSync('dart_tempdir'), 509 Expect.throws(() => new Directory(location).createTempSync('dart_tempdir'),
510 (e) => e is DirectoryException); 510 (e) => e is FileSystemException);
511 } 511 }
512 } 512 }
513 513
514 514
515 testCreateTempError() { 515 testCreateTempError() {
516 var location = illegalTempDirectoryLocation(); 516 var location = illegalTempDirectoryLocation();
517 if (location == null) return; 517 if (location == null) return;
518 518
519 asyncStart(); 519 asyncStart();
520 var future = new Directory(location).createTemp('dart_tempdir'); 520 var future = new Directory(location).createTemp('dart_tempdir');
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 561
562 562
563 testCreateDirExistingFileSync() { 563 testCreateDirExistingFileSync() {
564 // Test that creating an existing directory succeeds. 564 // Test that creating an existing directory succeeds.
565 var temp = Directory.systemTemp.createTempSync('directory_test'); 565 var temp = Directory.systemTemp.createTempSync('directory_test');
566 var path = '${temp.path}/flaf'; 566 var path = '${temp.path}/flaf';
567 var file = new File(path); 567 var file = new File(path);
568 file.createSync(); 568 file.createSync();
569 Expect.isTrue(file.existsSync()); 569 Expect.isTrue(file.existsSync());
570 Expect.throws(new Directory(path).createSync, 570 Expect.throws(new Directory(path).createSync,
571 (e) => e is DirectoryException); 571 (e) => e is FileSystemException);
572 temp.deleteSync(recursive: true); 572 temp.deleteSync(recursive: true);
573 } 573 }
574 574
575 575
576 testCreateDirExistingFile() { 576 testCreateDirExistingFile() {
577 // Test that creating an existing directory succeeds. 577 // Test that creating an existing directory succeeds.
578 asyncStart(); 578 asyncStart();
579 Directory.systemTemp.createTemp('dart_directory').then((temp) { 579 Directory.systemTemp.createTemp('dart_directory').then((temp) {
580 var path = '${temp.path}/flaf'; 580 var path = '${temp.path}/flaf';
581 var file = new File(path); 581 var file = new File(path);
582 var subDir = new Directory(path); 582 var subDir = new Directory(path);
583 file.create().then((_) { 583 file.create().then((_) {
584 subDir.create() 584 subDir.create()
585 .then((_) { Expect.fail("dir create should fail on existing file"); }) 585 .then((_) { Expect.fail("dir create should fail on existing file"); })
586 .catchError((error) { 586 .catchError((error) {
587 Expect.isTrue(error is DirectoryException); 587 Expect.isTrue(error is FileSystemException);
588 temp.delete(recursive: true).then((_) { 588 temp.delete(recursive: true).then((_) {
589 asyncEnd(); 589 asyncEnd();
590 }); 590 });
591 }); 591 });
592 }); 592 });
593 }); 593 });
594 } 594 }
595 595
596 596
597 testCreateRecursiveSync() { 597 testCreateRecursiveSync() {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 testCreateTempErrorSync(); 644 testCreateTempErrorSync();
645 testCreateTempError(); 645 testCreateTempError();
646 testCreateExistingSync(); 646 testCreateExistingSync();
647 testCreateExisting(); 647 testCreateExisting();
648 testCreateDirExistingFileSync(); 648 testCreateDirExistingFileSync();
649 testCreateDirExistingFile(); 649 testCreateDirExistingFile();
650 testCreateRecursive(); 650 testCreateRecursive();
651 testCreateRecursiveSync(); 651 testCreateRecursiveSync();
652 testRename(); 652 testRename();
653 } 653 }
OLDNEW
« no previous file with comments | « tests/standalone/io/directory_list_nonexistent_test.dart ('k') | tests/standalone/io/file_error_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698