OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 import "dart:async"; |
| 6 import 'package:expect/expect.dart'; |
| 7 import "dart:io"; |
| 8 import "dart:isolate"; |
| 9 |
| 10 |
| 11 class FutureExpect { |
| 12 static Future isTrue(Future<bool> result) => |
| 13 result.then((value) => Expect.isTrue(value)); |
| 14 static Future isFalse(Future<bool> result) => |
| 15 result.then((value) => Expect.isFalse(value)); |
| 16 static Future equals(expected, Future result) => |
| 17 result.then((value) => Expect.equals(expected, value)); |
| 18 static Future listEquals(expected, Future result) => |
| 19 result.then((value) => Expect.listEquals(expected, value)); |
| 20 static Future throws(Future result) => |
| 21 result.then((value) { |
| 22 throw new ExpectException( |
| 23 "FutureExpect.throws received $value instead of an exception"); |
| 24 }, onError: (_) => null); |
| 25 } |
| 26 |
| 27 |
| 28 Future testJunctionTypeDelete() { |
| 29 return new Directory('').createTemp().then((temp) { |
| 30 var x = '${temp.path}${Platform.pathSeparator}x'; |
| 31 var y = '${temp.path}${Platform.pathSeparator}y'; |
| 32 return new Directory(x).create() |
| 33 .then((_) => new Link(y).create(x)) |
| 34 .then((_) => FutureExpect.isTrue(new Directory(y).exists())) |
| 35 .then((_) => FutureExpect.isTrue(new Directory(x).exists())) |
| 36 .then((_) => FutureExpect.isTrue(FileSystemEntity.isLink(y))) |
| 37 .then((_) => FutureExpect.isFalse(FileSystemEntity.isLink(x))) |
| 38 .then((_) => FutureExpect.isTrue(FileSystemEntity.isDirectory(y))) |
| 39 .then((_) => FutureExpect.isTrue(FileSystemEntity.isDirectory(x))) |
| 40 .then((_) => FutureExpect.equals(FileSystemEntityType.DIRECTORY, |
| 41 FileSystemEntity.type(y))) |
| 42 .then((_) => FutureExpect.equals(FileSystemEntityType.DIRECTORY, |
| 43 FileSystemEntity.type(x))) |
| 44 .then((_) => FutureExpect.equals(FileSystemEntityType.LINK, |
| 45 FileSystemEntity.type(y, followLinks: false))) |
| 46 .then((_) => FutureExpect.equals(FileSystemEntityType.DIRECTORY, |
| 47 FileSystemEntity.type(x, followLinks: false))) |
| 48 .then((_) => FutureExpect.equals(x, new Link(y).target())) |
| 49 |
| 50 // Test Junction pointing to a missing directory. |
| 51 .then((_) => new Directory(x).delete()) |
| 52 .then((_) => FutureExpect.isTrue(new Link(y).exists())) |
| 53 .then((_) => FutureExpect.isFalse(new Directory(x).exists())) |
| 54 .then((_) => FutureExpect.isTrue(FileSystemEntity.isLink(y))) |
| 55 .then((_) => FutureExpect.isFalse(FileSystemEntity.isLink(x))) |
| 56 .then((_) => FutureExpect.isFalse(FileSystemEntity.isDirectory(y))) |
| 57 .then((_) => FutureExpect.isFalse(FileSystemEntity.isDirectory(x))) |
| 58 .then((_) => FutureExpect.equals(FileSystemEntityType.LINK, |
| 59 FileSystemEntity.type(y))) |
| 60 .then((_) => FutureExpect.equals(FileSystemEntityType.NOT_FOUND, |
| 61 FileSystemEntity.type(x))) |
| 62 .then((_) => FutureExpect.equals(FileSystemEntityType.LINK, |
| 63 FileSystemEntity.type(y, followLinks: false))) |
| 64 .then((_) => FutureExpect.equals(FileSystemEntityType.NOT_FOUND, |
| 65 FileSystemEntity.type(x, followLinks: false))) |
| 66 .then((_) => FutureExpect.equals(x, new Link(y).target())) |
| 67 |
| 68 // Delete Junction pointing to a missing directory. |
| 69 .then((_) => new Link(y).delete()) |
| 70 .then((_) => FutureExpect.isFalse(FileSystemEntity.isLink(y))) |
| 71 .then((_) => FutureExpect.equals(FileSystemEntityType.NOT_FOUND, |
| 72 FileSystemEntity.type(y))) |
| 73 .then((_) => FutureExpect.throws(new Link(y).target())) |
| 74 |
| 75 .then((_) => new Directory(x).create()) |
| 76 .then((_) => new Link(y).create(x)) |
| 77 .then((_) => FutureExpect.equals(FileSystemEntityType.LINK, |
| 78 FileSystemEntity.type(y, followLinks: false))) |
| 79 .then((_) => FutureExpect.equals(FileSystemEntityType.DIRECTORY, |
| 80 FileSystemEntity.type(x, followLinks: false))) |
| 81 .then((_) => FutureExpect.equals(x, new Link(y).target())) |
| 82 |
| 83 // Delete Junction pointing to an existing directory. |
| 84 .then((_) => new Directory(y).delete()) |
| 85 .then((_) => FutureExpect.equals(FileSystemEntityType.NOT_FOUND, |
| 86 FileSystemEntity.type(y))) |
| 87 .then((_) => FutureExpect.equals(FileSystemEntityType.NOT_FOUND, |
| 88 FileSystemEntity.type(y, followLinks: false))) |
| 89 .then((_) => FutureExpect.equals(FileSystemEntityType.DIRECTORY, |
| 90 FileSystemEntity.type(x))) |
| 91 .then((_) => FutureExpect.equals(FileSystemEntityType.DIRECTORY, |
| 92 FileSystemEntity.type(x, followLinks: false))) |
| 93 .then((_) => FutureExpect.throws(new Link(y).target())) |
| 94 .then((_) => temp.delete(recursive: true)); |
| 95 }); |
| 96 } |
| 97 |
| 98 |
| 99 main() { |
| 100 // Links on other platforms are tested by file_system_[async_]links_test. |
| 101 if (Platform.operatingSystem == 'windows') { |
| 102 ReceivePort keepAlive = new ReceivePort(); |
| 103 testJunctionTypeDelete().then((_) => keepAlive.close()); |
| 104 } |
| 105 } |
OLD | NEW |