Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(484)

Unified Diff: tests/standalone/io/link_async_test.dart

Issue 2771453003: Format all tests. (Closed)
Patch Set: Format files Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tests/standalone/io/link_async_test.dart
diff --git a/tests/standalone/io/link_async_test.dart b/tests/standalone/io/link_async_test.dart
index 9968c66cfcc2c38bd9a473df91733d7014e7efb9..9a42177447310f57752b7a8c6542c0f627e81e8f 100644
--- a/tests/standalone/io/link_async_test.dart
+++ b/tests/standalone/io/link_async_test.dart
@@ -20,14 +20,12 @@ class FutureExpect {
result.then((value) => Expect.equals(expected, value));
static Future listEquals(expected, Future result) =>
result.then((value) => Expect.listEquals(expected, value));
- static Future throws(Future result) =>
- result.then((value) {
+ static Future throws(Future result) => result.then((value) {
throw new ExpectException(
"FutureExpect.throws received $value instead of an exception");
- }, onError: (_) => null);
+ }, onError: (_) => null);
}
-
Future testCreate() {
return Directory.systemTemp.createTemp('dart_link_async').then((baseDir) {
if (isRelative(baseDir.path)) {
@@ -38,171 +36,141 @@ Future testCreate() {
String base = baseDir.path;
String link = join(base, 'link');
String target = join(base, 'target');
- return new Directory(target).create()
- .then((_) => new Link(link).create(target))
-
- .then((_) => FutureExpect.equals(FileSystemEntityType.DIRECTORY,
- FileSystemEntity.type(link)))
- .then((_) => FutureExpect.equals(FileSystemEntityType.DIRECTORY,
- FileSystemEntity.type(target)))
- .then((_) => FutureExpect.equals(FileSystemEntityType.LINK,
- FileSystemEntity.type(link, followLinks: false)))
- .then((_) => FutureExpect.equals(FileSystemEntityType.DIRECTORY,
- FileSystemEntity.type(target, followLinks: false)))
- .then((_) => FutureExpect.isTrue(FileSystemEntity.isLink(link)))
- .then((_) => FutureExpect.isFalse(FileSystemEntity.isLink(target)))
- .then((_) => FutureExpect.isTrue(new Directory(link).exists()))
- .then((_) => FutureExpect.isTrue(new Directory(target).exists()))
- .then((_) => FutureExpect.isTrue(new Link(link).exists()))
- .then((_) => FutureExpect.isFalse(new Link(target).exists()))
- .then((_) => FutureExpect.equals(target, new Link(link).target()))
- .then((_) => FutureExpect.throws(new Link(target).target()))
- .then((_) {
+ return new Directory(target)
+ .create()
+ .then((_) => new Link(link).create(target))
+ .then((_) => FutureExpect.equals(
+ FileSystemEntityType.DIRECTORY, FileSystemEntity.type(link)))
+ .then((_) => FutureExpect.equals(
+ FileSystemEntityType.DIRECTORY, FileSystemEntity.type(target)))
+ .then((_) => FutureExpect.equals(FileSystemEntityType.LINK,
+ FileSystemEntity.type(link, followLinks: false)))
+ .then((_) => FutureExpect.equals(FileSystemEntityType.DIRECTORY,
+ FileSystemEntity.type(target, followLinks: false)))
+ .then((_) => FutureExpect.isTrue(FileSystemEntity.isLink(link)))
+ .then((_) => FutureExpect.isFalse(FileSystemEntity.isLink(target)))
+ .then((_) => FutureExpect.isTrue(new Directory(link).exists()))
+ .then((_) => FutureExpect.isTrue(new Directory(target).exists()))
+ .then((_) => FutureExpect.isTrue(new Link(link).exists()))
+ .then((_) => FutureExpect.isFalse(new Link(target).exists()))
+ .then((_) => FutureExpect.equals(target, new Link(link).target()))
+ .then((_) => FutureExpect.throws(new Link(target).target()))
+ .then((_) {
String createdThroughLink = join(base, 'link', 'createdThroughLink');
String createdDirectly = join(base, 'target', 'createdDirectly');
String createdFile = join(base, 'link', 'createdFile');
- return new Directory(createdThroughLink).create()
- .then((_) => new Directory(createdDirectly).create())
- .then((_) => new File(createdFile).create())
- .then((_) => FutureExpect.isTrue(
- new Directory(createdThroughLink).exists()))
- .then((_) => FutureExpect.isTrue(
- new Directory(createdDirectly).exists()))
- .then((_) => FutureExpect.isTrue(
- new Directory(join(base, 'link', 'createdDirectly')).exists()))
- .then((_) => FutureExpect.isTrue(
- new Directory(join(base, 'target', 'createdThroughLink')).exists()))
- .then((_) => FutureExpect.equals(FileSystemEntityType.DIRECTORY,
- FileSystemEntity.type(createdThroughLink, followLinks: false)))
- .then((_) => FutureExpect.equals(FileSystemEntityType.DIRECTORY,
- FileSystemEntity.type(createdDirectly, followLinks: false)))
+ return new Directory(createdThroughLink)
+ .create()
+ .then((_) => new Directory(createdDirectly).create())
+ .then((_) => new File(createdFile).create())
+ .then((_) =>
+ FutureExpect.isTrue(new Directory(createdThroughLink).exists()))
+ .then((_) =>
+ FutureExpect.isTrue(new Directory(createdDirectly).exists()))
+ .then((_) => FutureExpect.isTrue(
+ new Directory(join(base, 'link', 'createdDirectly')).exists()))
+ .then((_) => FutureExpect.isTrue(
+ new Directory(join(base, 'target', 'createdThroughLink'))
+ .exists()))
+ .then((_) => FutureExpect.equals(FileSystemEntityType.DIRECTORY,
+ FileSystemEntity.type(createdThroughLink, followLinks: false)))
+ .then((_) => FutureExpect.equals(FileSystemEntityType.DIRECTORY,
+ FileSystemEntity.type(createdDirectly, followLinks: false)))
- // Test FileSystemEntity.identical on files, directories, and links,
- // reached by different paths.
- .then((_) => FutureExpect.isTrue(FileSystemEntity.identical(
- createdDirectly,
- createdDirectly)))
- .then((_) => FutureExpect.isFalse(FileSystemEntity.identical(
- createdDirectly,
- createdThroughLink)))
- .then((_) => FutureExpect.isTrue(FileSystemEntity.identical(
- createdDirectly,
- join(base, 'link', 'createdDirectly'))))
- .then((_) => FutureExpect.isTrue(FileSystemEntity.identical(
- createdThroughLink,
- join(base, 'target', 'createdThroughLink'))))
- .then((_) => FutureExpect.isFalse(FileSystemEntity.identical(
- target,
- link)))
- .then((_) => FutureExpect.isTrue(FileSystemEntity.identical(
- link,
- link)))
- .then((_) => FutureExpect.isTrue(FileSystemEntity.identical(
- target,
- target)))
- .then((_) => new Link(link).target())
- .then((linkTarget) => FutureExpect.isTrue(FileSystemEntity.identical(
- target,
- linkTarget)))
- .then((_) => new File(".").resolveSymbolicLinks())
- .then((fullCurrentDir) => FutureExpect.isTrue(FileSystemEntity.identical(
- ".",
- fullCurrentDir)))
- .then((_) => FutureExpect.isTrue(FileSystemEntity.identical(
- createdFile,
- createdFile)))
- .then((_) => FutureExpect.isFalse(FileSystemEntity.identical(
- createdFile,
- createdDirectly)))
- .then((_) => FutureExpect.isTrue(FileSystemEntity.identical(
- createdFile,
- join(base, 'link', 'createdFile'))))
- .then((_) => FutureExpect.throws(FileSystemEntity.identical(
- createdFile,
- join(base, 'link', 'does_not_exist'))))
-
- .then((_) => testDirectoryListing(base, baseDir))
- .then((_) => new Directory(target).delete(recursive: true))
- .then((_) {
+ // Test FileSystemEntity.identical on files, directories, and links,
+ // reached by different paths.
+ .then((_) => FutureExpect.isTrue(FileSystemEntity.identical(createdDirectly, createdDirectly)))
+ .then((_) => FutureExpect.isFalse(FileSystemEntity.identical(createdDirectly, createdThroughLink)))
+ .then((_) => FutureExpect.isTrue(FileSystemEntity.identical(createdDirectly, join(base, 'link', 'createdDirectly'))))
+ .then((_) => FutureExpect.isTrue(FileSystemEntity.identical(createdThroughLink, join(base, 'target', 'createdThroughLink'))))
+ .then((_) => FutureExpect.isFalse(FileSystemEntity.identical(target, link)))
+ .then((_) => FutureExpect.isTrue(FileSystemEntity.identical(link, link)))
+ .then((_) => FutureExpect.isTrue(FileSystemEntity.identical(target, target)))
+ .then((_) => new Link(link).target())
+ .then((linkTarget) => FutureExpect.isTrue(FileSystemEntity.identical(target, linkTarget)))
+ .then((_) => new File(".").resolveSymbolicLinks())
+ .then((fullCurrentDir) => FutureExpect.isTrue(FileSystemEntity.identical(".", fullCurrentDir)))
+ .then((_) => FutureExpect.isTrue(FileSystemEntity.identical(createdFile, createdFile)))
+ .then((_) => FutureExpect.isFalse(FileSystemEntity.identical(createdFile, createdDirectly)))
+ .then((_) => FutureExpect.isTrue(FileSystemEntity.identical(createdFile, join(base, 'link', 'createdFile'))))
+ .then((_) => FutureExpect.throws(FileSystemEntity.identical(createdFile, join(base, 'link', 'does_not_exist'))))
+ .then((_) => testDirectoryListing(base, baseDir))
+ .then((_) => new Directory(target).delete(recursive: true))
+ .then((_) {
List<Future> futures = [];
for (bool recursive in [true, false]) {
for (bool followLinks in [true, false]) {
- var result = baseDir.listSync(recursive: recursive,
- followLinks: followLinks);
+ var result = baseDir.listSync(
+ recursive: recursive, followLinks: followLinks);
Expect.equals(1, result.length);
Expect.isTrue(result[0] is Link);
- futures.add(FutureExpect.isTrue(
- baseDir.list(recursive: recursive,
- followLinks: followLinks)
- .single.then((element) => element is Link)));
+ futures.add(FutureExpect.isTrue(baseDir
+ .list(recursive: recursive, followLinks: followLinks)
+ .single
+ .then((element) => element is Link)));
}
}
return Future.wait(futures);
- })
- .then((_) => baseDir.delete(recursive: true));
+ }).then((_) => baseDir.delete(recursive: true));
});
});
}
-
Future testCreateLoopingLink(_) {
- return Directory.systemTemp.createTemp('dart_link_async')
- .then((dir) => dir.path)
- .then((String base) =>
- new Directory(join(base, 'a', 'b', 'c')).create(recursive: true)
- .then((_) => new Link(join(base, 'a', 'b', 'c', 'd'))
- .create(join(base, 'a', 'b')))
- .then((_) => new Link(join(base, 'a', 'b', 'c', 'e'))
- .create(join(base, 'a')))
- .then((_) => new Directory(join(base, 'a'))
- .list(recursive: true, followLinks: false).last)
- // This directory listing must terminate, even though it contains loops.
- .then((_) => new Directory(join(base, 'a'))
- .list(recursive: true, followLinks: true).last)
- // This directory listing must terminate, even though it contains loops.
- .then((_) => new Directory(join(base, 'a', 'b', 'c'))
- .list(recursive: true, followLinks: true).last)
- .then((_) => new Directory(base).delete(recursive: true))
- .then((_) => FutureExpect.isFalse(new Directory(base).exists()))
- );
+ return Directory.systemTemp
+ .createTemp('dart_link_async')
+ .then((dir) => dir.path)
+ .then((String base) => new Directory(join(base, 'a', 'b', 'c'))
+ .create(recursive: true)
+ .then((_) => new Link(join(base, 'a', 'b', 'c', 'd'))
+ .create(join(base, 'a', 'b')))
+ .then((_) =>
+ new Link(join(base, 'a', 'b', 'c', 'e')).create(join(base, 'a')))
+ .then((_) => new Directory(join(base, 'a'))
+ .list(recursive: true, followLinks: false)
+ .last)
+ // This directory listing must terminate, even though it contains loops.
+ .then((_) => new Directory(join(base, 'a'))
+ .list(recursive: true, followLinks: true)
+ .last)
+ // This directory listing must terminate, even though it contains loops.
+ .then((_) => new Directory(join(base, 'a', 'b', 'c'))
+ .list(recursive: true, followLinks: true)
+ .last)
+ .then((_) => new Directory(base).delete(recursive: true))
+ .then((_) => FutureExpect.isFalse(new Directory(base).exists())));
}
-
Future testRename(_) {
- Future testRename(String base , String target) {
+ Future testRename(String base, String target) {
Link link1;
Link link2;
- return new Link(join(base, 'c')).create(target)
- .then((link) {
+ return new Link(join(base, 'c')).create(target).then((link) {
link1 = link;
Expect.isTrue(link1.existsSync());
return link1.rename(join(base, 'd'));
- })
- .then((link) {
+ }).then((link) {
link2 = link;
Expect.isFalse(link1.existsSync());
Expect.isTrue(link2.existsSync());
return link2.delete();
- })
- .then((_) => Expect.isFalse(link2.existsSync()));
+ }).then((_) => Expect.isFalse(link2.existsSync()));
}
- Future testUpdate(String base , String target1, String target2) {
+ Future testUpdate(String base, String target1, String target2) {
Link link1;
- return new Link(join(base, 'c')).create(target1)
- .then((link) {
+ return new Link(join(base, 'c')).create(target1).then((link) {
link1 = link;
Expect.isTrue(link1.existsSync());
return link1.update(target2);
- })
- .then((Link link) {
+ }).then((Link link) {
Expect.isTrue(link1.existsSync());
Expect.isTrue(link.existsSync());
- return FutureExpect.equals(target2, link.target())
- .then((_) => FutureExpect.equals(target2, link1.target()))
- .then((_) => link.delete());
- })
- .then((_) => Expect.isFalse(link1.existsSync()));
+ return FutureExpect
+ .equals(target2, link.target())
+ .then((_) => FutureExpect.equals(target2, link1.target()))
+ .then((_) => link.delete());
+ }).then((_) => Expect.isFalse(link1.existsSync()));
}
return Directory.systemTemp.createTemp('dart_link_async').then((baseDir) {
@@ -211,16 +179,15 @@ Future testRename(_) {
targetsFutures.add(new Directory(join(base, 'a')).create());
if (Platform.isWindows) {
// Currently only links to directories are supported on Windows.
- targetsFutures.add(
- new Directory(join(base, 'b')).create());
+ targetsFutures.add(new Directory(join(base, 'b')).create());
} else {
targetsFutures.add(new File(join(base, 'b')).create());
}
return Future.wait(targetsFutures).then((targets) {
return testRename(base, targets[0].path)
- .then((_) => testRename(base, targets[1].path))
- .then((_) => testUpdate(base, targets[0].path, targets[1].path))
- .then((_) => baseDir.delete(recursive: true));
+ .then((_) => testRename(base, targets[1].path))
+ .then((_) => testUpdate(base, targets[0].path, targets[1].path))
+ .then((_) => baseDir.delete(recursive: true));
});
});
}
@@ -254,23 +221,22 @@ Future testDirectoryListing(String base, Directory baseDir) {
for (bool recursive in [true, false]) {
for (bool followLinks in [true, false]) {
Map expected = makeExpected(recursive, followLinks);
- for (var x in baseDir.listSync(recursive: recursive,
- followLinks: followLinks)) {
+ for (var x
+ in baseDir.listSync(recursive: recursive, followLinks: followLinks)) {
checkEntity(x, expected);
}
for (var v in expected.values) {
Expect.equals('Found', v);
}
expected = makeExpected(recursive, followLinks);
- futures.add(
- baseDir.list(recursive: recursive, followLinks: followLinks)
- .forEach((entity) => checkEntity(entity, expected))
- .then((_) {
- for (var v in expected.values) {
- Expect.equals('Found', v);
- }
- })
- );
+ futures.add(baseDir
+ .list(recursive: recursive, followLinks: followLinks)
+ .forEach((entity) => checkEntity(entity, expected))
+ .then((_) {
+ for (var v in expected.values) {
+ Expect.equals('Found', v);
+ }
+ }));
}
}
return Future.wait(futures);
@@ -281,42 +247,44 @@ Future checkExists(String filePath) =>
Future testRelativeLinks(_) {
return Directory.systemTemp
- .createTemp('dart_link_async')
- .then((tempDirectory) {
+ .createTemp('dart_link_async')
+ .then((tempDirectory) {
String temp = tempDirectory.path;
String oldWorkingDirectory = Directory.current.path;
// Make directories and files to test links.
- return new Directory(join(temp, 'dir1', 'dir2')).create(recursive: true)
- .then((_) => new File(join(temp, 'dir1', 'file1')).create())
- .then((_) => new File(join(temp, 'dir1', 'dir2', 'file2')).create())
- // Make links whose path and/or target is given by a relative path.
- .then((_) => new Link(join(temp, 'dir1', 'link1_2')).create('dir2'))
- .then((_) => Directory.current = temp)
- .then((_) => new Link('link0_2').create(join('dir1', 'dir2')))
- .then((_) => new Link(join('dir1', 'link1_0')).create('..'))
- .then((_) => Directory.current = 'dir1')
- .then((_) => new Link(join('..', 'link0_1')).create('dir1'))
- .then((_) => new Link(join('dir2', 'link2_1')).create(join(temp, 'dir1')))
- .then((_) => new Link(join(temp, 'dir1', 'dir2', 'link2_0'))
- .create(join('..', '..')))
- // Test that the links go to the right targets.
- .then((_) => checkExists(join('..', 'link0_1', 'file1')))
- .then((_) => checkExists(join('..', 'link0_2', 'file2')))
- .then((_) => checkExists(join('link1_0', 'dir1', 'file1')))
- .then((_) => checkExists(join('link1_2', 'file2')))
- .then((_) => checkExists(join('dir2', 'link2_0', 'dir1', 'file1')))
- .then((_) => checkExists(join('dir2', 'link2_1', 'file1')))
- // Clean up
- .whenComplete(() => Directory.current = oldWorkingDirectory)
- .whenComplete(() => tempDirectory.delete(recursive: true));
+ return new Directory(join(temp, 'dir1', 'dir2'))
+ .create(recursive: true)
+ .then((_) => new File(join(temp, 'dir1', 'file1')).create())
+ .then((_) => new File(join(temp, 'dir1', 'dir2', 'file2')).create())
+ // Make links whose path and/or target is given by a relative path.
+ .then((_) => new Link(join(temp, 'dir1', 'link1_2')).create('dir2'))
+ .then((_) => Directory.current = temp)
+ .then((_) => new Link('link0_2').create(join('dir1', 'dir2')))
+ .then((_) => new Link(join('dir1', 'link1_0')).create('..'))
+ .then((_) => Directory.current = 'dir1')
+ .then((_) => new Link(join('..', 'link0_1')).create('dir1'))
+ .then(
+ (_) => new Link(join('dir2', 'link2_1')).create(join(temp, 'dir1')))
+ .then((_) => new Link(join(temp, 'dir1', 'dir2', 'link2_0'))
+ .create(join('..', '..')))
+ // Test that the links go to the right targets.
+ .then((_) => checkExists(join('..', 'link0_1', 'file1')))
+ .then((_) => checkExists(join('..', 'link0_2', 'file2')))
+ .then((_) => checkExists(join('link1_0', 'dir1', 'file1')))
+ .then((_) => checkExists(join('link1_2', 'file2')))
+ .then((_) => checkExists(join('dir2', 'link2_0', 'dir1', 'file1')))
+ .then((_) => checkExists(join('dir2', 'link2_1', 'file1')))
+ // Clean up
+ .whenComplete(() => Directory.current = oldWorkingDirectory)
+ .whenComplete(() => tempDirectory.delete(recursive: true));
});
}
main() {
asyncStart();
testCreate()
- .then(testCreateLoopingLink)
- .then(testRename)
- .then(testRelativeLinks)
- .then((_) => asyncEnd());
+ .then(testCreateLoopingLink)
+ .then(testRename)
+ .then(testRelativeLinks)
+ .then((_) => asyncEnd());
}

Powered by Google App Engine
This is Rietveld 408576698