Chromium Code Reviews| 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 "dart:async"; | 5 import "dart:async"; |
| 6 import "dart:io"; | 6 import "dart:io"; |
| 7 | 7 |
| 8 import "package:async_helper/async_helper.dart"; | 8 import "package:async_helper/async_helper.dart"; |
| 9 import "package:expect/expect.dart"; | 9 import "package:expect/expect.dart"; |
| 10 import "package:path/path.dart"; | 10 import "package:path/path.dart"; |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 } | 133 } |
| 134 } | 134 } |
| 135 return Future.wait(futures); | 135 return Future.wait(futures); |
| 136 }) | 136 }) |
| 137 .then((_) => baseDir.delete(recursive: true)); | 137 .then((_) => baseDir.delete(recursive: true)); |
| 138 }); | 138 }); |
| 139 }); | 139 }); |
| 140 } | 140 } |
| 141 | 141 |
| 142 | 142 |
| 143 Future testCreateLoopingLink() { | 143 Future testCreateLoopingLink(_) { |
| 144 return new Directory('').createTemp() | 144 return new Directory('').createTemp() |
| 145 .then((dir) => dir.path) | 145 .then((dir) => dir.path) |
| 146 .then((String base) => | 146 .then((String base) => |
| 147 new Directory(join(base, 'a', 'b', 'c')).create(recursive: true) | 147 new Directory(join(base, 'a', 'b', 'c')).create(recursive: true) |
| 148 .then((_) => new Link(join(base, 'a', 'b', 'c', 'd')) | 148 .then((_) => new Link(join(base, 'a', 'b', 'c', 'd')) |
| 149 .create(join(base, 'a', 'b'))) | 149 .create(join(base, 'a', 'b'))) |
| 150 .then((_) => new Link(join(base, 'a', 'b', 'c', 'e')) | 150 .then((_) => new Link(join(base, 'a', 'b', 'c', 'e')) |
| 151 .create(join(base, 'a'))) | 151 .create(join(base, 'a'))) |
| 152 .then((_) => new Directory(join(base, 'a')) | 152 .then((_) => new Directory(join(base, 'a')) |
| 153 .list(recursive: true, followLinks: false).last) | 153 .list(recursive: true, followLinks: false).last) |
| 154 // This directory listing must terminate, even though it contains loops. | 154 // This directory listing must terminate, even though it contains loops. |
| 155 .then((_) => new Directory(join(base, 'a')) | 155 .then((_) => new Directory(join(base, 'a')) |
| 156 .list(recursive: true, followLinks: true).last) | 156 .list(recursive: true, followLinks: true).last) |
| 157 // This directory listing must terminate, even though it contains loops. | 157 // This directory listing must terminate, even though it contains loops. |
| 158 .then((_) => new Directory(join(base, 'a', 'b', 'c')) | 158 .then((_) => new Directory(join(base, 'a', 'b', 'c')) |
| 159 .list(recursive: true, followLinks: true).last) | 159 .list(recursive: true, followLinks: true).last) |
| 160 .then((_) => new Directory(base).delete(recursive: true)) | 160 .then((_) => new Directory(base).delete(recursive: true)) |
| 161 .then((_) => FutureExpect.isFalse(new Directory(base).exists())) | 161 .then((_) => FutureExpect.isFalse(new Directory(base).exists())) |
| 162 ); | 162 ); |
| 163 } | 163 } |
| 164 | 164 |
| 165 | 165 |
| 166 Future testRename() { | 166 Future testRename(_) { |
| 167 Future testRename(String base , String target) { | 167 Future testRename(String base , String target) { |
| 168 Link link1; | 168 Link link1; |
| 169 Link link2; | 169 Link link2; |
| 170 return new Link(join(base, 'c')).create(target) | 170 return new Link(join(base, 'c')).create(target) |
| 171 .then((link) { | 171 .then((link) { |
| 172 link1 = link; | 172 link1 = link; |
| 173 Expect.isTrue(link1.existsSync()); | 173 Expect.isTrue(link1.existsSync()); |
| 174 return link1.rename(join(base, 'd')); | 174 return link1.rename(join(base, 'd')); |
| 175 }) | 175 }) |
| 176 .then((link) { | 176 .then((link) { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 264 for (var v in expected.values) { | 264 for (var v in expected.values) { |
| 265 Expect.equals('Found', v); | 265 Expect.equals('Found', v); |
| 266 } | 266 } |
| 267 }) | 267 }) |
| 268 ); | 268 ); |
| 269 } | 269 } |
| 270 } | 270 } |
| 271 return Future.wait(futures); | 271 return Future.wait(futures); |
| 272 } | 272 } |
| 273 | 273 |
| 274 Future checkExists(String filePath) => | |
| 275 new File(filePath).exists().then((exists) => Expect.isTrue(exists)); | |
|
Søren Gjesse
2013/09/17 11:55:30
(exists) => Expect.isTrue(exists) can be written j
| |
| 276 | |
| 277 Future testRelativeLinks(_) { | |
| 278 return new Directory('').createTemp().then((tempDirectory) { | |
| 279 String temp = tempDirectory.path; | |
| 280 String oldWorkingDirectory = Directory.current.path; | |
| 281 // Make directories and files to test links. | |
| 282 return new Directory(join(temp, 'dir1', 'dir2')).create(recursive: true) | |
| 283 .then((_) => new File(join(temp, 'dir1', 'file1')).create()) | |
| 284 .then((_) => new File(join(temp, 'dir1', 'dir2', 'file2')).create()) | |
| 285 // Make links whose path and/or target is given by a relative path. | |
| 286 .then((_) => new Link(join(temp, 'dir1', 'link1_2')).create('dir2')) | |
| 287 .then((_) => Directory.current = temp) | |
| 288 .then((_) => new Link('link0_2').create(join('dir1', 'dir2'))) | |
| 289 .then((_) => new Link(join('dir1', 'link1_0')).create('..')) | |
| 290 .then((_) => Directory.current = 'dir1') | |
| 291 .then((_) => new Link(join('..', 'link0_1')).create('dir1')) | |
| 292 .then((_) => new Link(join('dir2', 'link2_1')).create(join(temp, 'dir1'))) | |
| 293 .then((_) => new Link(join(temp, 'dir1', 'dir2', 'link2_0')) | |
| 294 .create(join('..', '..'))) | |
| 295 // Test that the links go to the right targets. | |
| 296 .then((_) => checkExists(join('..', 'link0_1', 'file1'))) | |
| 297 .then((_) => checkExists(join('..', 'link0_2', 'file2'))) | |
| 298 .then((_) => checkExists(join('link1_0', 'dir1', 'file1'))) | |
| 299 .then((_) => checkExists(join('link1_2', 'file2'))) | |
| 300 .then((_) => checkExists(join('dir2', 'link2_0', 'dir1', 'file1'))) | |
| 301 .then((_) => checkExists(join('dir2', 'link2_1', 'file1'))) | |
| 302 // Clean up | |
| 303 .whenComplete(() => Directory.current = oldWorkingDirectory) | |
| 304 .whenComplete(() => tempDirectory.delete(recursive: true)); | |
| 305 }); | |
| 306 } | |
| 307 | |
| 274 main() { | 308 main() { |
| 275 asyncStart(); | 309 asyncStart(); |
| 276 testCreate() | 310 testCreate() |
| 277 .then((_) => testCreateLoopingLink()) | 311 .then(testCreateLoopingLink) |
| 278 .then((_) => testRename()) | 312 .then(testRename) |
| 313 .then(testRelativeLinks) | |
| 279 .then((_) => asyncEnd()); | 314 .then((_) => asyncEnd()); |
| 280 } | 315 } |
| OLD | NEW |