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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 .last) | 166 .last) |
167 .then((_) => | 167 .then((_) => |
168 // This directory listing must terminate, even though it contains loops. | 168 // This directory listing must terminate, even though it contains loops. |
169 new Directory.fromPath(base.append('a/b/c')) | 169 new Directory.fromPath(base.append('a/b/c')) |
170 .list(recursive: true, followLinks: true) | 170 .list(recursive: true, followLinks: true) |
171 .last) | 171 .last) |
172 .then((_) => | 172 .then((_) => |
173 new Directory.fromPath(base).delete(recursive: true)); | 173 new Directory.fromPath(base).delete(recursive: true)); |
174 } | 174 } |
175 | 175 |
| 176 testRenameSync() { |
| 177 testRename(Path base, String target) { |
| 178 Link link1 = new Link.fromPath(base.append('c'))..createSync(target); |
| 179 Expect.isTrue(link1.existsSync()); |
| 180 Link link2 = link1.renameSync(base.append('d').toNativePath()); |
| 181 Expect.isFalse(link1.existsSync()); |
| 182 Expect.isTrue(link2.existsSync()); |
| 183 link2.deleteSync(); |
| 184 Expect.isFalse(link2.existsSync()); |
| 185 } |
| 186 |
| 187 Directory baseDir = new Directory('').createTempSync(); |
| 188 Path base = new Path(baseDir.path); |
| 189 Directory dir = new Directory.fromPath(base.append('a'))..createSync(); |
| 190 File file = new File.fromPath(base.append('b'))..createSync(); |
| 191 |
| 192 testRename(base, file.path); |
| 193 testRename(base, dir.path); |
| 194 |
| 195 baseDir.deleteSync(recursive: true); |
| 196 } |
| 197 |
176 void testLinkErrorSync() { | 198 void testLinkErrorSync() { |
177 Expect.throws(() => | 199 Expect.throws(() => |
178 new Link('some-dir-that-doent exist/some link file/bla/fisk').createSync( | 200 new Link('some-dir-that-doent exist/some link file/bla/fisk').createSync( |
179 'bla bla bla/b lalal/blfir/sdfred/es'), | 201 'bla bla bla/b lalal/blfir/sdfred/es'), |
180 (e) => e is LinkException); | 202 (e) => e is LinkException); |
181 } | 203 } |
182 | 204 |
183 main() { | 205 main() { |
184 testCreateSync(); | 206 testCreateSync(); |
185 testCreateLoopingLink(); | 207 testCreateLoopingLink(); |
| 208 testRenameSync(); |
186 testLinkErrorSync(); | 209 testLinkErrorSync(); |
187 } | 210 } |
OLD | NEW |