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

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

Issue 11748017: Add synchronous directory listing to dart:io Directory. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments, move tests that fail on Windows due to VM bug 7157 to a separate test file. Created 7 years, 11 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
« no previous file with comments | « tests/standalone/io/directory_test.dart ('k') | tests/standalone/standalone.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 import "dart:io"; 5 import "dart:io";
6 6
7 7
8 createLink(String dst, String link, bool symbolic, void callback()) { 8 createLink(String dst, String link, bool symbolic, void callback()) {
9 var args = [ symbolic ? '-s' : '', dst, link ]; 9 var args = [ symbolic ? '-s' : '', dst, link ];
10 var script = 'tests/standalone/io/ln.sh'; 10 var script = 'tests/standalone/io/ln.sh';
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 120
121 testDirectoryListing() { 121 testDirectoryListing() {
122 var temp = new Directory('').createTempSync(); 122 var temp = new Directory('').createTempSync();
123 var temp2 = new Directory('').createTempSync(); 123 var temp2 = new Directory('').createTempSync();
124 var y = '${temp.path}${Platform.pathSeparator}y'; 124 var y = '${temp.path}${Platform.pathSeparator}y';
125 var x = '${temp2.path}${Platform.pathSeparator}x'; 125 var x = '${temp2.path}${Platform.pathSeparator}x';
126 new File(x).createSync(); 126 new File(x).createSync();
127 createLink(temp2.path, y, true, () { 127 createLink(temp2.path, y, true, () {
128 var files = []; 128 var files = [];
129 var dirs = []; 129 var dirs = [];
130 for (var entry in temp.listSync(recursive:true)) {
131 if (entry is File) {
132 files.add(entry.name);
133 } else {
134 Expect.isTrue(entry is Directory);
135 dirs.add(entry.path);
136 }
137 }
138 Expect.equals(1, files.length);
139 Expect.isTrue(files[0].endsWith(x));
140 Expect.equals(1, dirs.length);
141 Expect.isTrue(dirs[0].endsWith(y));
142
143 files = [];
144 dirs = [];
130 var lister = temp.list(recursive: true); 145 var lister = temp.list(recursive: true);
131 lister.onFile = (f) => files.add(f); 146 lister.onFile = (f) => files.add(f);
132 lister.onDir = (d) => dirs.add(d); 147 lister.onDir = (d) => dirs.add(d);
133 lister.onDone = (success) { 148 lister.onDone = (success) {
134 Expect.isTrue(success); 149 Expect.isTrue(success);
135 Expect.equals(1, files.length); 150 Expect.equals(1, files.length);
136 Expect.isTrue(files[0].endsWith(x)); 151 Expect.isTrue(files[0].endsWith(x));
137 Expect.equals(1, dirs.length); 152 Expect.equals(1, dirs.length);
138 Expect.isTrue(dirs[0].endsWith(y)); 153 Expect.isTrue(dirs[0].endsWith(y));
139 temp.deleteSync(recursive: true); 154 temp.deleteSync(recursive: true);
140 temp2.deleteSync(recursive: true); 155 temp2.deleteSync(recursive: true);
141 }; 156 };
142 }); 157 });
143 } 158 }
144 159
145 160
146 testDirectoryListingBrokenLink() { 161 testDirectoryListingBrokenLink() {
147 var temp = new Directory('').createTempSync(); 162 var temp = new Directory('').createTempSync();
148 var x = '${temp.path}${Platform.pathSeparator}x'; 163 var x = '${temp.path}${Platform.pathSeparator}x';
149 var link = '${temp.path}${Platform.pathSeparator}link'; 164 var link = '${temp.path}${Platform.pathSeparator}link';
150 var doesNotExist = 'this_thing_does_not_exist'; 165 var doesNotExist = 'this_thing_does_not_exist';
151 new File(x).createSync(); 166 new File(x).createSync();
152 createLink(doesNotExist, link, true, () { 167 createLink(doesNotExist, link, true, () {
168 Expect.throws(() => temp.listSync(recursive: true),
169 (e) => e is DirectoryIOException);
153 var files = []; 170 var files = [];
154 var dirs = []; 171 var dirs = [];
155 var errors = []; 172 var errors = [];
156 var lister = temp.list(recursive: true); 173 var lister = temp.list(recursive: true);
157 lister.onFile = (f) => files.add(f); 174 lister.onFile = (f) => files.add(f);
158 lister.onDir = (d) => dirs.add(d); 175 lister.onDir = (d) => dirs.add(d);
159 lister.onError = (d) => errors.add(d); 176 lister.onError = (d) => errors.add(d);
160 lister.onDone = (success) { 177 lister.onDone = (success) {
161 Expect.isFalse(success); 178 Expect.isFalse(success);
162 Expect.equals(1, files.length); 179 Expect.equals(1, files.length);
163 Expect.isTrue(files[0].endsWith(x)); 180 Expect.isTrue(files[0].endsWith(x));
164 Expect.equals(0, dirs.length); 181 Expect.equals(0, dirs.length);
165 Expect.equals(1, errors.length); 182 Expect.equals(1, errors.length);
166 Expect.isTrue(errors[0].toString().contains(link)); 183 Expect.isTrue(errors[0].toString().contains(link));
167 temp.deleteSync(recursive: true); 184 temp.deleteSync(recursive: true);
168 }; 185 };
169 }); 186 });
170 } 187 }
171 188
172 189
173 main() { 190 main() {
174 testFileExistsCreate(); 191 testFileExistsCreate();
175 testFileDelete(); 192 testFileDelete();
176 testFileWriteRead(); 193 testFileWriteRead();
177 testDirectoryExistsCreate(); 194 testDirectoryExistsCreate();
178 testDirectoryDelete(); 195 testDirectoryDelete();
179 testDirectoryListing(); 196 testDirectoryListing();
180 testDirectoryListingBrokenLink(); 197 testDirectoryListingBrokenLink();
181 } 198 }
OLDNEW
« no previous file with comments | « tests/standalone/io/directory_test.dart ('k') | tests/standalone/standalone.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698