| 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"; |
| 11 | 11 |
| 12 // Test the dart:io Link class. | 12 // Test the dart:io Link class. |
| 13 | 13 |
| 14 class FutureExpect { | 14 class FutureExpect { |
| 15 static Future isTrue(Future<bool> result) => | 15 static Future isTrue(Future<bool> result) => |
| 16 result.then((value) => Expect.isTrue(value)); | 16 result.then((value) => Expect.isTrue(value)); |
| 17 static Future isFalse(Future<bool> result) => | 17 static Future isFalse(Future<bool> result) => |
| 18 result.then((value) => Expect.isFalse(value)); | 18 result.then((value) => Expect.isFalse(value)); |
| 19 static Future equals(expected, Future result) => | 19 static Future equals(expected, Future result) => |
| 20 result.then((value) => Expect.equals(expected, value)); | 20 result.then((value) => Expect.equals(expected, value)); |
| 21 static Future listEquals(expected, Future result) => | 21 static Future listEquals(expected, Future result) => |
| 22 result.then((value) => Expect.listEquals(expected, value)); | 22 result.then((value) => Expect.listEquals(expected, value)); |
| 23 static Future throws(Future result) => | 23 static Future throws(Future result) => result.then((value) { |
| 24 result.then((value) { | |
| 25 throw new ExpectException( | 24 throw new ExpectException( |
| 26 "FutureExpect.throws received $value instead of an exception"); | 25 "FutureExpect.throws received $value instead of an exception"); |
| 27 }, onError: (_) => null); | 26 }, onError: (_) => null); |
| 28 } | 27 } |
| 29 | 28 |
| 30 | |
| 31 Future testCreate() { | 29 Future testCreate() { |
| 32 return Directory.systemTemp.createTemp('dart_link_async').then((baseDir) { | 30 return Directory.systemTemp.createTemp('dart_link_async').then((baseDir) { |
| 33 if (isRelative(baseDir.path)) { | 31 if (isRelative(baseDir.path)) { |
| 34 Expect.fail( | 32 Expect.fail( |
| 35 'Link tests expect absolute paths to system temporary directories. ' | 33 'Link tests expect absolute paths to system temporary directories. ' |
| 36 'A relative path in TMPDIR gives relative paths to them.'); | 34 'A relative path in TMPDIR gives relative paths to them.'); |
| 37 } | 35 } |
| 38 String base = baseDir.path; | 36 String base = baseDir.path; |
| 39 String link = join(base, 'link'); | 37 String link = join(base, 'link'); |
| 40 String target = join(base, 'target'); | 38 String target = join(base, 'target'); |
| 41 return new Directory(target).create() | 39 return new Directory(target) |
| 42 .then((_) => new Link(link).create(target)) | 40 .create() |
| 43 | 41 .then((_) => new Link(link).create(target)) |
| 44 .then((_) => FutureExpect.equals(FileSystemEntityType.DIRECTORY, | 42 .then((_) => FutureExpect.equals( |
| 45 FileSystemEntity.type(link))) | 43 FileSystemEntityType.DIRECTORY, FileSystemEntity.type(link))) |
| 46 .then((_) => FutureExpect.equals(FileSystemEntityType.DIRECTORY, | 44 .then((_) => FutureExpect.equals( |
| 47 FileSystemEntity.type(target))) | 45 FileSystemEntityType.DIRECTORY, FileSystemEntity.type(target))) |
| 48 .then((_) => FutureExpect.equals(FileSystemEntityType.LINK, | 46 .then((_) => FutureExpect.equals(FileSystemEntityType.LINK, |
| 49 FileSystemEntity.type(link, followLinks: false))) | 47 FileSystemEntity.type(link, followLinks: false))) |
| 50 .then((_) => FutureExpect.equals(FileSystemEntityType.DIRECTORY, | 48 .then((_) => FutureExpect.equals(FileSystemEntityType.DIRECTORY, |
| 51 FileSystemEntity.type(target, followLinks: false))) | 49 FileSystemEntity.type(target, followLinks: false))) |
| 52 .then((_) => FutureExpect.isTrue(FileSystemEntity.isLink(link))) | 50 .then((_) => FutureExpect.isTrue(FileSystemEntity.isLink(link))) |
| 53 .then((_) => FutureExpect.isFalse(FileSystemEntity.isLink(target))) | 51 .then((_) => FutureExpect.isFalse(FileSystemEntity.isLink(target))) |
| 54 .then((_) => FutureExpect.isTrue(new Directory(link).exists())) | 52 .then((_) => FutureExpect.isTrue(new Directory(link).exists())) |
| 55 .then((_) => FutureExpect.isTrue(new Directory(target).exists())) | 53 .then((_) => FutureExpect.isTrue(new Directory(target).exists())) |
| 56 .then((_) => FutureExpect.isTrue(new Link(link).exists())) | 54 .then((_) => FutureExpect.isTrue(new Link(link).exists())) |
| 57 .then((_) => FutureExpect.isFalse(new Link(target).exists())) | 55 .then((_) => FutureExpect.isFalse(new Link(target).exists())) |
| 58 .then((_) => FutureExpect.equals(target, new Link(link).target())) | 56 .then((_) => FutureExpect.equals(target, new Link(link).target())) |
| 59 .then((_) => FutureExpect.throws(new Link(target).target())) | 57 .then((_) => FutureExpect.throws(new Link(target).target())) |
| 60 .then((_) { | 58 .then((_) { |
| 61 String createdThroughLink = join(base, 'link', 'createdThroughLink'); | 59 String createdThroughLink = join(base, 'link', 'createdThroughLink'); |
| 62 String createdDirectly = join(base, 'target', 'createdDirectly'); | 60 String createdDirectly = join(base, 'target', 'createdDirectly'); |
| 63 String createdFile = join(base, 'link', 'createdFile'); | 61 String createdFile = join(base, 'link', 'createdFile'); |
| 64 return new Directory(createdThroughLink).create() | 62 return new Directory(createdThroughLink) |
| 65 .then((_) => new Directory(createdDirectly).create()) | 63 .create() |
| 66 .then((_) => new File(createdFile).create()) | 64 .then((_) => new Directory(createdDirectly).create()) |
| 67 .then((_) => FutureExpect.isTrue( | 65 .then((_) => new File(createdFile).create()) |
| 68 new Directory(createdThroughLink).exists())) | 66 .then((_) => |
| 69 .then((_) => FutureExpect.isTrue( | 67 FutureExpect.isTrue(new Directory(createdThroughLink).exists())) |
| 70 new Directory(createdDirectly).exists())) | 68 .then((_) => |
| 71 .then((_) => FutureExpect.isTrue( | 69 FutureExpect.isTrue(new Directory(createdDirectly).exists())) |
| 72 new Directory(join(base, 'link', 'createdDirectly')).exists())) | 70 .then((_) => FutureExpect.isTrue( |
| 73 .then((_) => FutureExpect.isTrue( | 71 new Directory(join(base, 'link', 'createdDirectly')).exists())) |
| 74 new Directory(join(base, 'target', 'createdThroughLink')).exists())) | 72 .then((_) => FutureExpect.isTrue( |
| 75 .then((_) => FutureExpect.equals(FileSystemEntityType.DIRECTORY, | 73 new Directory(join(base, 'target', 'createdThroughLink')) |
| 76 FileSystemEntity.type(createdThroughLink, followLinks: false))) | 74 .exists())) |
| 77 .then((_) => FutureExpect.equals(FileSystemEntityType.DIRECTORY, | 75 .then((_) => FutureExpect.equals(FileSystemEntityType.DIRECTORY, |
| 78 FileSystemEntity.type(createdDirectly, followLinks: false))) | 76 FileSystemEntity.type(createdThroughLink, followLinks: false))) |
| 77 .then((_) => FutureExpect.equals(FileSystemEntityType.DIRECTORY, |
| 78 FileSystemEntity.type(createdDirectly, followLinks: false))) |
| 79 | 79 |
| 80 // Test FileSystemEntity.identical on files, directories, and links, | 80 // Test FileSystemEntity.identical on files, directories, and links, |
| 81 // reached by different paths. | 81 // reached by different paths. |
| 82 .then((_) => FutureExpect.isTrue(FileSystemEntity.identical( | 82 .then((_) => FutureExpect.isTrue(FileSystemEntity.identical(createdDir
ectly, createdDirectly))) |
| 83 createdDirectly, | 83 .then((_) => FutureExpect.isFalse(FileSystemEntity.identical(createdDi
rectly, createdThroughLink))) |
| 84 createdDirectly))) | 84 .then((_) => FutureExpect.isTrue(FileSystemEntity.identical(createdDir
ectly, join(base, 'link', 'createdDirectly')))) |
| 85 .then((_) => FutureExpect.isFalse(FileSystemEntity.identical( | 85 .then((_) => FutureExpect.isTrue(FileSystemEntity.identical(createdThr
oughLink, join(base, 'target', 'createdThroughLink')))) |
| 86 createdDirectly, | 86 .then((_) => FutureExpect.isFalse(FileSystemEntity.identical(target, l
ink))) |
| 87 createdThroughLink))) | 87 .then((_) => FutureExpect.isTrue(FileSystemEntity.identical(link, link
))) |
| 88 .then((_) => FutureExpect.isTrue(FileSystemEntity.identical( | 88 .then((_) => FutureExpect.isTrue(FileSystemEntity.identical(target, ta
rget))) |
| 89 createdDirectly, | 89 .then((_) => new Link(link).target()) |
| 90 join(base, 'link', 'createdDirectly')))) | 90 .then((linkTarget) => FutureExpect.isTrue(FileSystemEntity.identical(t
arget, linkTarget))) |
| 91 .then((_) => FutureExpect.isTrue(FileSystemEntity.identical( | 91 .then((_) => new File(".").resolveSymbolicLinks()) |
| 92 createdThroughLink, | 92 .then((fullCurrentDir) => FutureExpect.isTrue(FileSystemEntity.identic
al(".", fullCurrentDir))) |
| 93 join(base, 'target', 'createdThroughLink')))) | 93 .then((_) => FutureExpect.isTrue(FileSystemEntity.identical(createdFil
e, createdFile))) |
| 94 .then((_) => FutureExpect.isFalse(FileSystemEntity.identical( | 94 .then((_) => FutureExpect.isFalse(FileSystemEntity.identical(createdFi
le, createdDirectly))) |
| 95 target, | 95 .then((_) => FutureExpect.isTrue(FileSystemEntity.identical(createdFil
e, join(base, 'link', 'createdFile')))) |
| 96 link))) | 96 .then((_) => FutureExpect.throws(FileSystemEntity.identical(createdFil
e, join(base, 'link', 'does_not_exist')))) |
| 97 .then((_) => FutureExpect.isTrue(FileSystemEntity.identical( | 97 .then((_) => testDirectoryListing(base, baseDir)) |
| 98 link, | 98 .then((_) => new Directory(target).delete(recursive: true)) |
| 99 link))) | 99 .then((_) { |
| 100 .then((_) => FutureExpect.isTrue(FileSystemEntity.identical( | |
| 101 target, | |
| 102 target))) | |
| 103 .then((_) => new Link(link).target()) | |
| 104 .then((linkTarget) => FutureExpect.isTrue(FileSystemEntity.identical( | |
| 105 target, | |
| 106 linkTarget))) | |
| 107 .then((_) => new File(".").resolveSymbolicLinks()) | |
| 108 .then((fullCurrentDir) => FutureExpect.isTrue(FileSystemEntity.identical( | |
| 109 ".", | |
| 110 fullCurrentDir))) | |
| 111 .then((_) => FutureExpect.isTrue(FileSystemEntity.identical( | |
| 112 createdFile, | |
| 113 createdFile))) | |
| 114 .then((_) => FutureExpect.isFalse(FileSystemEntity.identical( | |
| 115 createdFile, | |
| 116 createdDirectly))) | |
| 117 .then((_) => FutureExpect.isTrue(FileSystemEntity.identical( | |
| 118 createdFile, | |
| 119 join(base, 'link', 'createdFile')))) | |
| 120 .then((_) => FutureExpect.throws(FileSystemEntity.identical( | |
| 121 createdFile, | |
| 122 join(base, 'link', 'does_not_exist')))) | |
| 123 | |
| 124 .then((_) => testDirectoryListing(base, baseDir)) | |
| 125 .then((_) => new Directory(target).delete(recursive: true)) | |
| 126 .then((_) { | |
| 127 List<Future> futures = []; | 100 List<Future> futures = []; |
| 128 for (bool recursive in [true, false]) { | 101 for (bool recursive in [true, false]) { |
| 129 for (bool followLinks in [true, false]) { | 102 for (bool followLinks in [true, false]) { |
| 130 var result = baseDir.listSync(recursive: recursive, | 103 var result = baseDir.listSync( |
| 131 followLinks: followLinks); | 104 recursive: recursive, followLinks: followLinks); |
| 132 Expect.equals(1, result.length); | 105 Expect.equals(1, result.length); |
| 133 Expect.isTrue(result[0] is Link); | 106 Expect.isTrue(result[0] is Link); |
| 134 futures.add(FutureExpect.isTrue( | 107 futures.add(FutureExpect.isTrue(baseDir |
| 135 baseDir.list(recursive: recursive, | 108 .list(recursive: recursive, followLinks: followLinks) |
| 136 followLinks: followLinks) | 109 .single |
| 137 .single.then((element) => element is Link))); | 110 .then((element) => element is Link))); |
| 138 } | 111 } |
| 139 } | 112 } |
| 140 return Future.wait(futures); | 113 return Future.wait(futures); |
| 141 }) | 114 }).then((_) => baseDir.delete(recursive: true)); |
| 142 .then((_) => baseDir.delete(recursive: true)); | |
| 143 }); | 115 }); |
| 144 }); | 116 }); |
| 145 } | 117 } |
| 146 | 118 |
| 147 | |
| 148 Future testCreateLoopingLink(_) { | 119 Future testCreateLoopingLink(_) { |
| 149 return Directory.systemTemp.createTemp('dart_link_async') | 120 return Directory.systemTemp |
| 150 .then((dir) => dir.path) | 121 .createTemp('dart_link_async') |
| 151 .then((String base) => | 122 .then((dir) => dir.path) |
| 152 new Directory(join(base, 'a', 'b', 'c')).create(recursive: true) | 123 .then((String base) => new Directory(join(base, 'a', 'b', 'c')) |
| 153 .then((_) => new Link(join(base, 'a', 'b', 'c', 'd')) | 124 .create(recursive: true) |
| 154 .create(join(base, 'a', 'b'))) | 125 .then((_) => new Link(join(base, 'a', 'b', 'c', 'd')) |
| 155 .then((_) => new Link(join(base, 'a', 'b', 'c', 'e')) | 126 .create(join(base, 'a', 'b'))) |
| 156 .create(join(base, 'a'))) | 127 .then((_) => |
| 157 .then((_) => new Directory(join(base, 'a')) | 128 new Link(join(base, 'a', 'b', 'c', 'e')).create(join(base, 'a'))) |
| 158 .list(recursive: true, followLinks: false).last) | 129 .then((_) => new Directory(join(base, 'a')) |
| 159 // This directory listing must terminate, even though it contains loops. | 130 .list(recursive: true, followLinks: false) |
| 160 .then((_) => new Directory(join(base, 'a')) | 131 .last) |
| 161 .list(recursive: true, followLinks: true).last) | 132 // This directory listing must terminate, even though it contains loop
s. |
| 162 // This directory listing must terminate, even though it contains loops. | 133 .then((_) => new Directory(join(base, 'a')) |
| 163 .then((_) => new Directory(join(base, 'a', 'b', 'c')) | 134 .list(recursive: true, followLinks: true) |
| 164 .list(recursive: true, followLinks: true).last) | 135 .last) |
| 165 .then((_) => new Directory(base).delete(recursive: true)) | 136 // This directory listing must terminate, even though it contains loop
s. |
| 166 .then((_) => FutureExpect.isFalse(new Directory(base).exists())) | 137 .then((_) => new Directory(join(base, 'a', 'b', 'c')) |
| 167 ); | 138 .list(recursive: true, followLinks: true) |
| 139 .last) |
| 140 .then((_) => new Directory(base).delete(recursive: true)) |
| 141 .then((_) => FutureExpect.isFalse(new Directory(base).exists()))); |
| 168 } | 142 } |
| 169 | 143 |
| 170 | |
| 171 Future testRename(_) { | 144 Future testRename(_) { |
| 172 Future testRename(String base , String target) { | 145 Future testRename(String base, String target) { |
| 173 Link link1; | 146 Link link1; |
| 174 Link link2; | 147 Link link2; |
| 175 return new Link(join(base, 'c')).create(target) | 148 return new Link(join(base, 'c')).create(target).then((link) { |
| 176 .then((link) { | |
| 177 link1 = link; | 149 link1 = link; |
| 178 Expect.isTrue(link1.existsSync()); | 150 Expect.isTrue(link1.existsSync()); |
| 179 return link1.rename(join(base, 'd')); | 151 return link1.rename(join(base, 'd')); |
| 180 }) | 152 }).then((link) { |
| 181 .then((link) { | |
| 182 link2 = link; | 153 link2 = link; |
| 183 Expect.isFalse(link1.existsSync()); | 154 Expect.isFalse(link1.existsSync()); |
| 184 Expect.isTrue(link2.existsSync()); | 155 Expect.isTrue(link2.existsSync()); |
| 185 return link2.delete(); | 156 return link2.delete(); |
| 186 }) | 157 }).then((_) => Expect.isFalse(link2.existsSync())); |
| 187 .then((_) => Expect.isFalse(link2.existsSync())); | |
| 188 } | 158 } |
| 189 | 159 |
| 190 Future testUpdate(String base , String target1, String target2) { | 160 Future testUpdate(String base, String target1, String target2) { |
| 191 Link link1; | 161 Link link1; |
| 192 return new Link(join(base, 'c')).create(target1) | 162 return new Link(join(base, 'c')).create(target1).then((link) { |
| 193 .then((link) { | |
| 194 link1 = link; | 163 link1 = link; |
| 195 Expect.isTrue(link1.existsSync()); | 164 Expect.isTrue(link1.existsSync()); |
| 196 return link1.update(target2); | 165 return link1.update(target2); |
| 197 }) | 166 }).then((Link link) { |
| 198 .then((Link link) { | |
| 199 Expect.isTrue(link1.existsSync()); | 167 Expect.isTrue(link1.existsSync()); |
| 200 Expect.isTrue(link.existsSync()); | 168 Expect.isTrue(link.existsSync()); |
| 201 return FutureExpect.equals(target2, link.target()) | 169 return FutureExpect |
| 202 .then((_) => FutureExpect.equals(target2, link1.target())) | 170 .equals(target2, link.target()) |
| 203 .then((_) => link.delete()); | 171 .then((_) => FutureExpect.equals(target2, link1.target())) |
| 204 }) | 172 .then((_) => link.delete()); |
| 205 .then((_) => Expect.isFalse(link1.existsSync())); | 173 }).then((_) => Expect.isFalse(link1.existsSync())); |
| 206 } | 174 } |
| 207 | 175 |
| 208 return Directory.systemTemp.createTemp('dart_link_async').then((baseDir) { | 176 return Directory.systemTemp.createTemp('dart_link_async').then((baseDir) { |
| 209 String base = baseDir.path; | 177 String base = baseDir.path; |
| 210 var targetsFutures = []; | 178 var targetsFutures = []; |
| 211 targetsFutures.add(new Directory(join(base, 'a')).create()); | 179 targetsFutures.add(new Directory(join(base, 'a')).create()); |
| 212 if (Platform.isWindows) { | 180 if (Platform.isWindows) { |
| 213 // Currently only links to directories are supported on Windows. | 181 // Currently only links to directories are supported on Windows. |
| 214 targetsFutures.add( | 182 targetsFutures.add(new Directory(join(base, 'b')).create()); |
| 215 new Directory(join(base, 'b')).create()); | |
| 216 } else { | 183 } else { |
| 217 targetsFutures.add(new File(join(base, 'b')).create()); | 184 targetsFutures.add(new File(join(base, 'b')).create()); |
| 218 } | 185 } |
| 219 return Future.wait(targetsFutures).then((targets) { | 186 return Future.wait(targetsFutures).then((targets) { |
| 220 return testRename(base, targets[0].path) | 187 return testRename(base, targets[0].path) |
| 221 .then((_) => testRename(base, targets[1].path)) | 188 .then((_) => testRename(base, targets[1].path)) |
| 222 .then((_) => testUpdate(base, targets[0].path, targets[1].path)) | 189 .then((_) => testUpdate(base, targets[0].path, targets[1].path)) |
| 223 .then((_) => baseDir.delete(recursive: true)); | 190 .then((_) => baseDir.delete(recursive: true)); |
| 224 }); | 191 }); |
| 225 }); | 192 }); |
| 226 } | 193 } |
| 227 | 194 |
| 228 Future testDirectoryListing(String base, Directory baseDir) { | 195 Future testDirectoryListing(String base, Directory baseDir) { |
| 229 Map makeExpected(bool recursive, bool followLinks) { | 196 Map makeExpected(bool recursive, bool followLinks) { |
| 230 Map expected = new Map(); | 197 Map expected = new Map(); |
| 231 expected['target'] = 'Directory'; | 198 expected['target'] = 'Directory'; |
| 232 expected['link'] = followLinks ? 'Directory' : 'Link'; | 199 expected['link'] = followLinks ? 'Directory' : 'Link'; |
| 233 if (recursive) { | 200 if (recursive) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 247 String ending = relative(x.path, from: base); | 214 String ending = relative(x.path, from: base); |
| 248 Expect.isNotNull(expected[ending]); | 215 Expect.isNotNull(expected[ending]); |
| 249 Expect.isTrue(x.toString().startsWith(expected[ending])); | 216 Expect.isTrue(x.toString().startsWith(expected[ending])); |
| 250 expected[ending] = 'Found'; | 217 expected[ending] = 'Found'; |
| 251 } | 218 } |
| 252 | 219 |
| 253 List futures = []; | 220 List futures = []; |
| 254 for (bool recursive in [true, false]) { | 221 for (bool recursive in [true, false]) { |
| 255 for (bool followLinks in [true, false]) { | 222 for (bool followLinks in [true, false]) { |
| 256 Map expected = makeExpected(recursive, followLinks); | 223 Map expected = makeExpected(recursive, followLinks); |
| 257 for (var x in baseDir.listSync(recursive: recursive, | 224 for (var x |
| 258 followLinks: followLinks)) { | 225 in baseDir.listSync(recursive: recursive, followLinks: followLinks)) { |
| 259 checkEntity(x, expected); | 226 checkEntity(x, expected); |
| 260 } | 227 } |
| 261 for (var v in expected.values) { | 228 for (var v in expected.values) { |
| 262 Expect.equals('Found', v); | 229 Expect.equals('Found', v); |
| 263 } | 230 } |
| 264 expected = makeExpected(recursive, followLinks); | 231 expected = makeExpected(recursive, followLinks); |
| 265 futures.add( | 232 futures.add(baseDir |
| 266 baseDir.list(recursive: recursive, followLinks: followLinks) | 233 .list(recursive: recursive, followLinks: followLinks) |
| 267 .forEach((entity) => checkEntity(entity, expected)) | 234 .forEach((entity) => checkEntity(entity, expected)) |
| 268 .then((_) { | 235 .then((_) { |
| 269 for (var v in expected.values) { | 236 for (var v in expected.values) { |
| 270 Expect.equals('Found', v); | 237 Expect.equals('Found', v); |
| 271 } | 238 } |
| 272 }) | 239 })); |
| 273 ); | |
| 274 } | 240 } |
| 275 } | 241 } |
| 276 return Future.wait(futures); | 242 return Future.wait(futures); |
| 277 } | 243 } |
| 278 | 244 |
| 279 Future checkExists(String filePath) => | 245 Future checkExists(String filePath) => |
| 280 new File(filePath).exists().then(Expect.isTrue); | 246 new File(filePath).exists().then(Expect.isTrue); |
| 281 | 247 |
| 282 Future testRelativeLinks(_) { | 248 Future testRelativeLinks(_) { |
| 283 return Directory.systemTemp | 249 return Directory.systemTemp |
| 284 .createTemp('dart_link_async') | 250 .createTemp('dart_link_async') |
| 285 .then((tempDirectory) { | 251 .then((tempDirectory) { |
| 286 String temp = tempDirectory.path; | 252 String temp = tempDirectory.path; |
| 287 String oldWorkingDirectory = Directory.current.path; | 253 String oldWorkingDirectory = Directory.current.path; |
| 288 // Make directories and files to test links. | 254 // Make directories and files to test links. |
| 289 return new Directory(join(temp, 'dir1', 'dir2')).create(recursive: true) | 255 return new Directory(join(temp, 'dir1', 'dir2')) |
| 290 .then((_) => new File(join(temp, 'dir1', 'file1')).create()) | 256 .create(recursive: true) |
| 291 .then((_) => new File(join(temp, 'dir1', 'dir2', 'file2')).create()) | 257 .then((_) => new File(join(temp, 'dir1', 'file1')).create()) |
| 292 // Make links whose path and/or target is given by a relative path. | 258 .then((_) => new File(join(temp, 'dir1', 'dir2', 'file2')).create()) |
| 293 .then((_) => new Link(join(temp, 'dir1', 'link1_2')).create('dir2')) | 259 // Make links whose path and/or target is given by a relative path. |
| 294 .then((_) => Directory.current = temp) | 260 .then((_) => new Link(join(temp, 'dir1', 'link1_2')).create('dir2')) |
| 295 .then((_) => new Link('link0_2').create(join('dir1', 'dir2'))) | 261 .then((_) => Directory.current = temp) |
| 296 .then((_) => new Link(join('dir1', 'link1_0')).create('..')) | 262 .then((_) => new Link('link0_2').create(join('dir1', 'dir2'))) |
| 297 .then((_) => Directory.current = 'dir1') | 263 .then((_) => new Link(join('dir1', 'link1_0')).create('..')) |
| 298 .then((_) => new Link(join('..', 'link0_1')).create('dir1')) | 264 .then((_) => Directory.current = 'dir1') |
| 299 .then((_) => new Link(join('dir2', 'link2_1')).create(join(temp, 'dir1'))) | 265 .then((_) => new Link(join('..', 'link0_1')).create('dir1')) |
| 300 .then((_) => new Link(join(temp, 'dir1', 'dir2', 'link2_0')) | 266 .then( |
| 301 .create(join('..', '..'))) | 267 (_) => new Link(join('dir2', 'link2_1')).create(join(temp, 'dir1'))) |
| 302 // Test that the links go to the right targets. | 268 .then((_) => new Link(join(temp, 'dir1', 'dir2', 'link2_0')) |
| 303 .then((_) => checkExists(join('..', 'link0_1', 'file1'))) | 269 .create(join('..', '..'))) |
| 304 .then((_) => checkExists(join('..', 'link0_2', 'file2'))) | 270 // Test that the links go to the right targets. |
| 305 .then((_) => checkExists(join('link1_0', 'dir1', 'file1'))) | 271 .then((_) => checkExists(join('..', 'link0_1', 'file1'))) |
| 306 .then((_) => checkExists(join('link1_2', 'file2'))) | 272 .then((_) => checkExists(join('..', 'link0_2', 'file2'))) |
| 307 .then((_) => checkExists(join('dir2', 'link2_0', 'dir1', 'file1'))) | 273 .then((_) => checkExists(join('link1_0', 'dir1', 'file1'))) |
| 308 .then((_) => checkExists(join('dir2', 'link2_1', 'file1'))) | 274 .then((_) => checkExists(join('link1_2', 'file2'))) |
| 309 // Clean up | 275 .then((_) => checkExists(join('dir2', 'link2_0', 'dir1', 'file1'))) |
| 310 .whenComplete(() => Directory.current = oldWorkingDirectory) | 276 .then((_) => checkExists(join('dir2', 'link2_1', 'file1'))) |
| 311 .whenComplete(() => tempDirectory.delete(recursive: true)); | 277 // Clean up |
| 278 .whenComplete(() => Directory.current = oldWorkingDirectory) |
| 279 .whenComplete(() => tempDirectory.delete(recursive: true)); |
| 312 }); | 280 }); |
| 313 } | 281 } |
| 314 | 282 |
| 315 main() { | 283 main() { |
| 316 asyncStart(); | 284 asyncStart(); |
| 317 testCreate() | 285 testCreate() |
| 318 .then(testCreateLoopingLink) | 286 .then(testCreateLoopingLink) |
| 319 .then(testRename) | 287 .then(testRename) |
| 320 .then(testRelativeLinks) | 288 .then(testRelativeLinks) |
| 321 .then((_) => asyncEnd()); | 289 .then((_) => asyncEnd()); |
| 322 } | 290 } |
| OLD | NEW |