OLD | NEW |
---|---|
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
6 import "dart:async"; | 6 import "dart:async"; |
7 import "dart:io"; | 7 import "dart:io"; |
8 import "dart:isolate"; | 8 import "dart:isolate"; |
9 | 9 |
10 // Test the dart:io Link class. | 10 // Test the dart:io Link class. |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
157 .then((_) => new Directory.fromPath(base.append('a')) | 157 .then((_) => new Directory.fromPath(base.append('a')) |
158 .list(recursive: true, followLinks: true).last) | 158 .list(recursive: true, followLinks: true).last) |
159 // This directory listing must terminate, even though it contains loops. | 159 // This directory listing must terminate, even though it contains loops. |
160 .then((_) => new Directory.fromPath(base.append('a/b/c')) | 160 .then((_) => new Directory.fromPath(base.append('a/b/c')) |
161 .list(recursive: true, followLinks: true).last) | 161 .list(recursive: true, followLinks: true).last) |
162 .then((_) => new Directory.fromPath(base).delete(recursive: true)) | 162 .then((_) => new Directory.fromPath(base).delete(recursive: true)) |
163 ); | 163 ); |
164 } | 164 } |
165 | 165 |
166 | 166 |
167 Future testRename() { | |
168 Future testRename(Path base, String target) { | |
169 Link link1; | |
170 Link link2; | |
171 return new Link.fromPath(base.append('c')).create(target) | |
172 .then((link) { | |
173 link1 = link; | |
174 Expect.isTrue(link1.existsSync()); | |
175 return link1.rename(base.append('d').toNativePath()); | |
176 }) | |
177 .then((link) { | |
178 link2 = link; | |
179 Expect.isFalse(link1.existsSync()); | |
180 Expect.isTrue(link2.existsSync()); | |
181 return link2.delete(); | |
182 }) | |
183 .then((_) => Expect.isFalse(link2.existsSync())); | |
184 } | |
185 | |
186 return new Directory('').createTemp() | |
187 .then((baseDir) { | |
188 Path base = new Path(baseDir.path); | |
189 var targetsFutures = []; | |
190 targetsFutures.add(new Directory.fromPath(base.append('a')).create()); | |
191 if (Platform.isWindows) { | |
192 // Currently only links to directories are supported on Windows. | |
193 targetsFutures.add( | |
194 new Directory.fromPath(base.append('b')).create()); | |
195 } else { | |
196 targetsFutures.add(new File.fromPath(base.append('b')).create()); | |
197 } | |
198 return Future.wait(targetsFutures) | |
199 .then((targets) { | |
200 return testRename(base, targets[0].path) | |
201 .then((_) => testRename(base, targets[1].path)) | |
Bill Hesse
2013/06/26 12:03:54
Don't we indent zero on a .then?
And actually, th
Søren Gjesse
2013/06/26 13:59:40
Done.
| |
202 .then((_) => baseDir.delete(recursive: true)); | |
203 }); | |
204 }); | |
205 } | |
206 | |
167 Future testDirectoryListing(Path base, Directory baseDir) { | 207 Future testDirectoryListing(Path base, Directory baseDir) { |
168 Map makeExpected(bool recursive, bool followLinks) { | 208 Map makeExpected(bool recursive, bool followLinks) { |
169 Map expected = new Map(); | 209 Map expected = new Map(); |
170 expected['target'] = 'Directory'; | 210 expected['target'] = 'Directory'; |
171 expected['link'] = followLinks ? 'Directory' : 'Link'; | 211 expected['link'] = followLinks ? 'Directory' : 'Link'; |
172 if (recursive) { | 212 if (recursive) { |
173 expected['target/createdDirectly'] = 'Directory'; | 213 expected['target/createdDirectly'] = 'Directory'; |
174 expected['target/createdThroughLink'] = 'Directory'; | 214 expected['target/createdThroughLink'] = 'Directory'; |
175 expected['target/createdFile'] = 'File'; | 215 expected['target/createdFile'] = 'File'; |
176 if (followLinks) { | 216 if (followLinks) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
212 ); | 252 ); |
213 } | 253 } |
214 } | 254 } |
215 return Future.wait(futures); | 255 return Future.wait(futures); |
216 } | 256 } |
217 | 257 |
218 main() { | 258 main() { |
219 ReceivePort keepAlive = new ReceivePort(); | 259 ReceivePort keepAlive = new ReceivePort(); |
220 testCreate() | 260 testCreate() |
221 .then((_) => testCreateLoopingLink()) | 261 .then((_) => testCreateLoopingLink()) |
262 .then((_) => testRename()) | |
222 .then((_) => keepAlive.close()); | 263 .then((_) => keepAlive.close()); |
223 } | 264 } |
OLD | NEW |