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

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

Issue 52363002: dart:io | Add 'recursive' flag to File.create and Link.create. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove recursive call to create(), simplifying control flow. Created 7 years, 2 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/create_recursive_test.dart
diff --git a/tests/standalone/io/create_recursive_test.dart b/tests/standalone/io/create_recursive_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..10d5fcdd5e65ba76f98472e924ab678fb4c99587
--- /dev/null
+++ b/tests/standalone/io/create_recursive_test.dart
@@ -0,0 +1,153 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'dart:io';
+
+import "package:async_helper/async_helper.dart";
+import "package:expect/expect.dart";
+import "package:path/path.dart";
+
+main() {
+ testCreateRecursiveSync();
+ testCreateRecursive();
+}
+
+testCreateRecursiveSync() {
Anders Johnsen 2013/10/30 12:23:56 Can you split up these two functions to smaller te
Bill Hesse 2013/10/30 15:07:37 Done.
+ var temp = Directory.systemTemp.createTempSync('directory_test');
+ var a = new Directory(join(temp.path, 'a'));
+ var b = new Directory(join(a.path, 'b'));
+ var c = new Directory(join(b.path, 'c'));
+ void expectDirectories() {
+ Expect.isTrue(a.existsSync());
+ Expect.isTrue(b.existsSync());
+ Expect.isTrue(c.existsSync());
+ }
+
+ try {
+ Expect.throws(() => c.createSync());
+ c.createSync(recursive: true);
+ expectDirectories();
+ a.deleteSync(recursive: true);
+
+ var d = new Directory('${c.path}/');
+ d.createSync(recursive: true);
+ expectDirectories();
+ Expect.isTrue(d.existsSync());
+ a.deleteSync(recursive: true);
+
+ var f = new File(join(c.path, 'file'));
+ Expect.throws(() => f.createSync());
+ f.createSync(recursive: true);
+ expectDirectories();
+ Expect.isTrue(f.existsSync());
+ a.deleteSync(recursive: true);
+
+ var l = new Link(join(c.path, 'link'));
+ Expect.throws(() => l.createSync(temp.path));
+ l.createSync(temp.path, recursive:true);
+ expectDirectories();
+ Expect.isTrue(l.existsSync());
+ Expect.isTrue(new Directory(l.targetSync()).existsSync());
+ a.deleteSync(recursive: true);
+
+ // Test cases where the directories or the object already exist.
+ a.createSync(recursive: true);
+ Expect.isTrue(a.existsSync());
+ a.createSync(recursive: true);
+ Expect.isTrue(a.existsSync());
+
+ f = new File(join(temp.path, 'file'));
+ f.createSync(recursive: true);
+ Expect.isTrue(f.existsSync());
+ f.createSync(recursive: true);
+ Expect.isTrue(f.existsSync());
+
+ l = new Link(join(temp.path, 'link'));
+ l.createSync(temp.path, recursive: true);
+ Expect.isTrue(l.existsSync());
+ Expect.throws(() => l.createSync(temp.path, recursive: true));
+ Expect.isTrue(l.existsSync());
+ } finally {
+ temp.deleteSync(recursive: true);
+ }
+}
+
+testCreateRecursive() {
+ asyncStart();
+ Directory temp;
+ Directory a;
+ Directory b;
+ Directory c;
+ Directory d;
+ File f;
+ Link l;
+ Function lift(Function f) =>
+ (futureValue) => futureValue.then((value) => f(value));
+
+ Future expectDirectories() {
+ return lift(Expect.isTrue)(a.exists())
+ .then((_) => lift(Expect.isTrue)(b.exists()))
+ .then((_) => lift(Expect.isTrue)(c.exists()));
+ }
+
+ Future expectFileSystemException(Function f, String message) {
+ return f().then(
+ (_) => Expect.fail('Expected a FileSystemException: $message'),
+ onError: (e) => Expect.isTrue(e is FileSystemException));
+ }
+
+ Directory.systemTemp.createTemp('dart_directory').then((dir) {
+ temp = dir;
+ a = new Directory(join(temp.path, 'a'));
+ b = new Directory(join(a.path, 'b'));
+ c = new Directory(join(b.path, 'c'));
+ }).then((_) => expectFileSystemException(() => c.create(), 'c.create'))
+ .then((_) => c.create(recursive: true))
+ .then((_) => expectDirectories())
+ .then((_) => a.delete(recursive: true))
+
+ .then((_) => d = new Directory('${c.path}/'))
+ .then((_) => d.create(recursive: true))
+ .then((_) => expectDirectories())
+ .then((_) => lift(Expect.isTrue)(d.exists()))
+ .then((_) => a.delete(recursive: true))
+
+ .then((_) => f = new File(join(c.path, 'file')))
+ .then((_) => expectFileSystemException(() => f.create(), 'f.create'))
+ .then((_) => f.create(recursive: true))
+ .then((_) => expectDirectories())
+ .then((_) => lift(Expect.isTrue)(f.exists()))
+ .then((_) => a.delete(recursive: true))
+
+ .then((_) => l = new Link(join(c.path, 'link')))
+ .then((_) => expectFileSystemException(() => l.create(temp.path),
+ 'l.create'))
+ .then((_) => l.create(temp.path, recursive: true))
+ .then((_) => expectDirectories())
+ .then((_) => lift(Expect.isTrue)(l.exists()))
+ .then((_) => lift(Expect.isTrue)(new Directory(l.targetSync()).exists()))
+ .then((_) => a.delete(recursive: true))
+
+ // Test cases where the directories or the object already exist.
+ .then((_) => a.create(recursive: true))
+ .then((_) => lift(Expect.isTrue)(a.exists()))
+ .then((_) => a.create(recursive: true))
+ .then((_) => lift(Expect.isTrue)(a.exists()))
+
+ .then((_) => f = new File(join(temp.path, 'file')))
+ .then((_) => f.create(recursive: true))
+ .then((_) => lift(Expect.isTrue)(f.exists()))
+ .then((_) => f.create(recursive: true))
+ .then((_) => lift(Expect.isTrue)(f.exists()))
+
+ .then((_) => l = new Link(join(temp.path, 'link')))
+ .then((_) => l.create(temp.path, recursive: true))
+ .then((_) => lift(Expect.isTrue)(l.exists()))
+ .then((_) => expectFileSystemException(
+ () => l.create(temp.path, recursive: true), 'l.create existing'))
+ .then((_) => lift(Expect.isTrue)(l.exists()))
+
+ .then((_) => asyncEnd())
+ .whenComplete(() => temp.delete(recursive: true));
+}

Powered by Google App Engine
This is Rietveld 408576698