| 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().then((baseDir) { |
| 187 Path base = new Path(baseDir.path); |
| 188 var targetsFutures = []; |
| 189 targetsFutures.add(new Directory.fromPath(base.append('a')).create()); |
| 190 if (Platform.isWindows) { |
| 191 // Currently only links to directories are supported on Windows. |
| 192 targetsFutures.add( |
| 193 new Directory.fromPath(base.append('b')).create()); |
| 194 } else { |
| 195 targetsFutures.add(new File.fromPath(base.append('b')).create()); |
| 196 } |
| 197 return Future.wait(targetsFutures).then((targets) { |
| 198 return testRename(base, targets[0].path) |
| 199 .then((_) => testRename(base, targets[1].path)) |
| 200 .then((_) => baseDir.delete(recursive: true)); |
| 201 }); |
| 202 }); |
| 203 } |
| 204 |
| 167 Future testDirectoryListing(Path base, Directory baseDir) { | 205 Future testDirectoryListing(Path base, Directory baseDir) { |
| 168 Map makeExpected(bool recursive, bool followLinks) { | 206 Map makeExpected(bool recursive, bool followLinks) { |
| 169 Map expected = new Map(); | 207 Map expected = new Map(); |
| 170 expected['target'] = 'Directory'; | 208 expected['target'] = 'Directory'; |
| 171 expected['link'] = followLinks ? 'Directory' : 'Link'; | 209 expected['link'] = followLinks ? 'Directory' : 'Link'; |
| 172 if (recursive) { | 210 if (recursive) { |
| 173 expected['target/createdDirectly'] = 'Directory'; | 211 expected['target/createdDirectly'] = 'Directory'; |
| 174 expected['target/createdThroughLink'] = 'Directory'; | 212 expected['target/createdThroughLink'] = 'Directory'; |
| 175 expected['target/createdFile'] = 'File'; | 213 expected['target/createdFile'] = 'File'; |
| 176 if (followLinks) { | 214 if (followLinks) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 ); | 250 ); |
| 213 } | 251 } |
| 214 } | 252 } |
| 215 return Future.wait(futures); | 253 return Future.wait(futures); |
| 216 } | 254 } |
| 217 | 255 |
| 218 main() { | 256 main() { |
| 219 ReceivePort keepAlive = new ReceivePort(); | 257 ReceivePort keepAlive = new ReceivePort(); |
| 220 testCreate() | 258 testCreate() |
| 221 .then((_) => testCreateLoopingLink()) | 259 .then((_) => testCreateLoopingLink()) |
| 260 .then((_) => testRename()) |
| 222 .then((_) => keepAlive.close()); | 261 .then((_) => keepAlive.close()); |
| 223 } | 262 } |
| OLD | NEW |