| 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 "package:path/path.dart"; | 6 import "package:path/path.dart"; |
| 7 import "dart:async"; | 7 import "dart:async"; |
| 8 import "dart:io"; | 8 import "dart:io"; |
| 9 import "dart:isolate"; | 9 import "dart:isolate"; |
| 10 | 10 |
| 11 // Test the dart:io Link class. | 11 // Test the dart:io Link class. |
| 12 | 12 |
| 13 testCreateSync() { | 13 testCreateSync() { |
| 14 String base = new Directory('').createTempSync().path; | 14 String base = Directory.systemTemp.createTempSync('dart_link').path; |
| 15 if (isRelative(base)) { |
| 16 Expect.fail( |
| 17 'Link tests expect absolute paths to system temporary directories. ' |
| 18 'A relative path in TMPDIR gives relative paths to them.'); |
| 19 } |
| 15 String link = join(base, 'link'); | 20 String link = join(base, 'link'); |
| 16 String target = join(base, 'target'); | 21 String target = join(base, 'target'); |
| 17 new Directory(target).createSync(); | 22 new Directory(target).createSync(); |
| 23 print("link: $link"); |
| 24 print("target: $target"); |
| 18 new Link(link).createSync(target); | 25 new Link(link).createSync(target); |
| 19 | 26 return; |
| 20 Expect.equals(FileSystemEntityType.DIRECTORY, | 27 Expect.equals(FileSystemEntityType.DIRECTORY, |
| 21 FileSystemEntity.typeSync(link)); | 28 FileSystemEntity.typeSync(link)); |
| 22 Expect.equals(FileSystemEntityType.DIRECTORY, | 29 Expect.equals(FileSystemEntityType.DIRECTORY, |
| 23 FileSystemEntity.typeSync(target)); | 30 FileSystemEntity.typeSync(target)); |
| 24 Expect.equals(FileSystemEntityType.LINK, | 31 Expect.equals(FileSystemEntityType.LINK, |
| 25 FileSystemEntity.typeSync(link, followLinks: false)); | 32 FileSystemEntity.typeSync(link, followLinks: false)); |
| 26 Expect.equals(FileSystemEntityType.DIRECTORY, | 33 Expect.equals(FileSystemEntityType.DIRECTORY, |
| 27 FileSystemEntity.typeSync(target, followLinks: false)); | 34 FileSystemEntity.typeSync(target, followLinks: false)); |
| 28 Expect.isTrue(FileSystemEntity.isLinkSync(link)); | 35 Expect.isTrue(FileSystemEntity.isLinkSync(link)); |
| 29 Expect.isFalse(FileSystemEntity.isLinkSync(target)); | 36 Expect.isFalse(FileSystemEntity.isLinkSync(target)); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 followLinks: followLinks); | 147 followLinks: followLinks); |
| 141 Expect.equals(1, result.length); | 148 Expect.equals(1, result.length); |
| 142 Expect.isTrue(result[0] is Link); | 149 Expect.isTrue(result[0] is Link); |
| 143 } | 150 } |
| 144 } | 151 } |
| 145 baseDir.deleteSync(recursive: true); | 152 baseDir.deleteSync(recursive: true); |
| 146 }); | 153 }); |
| 147 } | 154 } |
| 148 | 155 |
| 149 testCreateLoopingLink() { | 156 testCreateLoopingLink() { |
| 150 String base = new Directory('').createTempSync().path; | 157 String base = Directory.systemTemp.createTempSync('dart_link').path; |
| 151 new Directory(join(base, 'a', 'b', 'c')).create(recursive: true) | 158 new Directory(join(base, 'a', 'b', 'c')).create(recursive: true) |
| 152 .then((_) => | 159 .then((_) => |
| 153 new Link(join(base, 'a', 'b', 'c', 'd')).create(join(base, 'a', 'b'))) | 160 new Link(join(base, 'a', 'b', 'c', 'd')).create(join(base, 'a', 'b'))) |
| 154 .then((_) => | 161 .then((_) => |
| 155 new Link(join(base, 'a', 'b', 'c', 'e')).create(join(base, 'a'))) | 162 new Link(join(base, 'a', 'b', 'c', 'e')).create(join(base, 'a'))) |
| 156 .then((_) => | 163 .then((_) => |
| 157 new Directory(join(base, 'a')) | 164 new Directory(join(base, 'a')) |
| 158 .list(recursive: true, followLinks: false) | 165 .list(recursive: true, followLinks: false) |
| 159 .last) | 166 .last) |
| 160 .then((_) => | 167 .then((_) => |
| (...skipping 14 matching lines...) Expand all Loading... |
| 175 testRename(String base, String target) { | 182 testRename(String base, String target) { |
| 176 Link link1 = new Link(join(base, 'c'))..createSync(target); | 183 Link link1 = new Link(join(base, 'c'))..createSync(target); |
| 177 Expect.isTrue(link1.existsSync()); | 184 Expect.isTrue(link1.existsSync()); |
| 178 Link link2 = link1.renameSync(join(base, 'd')); | 185 Link link2 = link1.renameSync(join(base, 'd')); |
| 179 Expect.isFalse(link1.existsSync()); | 186 Expect.isFalse(link1.existsSync()); |
| 180 Expect.isTrue(link2.existsSync()); | 187 Expect.isTrue(link2.existsSync()); |
| 181 link2.deleteSync(); | 188 link2.deleteSync(); |
| 182 Expect.isFalse(link2.existsSync()); | 189 Expect.isFalse(link2.existsSync()); |
| 183 } | 190 } |
| 184 | 191 |
| 185 Directory baseDir = new Directory('').createTempSync(); | 192 Directory baseDir = Directory.systemTemp.createTempSync('dart_link'); |
| 186 String base = baseDir.path; | 193 String base = baseDir.path; |
| 187 Directory dir = new Directory(join(base, 'a'))..createSync(); | 194 Directory dir = new Directory(join(base, 'a'))..createSync(); |
| 188 File file = new File(join(base, 'b'))..createSync(); | 195 File file = new File(join(base, 'b'))..createSync(); |
| 189 | 196 |
| 190 testRename(base, file.path); | 197 testRename(base, file.path); |
| 191 testRename(base, dir.path); | 198 testRename(base, dir.path); |
| 192 | 199 |
| 193 baseDir.deleteSync(recursive: true); | 200 baseDir.deleteSync(recursive: true); |
| 194 } | 201 } |
| 195 | 202 |
| 196 void testLinkErrorSync() { | 203 void testLinkErrorSync() { |
| 197 Expect.throws(() => | 204 Expect.throws(() => |
| 198 new Link('some-dir-that-doent exist/some link file/bla/fisk').createSync( | 205 new Link('some-dir-that-doent exist/some link file/bla/fisk').createSync( |
| 199 'bla bla bla/b lalal/blfir/sdfred/es'), | 206 'bla bla bla/b lalal/blfir/sdfred/es'), |
| 200 (e) => e is LinkException); | 207 (e) => e is LinkException); |
| 201 } | 208 } |
| 202 | 209 |
| 203 checkExists(String filePath) => Expect.isTrue(new File(filePath).existsSync()); | 210 checkExists(String filePath) => Expect.isTrue(new File(filePath).existsSync()); |
| 204 | 211 |
| 205 testRelativeLinksSync() { | 212 testRelativeLinksSync() { |
| 206 Directory tempDirectory = new Directory('').createTempSync(); | 213 Directory tempDirectory = Directory.systemTemp.createTempSync('dart_link'); |
| 207 String temp = tempDirectory.path; | 214 String temp = tempDirectory.path; |
| 208 String oldWorkingDirectory = Directory.current.path; | 215 String oldWorkingDirectory = Directory.current.path; |
| 209 // Make directories and files to test links. | 216 // Make directories and files to test links. |
| 210 new Directory(join(temp, 'dir1', 'dir2')).createSync(recursive: true); | 217 new Directory(join(temp, 'dir1', 'dir2')).createSync(recursive: true); |
| 211 new File(join(temp, 'dir1', 'file1')).createSync(); | 218 new File(join(temp, 'dir1', 'file1')).createSync(); |
| 212 new File(join(temp, 'dir1', 'dir2', 'file2')).createSync(); | 219 new File(join(temp, 'dir1', 'dir2', 'file2')).createSync(); |
| 213 // Make links whose path and/or target is given by a relative path. | 220 // Make links whose path and/or target is given by a relative path. |
| 214 new Link(join(temp, 'dir1', 'link1_2')).createSync('dir2'); | 221 new Link(join(temp, 'dir1', 'link1_2')).createSync('dir2'); |
| 215 Directory.current = temp; | 222 Directory.current = temp; |
| 216 new Link('link0_2').createSync(join('dir1', 'dir2')); | 223 new Link('link0_2').createSync(join('dir1', 'dir2')); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 231 tempDirectory.deleteSync(recursive: true); | 238 tempDirectory.deleteSync(recursive: true); |
| 232 } | 239 } |
| 233 | 240 |
| 234 main() { | 241 main() { |
| 235 testCreateSync(); | 242 testCreateSync(); |
| 236 testCreateLoopingLink(); | 243 testCreateLoopingLink(); |
| 237 testRenameSync(); | 244 testRenameSync(); |
| 238 testLinkErrorSync(); | 245 testLinkErrorSync(); |
| 239 testRelativeLinksSync(); | 246 testRelativeLinksSync(); |
| 240 } | 247 } |
| OLD | NEW |