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

Side by Side 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: Indentation. Created 7 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/io/link.dart ('k') | tests/standalone/io/directory_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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:io';
6
7 import "package:async_helper/async_helper.dart";
8 import "package:expect/expect.dart";
9 import "package:path/path.dart";
10
11 main() {
12 testCreateDirectoryRecursiveSync();
13 testCreateLinkRecursiveSync();
14 testCreateFileRecursiveSync();
15 testCreateDirectoryRecursive();
16 testCreateLinkRecursive();
17 testCreateFileRecursive();
18 }
19
20 testCreateDirectoryRecursiveSync() {
21 var temp = Directory.systemTemp.createTempSync('directory_test');
22 try {
23 var dir = new Directory(join(temp.path, 'a', 'b', 'c'));
24 Expect.throws(() => dir.createSync());
25 dir.createSync(recursive: true);
26 Expect.isTrue(dir.existsSync());
27 // Test cases where the directory or parent directory already exists.
28 dir.deleteSync();
29 dir.createSync(recursive: true);
30 Expect.isTrue(dir.existsSync());
31 dir.createSync(recursive: true);
32 Expect.isTrue(dir.existsSync());
33 } finally {
34 temp.deleteSync(recursive: true);
35 }
36 }
37
38 testCreateFileRecursiveSync() {
39 var temp = Directory.systemTemp.createTempSync('directory_test');
40 try {
41 var file = new File(join(temp.path, 'a', 'b', 'c'));
42 Expect.throws(() => file.createSync());
43 file.createSync(recursive: true);
44 Expect.isTrue(file.existsSync());
45 // Test cases where the file or parent directory already exists.
46 file.deleteSync();
47 file.createSync(recursive: true);
48 Expect.isTrue(file.existsSync());
49 file.createSync(recursive: true);
50 Expect.isTrue(file.existsSync());
51 } finally {
52 temp.deleteSync(recursive: true);
53 }
54 }
55
56 testCreateLinkRecursiveSync() {
57 var temp = Directory.systemTemp.createTempSync('directory_test');
58 try {
59 var link = new Link(join(temp.path, 'a', 'b', 'c'));
60 Expect.throws(() => link.createSync(temp.path));
61 link.createSync(temp.path, recursive: true);
62 Expect.isTrue(link.existsSync());
63 Expect.isTrue(new Directory(link.targetSync()).existsSync());
64 // Test cases where the link or parent directory already exists.
65 link.deleteSync();
66 link.createSync(temp.path, recursive: true);
67 Expect.isTrue(link.existsSync());
68 Expect.throws(() => link.createSync(temp.path, recursive: true));
69 Expect.isTrue(link.existsSync());
70 } finally {
71 temp.deleteSync(recursive: true);
72 }
73 }
74
75 Future expectFutureIsTrue(Future future) =>
76 future.then((value) => Expect.isTrue(value));
77
78 Future expectFileSystemException(Function f, String message) {
79 return f().then(
80 (_) => Expect.fail('Expected a FileSystemException: $message'),
81 onError: (e) => Expect.isTrue(e is FileSystemException));
82 }
83
84 testCreateDirectoryRecursive() {
85 asyncStart();
86 Directory.systemTemp.createTemp('dart_directory').then((temp) {
87 var dir = new Directory(join(temp.path, 'a', 'b', 'c'));
88 return expectFileSystemException(() => dir.create(), 'dir.create')
89 .then((_) => dir.create(recursive: true))
90 .then((_) => expectFutureIsTrue(dir.exists()))
91 // Test cases where the directory or parent directory already exists.
92 .then((_) => dir.delete())
93 .then((_) => dir.create(recursive: true))
94 .then((_) => expectFutureIsTrue(dir.exists()))
95 .then((_) => dir.create(recursive: true))
96 .then((_) => expectFutureIsTrue(dir.exists()))
97
98 .then((_) => asyncEnd())
99 .whenComplete(() => temp.delete(recursive: true));
100 });
101 }
102
103 testCreateFileRecursive() {
104 asyncStart();
105 Directory.systemTemp.createTemp('dart_directory').then((temp) {
106 var file = new File(join(temp.path, 'a', 'b', 'c'));
107 return expectFileSystemException(() => file.create(), 'file.create')
108 .then((_) => file.create(recursive: true))
109 .then((_) => expectFutureIsTrue(file.exists()))
110 // Test cases where the file or parent directory already exists.
111 .then((_) => file.delete())
112 .then((_) => file.create(recursive: true))
113 .then((_) => expectFutureIsTrue(file.exists()))
114 .then((_) => file.create(recursive: true))
115 .then((_) => expectFutureIsTrue(file.exists()))
116
117 .then((_) => asyncEnd())
118 .whenComplete(() => temp.delete(recursive: true));
119 });
120 }
121
122 testCreateLinkRecursive() {
123 asyncStart();
124 Directory.systemTemp.createTemp('dart_directory').then((temp) {
125 var link = new Link(join(temp.path, 'a', 'b', 'c'));
126 return expectFileSystemException(() => link.create(temp.path),
127 'link.create')
128 .then((_) => link.create(temp.path, recursive: true))
129 .then((_) => expectFutureIsTrue(link.exists()))
130 // Test cases where the link or parent directory already exists.
131 .then((_) => link.delete())
132 .then((_) => link.create(temp.path, recursive: true))
133 .then((_) => expectFutureIsTrue(link.exists()))
134 .then((_) => expectFileSystemException(
135 () => link.create(temp.path, recursive: true),
136 'existing link.create'))
137 .then((_) => expectFutureIsTrue(link.exists()))
138
139 .then((_) => asyncEnd())
140 .whenComplete(() => temp.delete(recursive: true));
141 });
142 }
OLDNEW
« no previous file with comments | « sdk/lib/io/link.dart ('k') | tests/standalone/io/directory_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698