| 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:async_helper/async_helper.dart"; |
| 5 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
| 6 import "package:path/path.dart"; | 7 import "package:path/path.dart"; |
| 7 import "dart:async"; | 8 import "dart:async"; |
| 8 import "dart:io"; | 9 import "dart:io"; |
| 9 import "dart:isolate"; | 10 import "dart:isolate"; |
| 10 | 11 |
| 11 // Test the dart:io Link class. | 12 // Test the dart:io Link class. |
| 12 | 13 |
| 13 testCreateSync() { | 14 testCreateSync() { |
| 15 asyncStart(); |
| 14 String base = Directory.systemTemp.createTempSync('dart_link').path; | 16 String base = Directory.systemTemp.createTempSync('dart_link').path; |
| 15 if (isRelative(base)) { | 17 if (isRelative(base)) { |
| 16 Expect.fail( | 18 Expect.fail( |
| 17 'Link tests expect absolute paths to system temporary directories. ' | 19 'Link tests expect absolute paths to system temporary directories. ' |
| 18 'A relative path in TMPDIR gives relative paths to them.'); | 20 'A relative path in TMPDIR gives relative paths to them.'); |
| 19 } | 21 } |
| 20 String link = join(base, 'link'); | 22 String link = join(base, 'link'); |
| 21 String target = join(base, 'target'); | 23 String target = join(base, 'target'); |
| 22 new Directory(target).createSync(); | 24 new Directory(target).createSync(); |
| 23 print("link: $link"); | |
| 24 print("target: $target"); | |
| 25 new Link(link).createSync(target); | 25 new Link(link).createSync(target); |
| 26 return; | |
| 27 Expect.equals(FileSystemEntityType.DIRECTORY, | 26 Expect.equals(FileSystemEntityType.DIRECTORY, |
| 28 FileSystemEntity.typeSync(link)); | 27 FileSystemEntity.typeSync(link)); |
| 29 Expect.equals(FileSystemEntityType.DIRECTORY, | 28 Expect.equals(FileSystemEntityType.DIRECTORY, |
| 30 FileSystemEntity.typeSync(target)); | 29 FileSystemEntity.typeSync(target)); |
| 31 Expect.equals(FileSystemEntityType.LINK, | 30 Expect.equals(FileSystemEntityType.LINK, |
| 32 FileSystemEntity.typeSync(link, followLinks: false)); | 31 FileSystemEntity.typeSync(link, followLinks: false)); |
| 33 Expect.equals(FileSystemEntityType.DIRECTORY, | 32 Expect.equals(FileSystemEntityType.DIRECTORY, |
| 34 FileSystemEntity.typeSync(target, followLinks: false)); | 33 FileSystemEntity.typeSync(target, followLinks: false)); |
| 35 Expect.isTrue(FileSystemEntity.isLinkSync(link)); | 34 Expect.isTrue(FileSystemEntity.isLinkSync(link)); |
| 36 Expect.isFalse(FileSystemEntity.isLinkSync(target)); | 35 Expect.isFalse(FileSystemEntity.isLinkSync(target)); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 new Directory(target).deleteSync(recursive: true); | 142 new Directory(target).deleteSync(recursive: true); |
| 144 for (bool recursive in [true, false]) { | 143 for (bool recursive in [true, false]) { |
| 145 for (bool followLinks in [true, false]) { | 144 for (bool followLinks in [true, false]) { |
| 146 var result = baseDir.listSync(recursive: recursive, | 145 var result = baseDir.listSync(recursive: recursive, |
| 147 followLinks: followLinks); | 146 followLinks: followLinks); |
| 148 Expect.equals(1, result.length); | 147 Expect.equals(1, result.length); |
| 149 Expect.isTrue(result[0] is Link); | 148 Expect.isTrue(result[0] is Link); |
| 150 } | 149 } |
| 151 } | 150 } |
| 152 baseDir.deleteSync(recursive: true); | 151 baseDir.deleteSync(recursive: true); |
| 152 asyncEnd(); |
| 153 }); | 153 }); |
| 154 } | 154 } |
| 155 | 155 |
| 156 testCreateLoopingLink() { | 156 testCreateLoopingLink() { |
| 157 asyncStart(); |
| 157 String base = Directory.systemTemp.createTempSync('dart_link').path; | 158 String base = Directory.systemTemp.createTempSync('dart_link').path; |
| 158 new Directory(join(base, 'a', 'b', 'c')).create(recursive: true) | 159 new Directory(join(base, 'a', 'b', 'c')).create(recursive: true) |
| 159 .then((_) => | 160 .then((_) => |
| 160 new Link(join(base, 'a', 'b', 'c', 'd')).create(join(base, 'a', 'b'))) | 161 new Link(join(base, 'a', 'b', 'c', 'd')).create(join(base, 'a', 'b'))) |
| 161 .then((_) => | 162 .then((_) => |
| 162 new Link(join(base, 'a', 'b', 'c', 'e')).create(join(base, 'a'))) | 163 new Link(join(base, 'a', 'b', 'c', 'e')).create(join(base, 'a'))) |
| 163 .then((_) => | 164 .then((_) => |
| 164 new Directory(join(base, 'a')) | 165 new Directory(join(base, 'a')) |
| 165 .list(recursive: true, followLinks: false) | 166 .list(recursive: true, followLinks: false) |
| 166 .last) | 167 .last) |
| 167 .then((_) => | 168 .then((_) => |
| 168 // This directory listing must terminate, even though it contains loops. | 169 // This directory listing must terminate, even though it contains loops. |
| 169 new Directory(join(base, 'a')) | 170 new Directory(join(base, 'a')) |
| 170 .list(recursive: true, followLinks: true) | 171 .list(recursive: true, followLinks: true) |
| 171 .last) | 172 .last) |
| 172 .then((_) => | 173 .then((_) => |
| 173 // This directory listing must terminate, even though it contains loops. | 174 // This directory listing must terminate, even though it contains loops. |
| 174 new Directory(join(base, 'a', 'b', 'c')) | 175 new Directory(join(base, 'a', 'b', 'c')) |
| 175 .list(recursive: true, followLinks: true) | 176 .list(recursive: true, followLinks: true) |
| 176 .last) | 177 .last) |
| 177 .then((_) => | 178 .whenComplete(() { |
| 178 new Directory(base).delete(recursive: true)); | 179 new Directory(base).deleteSync(recursive: true); |
| 180 asyncEnd(); |
| 181 }); |
| 179 } | 182 } |
| 180 | 183 |
| 181 testRenameSync() { | 184 testRenameSync() { |
| 182 testRename(String base, String target) { | 185 testRename(String base, String target) { |
| 183 Link link1 = new Link(join(base, 'c'))..createSync(target); | 186 Link link1 = new Link(join(base, 'c'))..createSync(target); |
| 184 Expect.isTrue(link1.existsSync()); | 187 Expect.isTrue(link1.existsSync()); |
| 185 Link link2 = link1.renameSync(join(base, 'd')); | 188 Link link2 = link1.renameSync(join(base, 'd')); |
| 186 Expect.isFalse(link1.existsSync()); | 189 Expect.isFalse(link1.existsSync()); |
| 187 Expect.isTrue(link2.existsSync()); | 190 Expect.isTrue(link2.existsSync()); |
| 188 link2.deleteSync(); | 191 link2.deleteSync(); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 tempDirectory.deleteSync(recursive: true); | 241 tempDirectory.deleteSync(recursive: true); |
| 239 } | 242 } |
| 240 | 243 |
| 241 main() { | 244 main() { |
| 242 testCreateSync(); | 245 testCreateSync(); |
| 243 testCreateLoopingLink(); | 246 testCreateLoopingLink(); |
| 244 testRenameSync(); | 247 testRenameSync(); |
| 245 testLinkErrorSync(); | 248 testLinkErrorSync(); |
| 246 testRelativeLinksSync(); | 249 testRelativeLinksSync(); |
| 247 } | 250 } |
| OLD | NEW |