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

Side by Side Diff: tests/standalone/io/file_system_async_links_test.dart

Issue 25471003: Modify tests to use Directory.systemTemp (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 10
11 class FutureExpect { 11 class FutureExpect {
12 static Future isTrue(Future<bool> result) => 12 static Future isTrue(Future<bool> result) =>
13 result.then((value) => Expect.isTrue(value)); 13 result.then((value) => Expect.isTrue(value));
14 static Future isFalse(Future<bool> result) => 14 static Future isFalse(Future<bool> result) =>
15 result.then((value) => Expect.isFalse(value)); 15 result.then((value) => Expect.isFalse(value));
16 static Future equals(expected, Future result) => 16 static Future equals(expected, Future result) =>
17 result.then((value) => Expect.equals(expected, value)); 17 result.then((value) => Expect.equals(expected, value));
18 static Future listEquals(expected, Future result) => 18 static Future listEquals(expected, Future result) =>
19 result.then((value) => Expect.listEquals(expected, value)); 19 result.then((value) => Expect.listEquals(expected, value));
20 static Future throws(Future result) => 20 static Future throws(Future result) =>
21 result.then((value) { 21 result.then((value) {
22 throw new ExpectException( 22 throw new ExpectException(
23 "FutureExpect.throws received $value instead of an exception"); 23 "FutureExpect.throws received $value instead of an exception");
24 }, onError: (_) => null); 24 }, onError: (_) => null);
25 } 25 }
26 26
27 27
28 Future testFileExistsCreate() { 28 Future testFileExistsCreate() {
29 return new Directory('').createTemp().then((temp) { 29 return Directory.createSystemTemp('dart_file_system_async').then((temp) {
30 var x = '${temp.path}${Platform.pathSeparator}x'; 30 var x = '${temp.path}${Platform.pathSeparator}x';
31 var y = '${temp.path}${Platform.pathSeparator}y'; 31 var y = '${temp.path}${Platform.pathSeparator}y';
32 return new Link(y).create(x) 32 return new Link(y).create(x)
33 .then((link) => Expect.equals(y, link.path)) 33 .then((link) => Expect.equals(y, link.path))
34 .then((_) => FutureExpect.isFalse(new File(y).exists())) 34 .then((_) => FutureExpect.isFalse(new File(y).exists()))
35 .then((_) => FutureExpect.isFalse(new File(x).exists())) 35 .then((_) => FutureExpect.isFalse(new File(x).exists()))
36 .then((_) => FutureExpect.isTrue(FileSystemEntity.isLink(y))) 36 .then((_) => FutureExpect.isTrue(FileSystemEntity.isLink(y)))
37 .then((_) => FutureExpect.isFalse(FileSystemEntity.isLink(x))) 37 .then((_) => FutureExpect.isFalse(FileSystemEntity.isLink(x)))
38 .then((_) => FutureExpect.equals(FileSystemEntityType.NOT_FOUND, 38 .then((_) => FutureExpect.equals(FileSystemEntityType.NOT_FOUND,
39 FileSystemEntity.type(y))) 39 FileSystemEntity.type(y)))
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 FileSystemEntity.type(y))) 91 FileSystemEntity.type(y)))
92 .then((_) => FutureExpect.equals(FileSystemEntityType.DIRECTORY, 92 .then((_) => FutureExpect.equals(FileSystemEntityType.DIRECTORY,
93 FileSystemEntity.type(x))) 93 FileSystemEntity.type(x)))
94 .then((_) => FutureExpect.throws(new Link(y).target())) 94 .then((_) => FutureExpect.throws(new Link(y).target()))
95 .then((_) => temp.delete(recursive: true)); 95 .then((_) => temp.delete(recursive: true));
96 }); 96 });
97 } 97 }
98 98
99 99
100 Future testFileDelete() { 100 Future testFileDelete() {
101 return new Directory('').createTemp().then((temp) { 101 return Directory.createSystemTemp('dart_file_system_async').then((temp) {
102 var x = '${temp.path}${Platform.pathSeparator}x'; 102 var x = '${temp.path}${Platform.pathSeparator}x';
103 var y = '${temp.path}${Platform.pathSeparator}y'; 103 var y = '${temp.path}${Platform.pathSeparator}y';
104 return new File(x).create() 104 return new File(x).create()
105 .then((_) => new Link(y).create(x)) 105 .then((_) => new Link(y).create(x))
106 .then((_) => FutureExpect.isTrue(new File(x).exists())) 106 .then((_) => FutureExpect.isTrue(new File(x).exists()))
107 .then((_) => FutureExpect.isTrue(new File(y).exists())) 107 .then((_) => FutureExpect.isTrue(new File(y).exists()))
108 .then((_) => new File(y).delete()) 108 .then((_) => new File(y).delete())
109 .then((_) => FutureExpect.isTrue(new File(x).exists())) 109 .then((_) => FutureExpect.isTrue(new File(x).exists()))
110 .then((_) => FutureExpect.isFalse(new File(y).exists())) 110 .then((_) => FutureExpect.isFalse(new File(y).exists()))
111 .then((_) => new Link(y).create(x)) 111 .then((_) => new Link(y).create(x))
112 .then((_) => FutureExpect.isTrue(new File(x).exists())) 112 .then((_) => FutureExpect.isTrue(new File(x).exists()))
113 .then((_) => FutureExpect.isTrue(new File(y).exists())) 113 .then((_) => FutureExpect.isTrue(new File(y).exists()))
114 .then((_) => new File(y).delete()) 114 .then((_) => new File(y).delete())
115 .then((_) => FutureExpect.isTrue(new File(x).exists())) 115 .then((_) => FutureExpect.isTrue(new File(x).exists()))
116 .then((_) => FutureExpect.isFalse(new File(y).exists())) 116 .then((_) => FutureExpect.isFalse(new File(y).exists()))
117 .then((_) => temp.delete(recursive: true)); 117 .then((_) => temp.delete(recursive: true));
118 }); 118 });
119 } 119 }
120 120
121 121
122 Future testFileWriteRead() { 122 Future testFileWriteRead() {
123 return new Directory('').createTemp().then((temp) { 123 return Directory.createSystemTemp('dart_file_system_async').then((temp) {
124 var x = '${temp.path}${Platform.pathSeparator}x'; 124 var x = '${temp.path}${Platform.pathSeparator}x';
125 var y = '${temp.path}${Platform.pathSeparator}y'; 125 var y = '${temp.path}${Platform.pathSeparator}y';
126 var data = "asdf".codeUnits; 126 var data = "asdf".codeUnits;
127 return new File(x).create() 127 return new File(x).create()
128 .then((_) => new Link(y).create(x)) 128 .then((_) => new Link(y).create(x))
129 .then((_) => 129 .then((_) =>
130 (new File(y).openWrite(mode: FileMode.WRITE)..add(data)).close()) 130 (new File(y).openWrite(mode: FileMode.WRITE)..add(data)).close())
131 .then((_) => FutureExpect.listEquals(data, new File(y).readAsBytes())) 131 .then((_) => FutureExpect.listEquals(data, new File(y).readAsBytes()))
132 .then((_) => FutureExpect.listEquals(data, new File(x).readAsBytes())) 132 .then((_) => FutureExpect.listEquals(data, new File(x).readAsBytes()))
133 .then((_) => temp.delete(recursive: true)); 133 .then((_) => temp.delete(recursive: true));
134 }); 134 });
135 } 135 }
136 136
137 137
138 Future testDirectoryExistsCreate() { 138 Future testDirectoryExistsCreate() {
139 return new Directory('').createTemp().then((temp) { 139 return Directory.createSystemTemp('dart_file_system_async').then((temp) {
140 var x = '${temp.path}${Platform.pathSeparator}x'; 140 var x = '${temp.path}${Platform.pathSeparator}x';
141 var y = '${temp.path}${Platform.pathSeparator}y'; 141 var y = '${temp.path}${Platform.pathSeparator}y';
142 return new Link(y).create(x) 142 return new Link(y).create(x)
143 .then((_) => FutureExpect.isFalse(new Directory(x).exists())) 143 .then((_) => FutureExpect.isFalse(new Directory(x).exists()))
144 .then((_) => FutureExpect.isFalse(new Directory(y).exists())) 144 .then((_) => FutureExpect.isFalse(new Directory(y).exists()))
145 .then((_) => FutureExpect.throws(new Directory(y).create())) 145 .then((_) => FutureExpect.throws(new Directory(y).create()))
146 .then((_) => temp.delete(recursive: true)); 146 .then((_) => temp.delete(recursive: true));
147 }); 147 });
148 } 148 }
149 149
150 150
151 Future testDirectoryDelete() { 151 Future testDirectoryDelete() {
152 return new Directory('').createTemp().then((temp) => 152 return Directory.createSystemTemp('dart_file_system_async').then((temp) =>
153 new Directory('').createTemp().then((temp2) { 153 Directory.createSystemTemp('dart_file_system_async').then((temp2) {
154 var y = '${temp.path}${Platform.pathSeparator}y'; 154 var y = '${temp.path}${Platform.pathSeparator}y';
155 var x = '${temp2.path}${Platform.pathSeparator}x'; 155 var x = '${temp2.path}${Platform.pathSeparator}x';
156 var link = new Directory(y); 156 var link = new Directory(y);
157 return new File(x).create() 157 return new File(x).create()
158 .then((_) => new Link(y).create(temp2.path)) 158 .then((_) => new Link(y).create(temp2.path))
159 .then((_) => FutureExpect.isTrue(link.exists())) 159 .then((_) => FutureExpect.isTrue(link.exists()))
160 .then((_) => FutureExpect.isTrue(temp2.exists())) 160 .then((_) => FutureExpect.isTrue(temp2.exists()))
161 .then((_) => link.delete()) 161 .then((_) => link.delete())
162 .then((_) => FutureExpect.isFalse(link.exists())) 162 .then((_) => FutureExpect.isFalse(link.exists()))
163 .then((_) => FutureExpect.isTrue(temp2.exists())) 163 .then((_) => FutureExpect.isTrue(temp2.exists()))
164 .then((_) => new Link(y).create(temp2.path)) 164 .then((_) => new Link(y).create(temp2.path))
165 .then((_) => FutureExpect.isTrue(link.exists())) 165 .then((_) => FutureExpect.isTrue(link.exists()))
166 .then((_) => temp.delete(recursive: true)) 166 .then((_) => temp.delete(recursive: true))
167 .then((_) => FutureExpect.isFalse(link.exists())) 167 .then((_) => FutureExpect.isFalse(link.exists()))
168 .then((_) => FutureExpect.isFalse(temp.exists())) 168 .then((_) => FutureExpect.isFalse(temp.exists()))
169 .then((_) => FutureExpect.isTrue(temp2.exists())) 169 .then((_) => FutureExpect.isTrue(temp2.exists()))
170 .then((_) => FutureExpect.isTrue(new File(x).exists())) 170 .then((_) => FutureExpect.isTrue(new File(x).exists()))
171 .then((_) => temp2.delete(recursive: true)); 171 .then((_) => temp2.delete(recursive: true));
172 })); 172 }));
173 } 173 }
174 174
175 175
176 Future testDirectoryListing() { 176 Future testDirectoryListing() {
177 return new Directory('').createTemp().then((temp) => 177 return Directory.createSystemTemp('dart_file_system_async').then((temp) =>
178 new Directory('').createTemp().then((temp2) { 178 Directory.createSystemTemp('dart_file_system_async_links').then((temp2) {
179 var sep = Platform.pathSeparator; 179 var sep = Platform.pathSeparator;
180 var y = '${temp.path}${sep}y'; 180 var y = '${temp.path}${sep}y';
181 var x = '${temp2.path}${sep}x'; 181 var x = '${temp2.path}${sep}x';
182 return new File(x).create() 182 return new File(x).create()
183 .then((_) => new Link(y).create(temp2.path)) 183 .then((_) => new Link(y).create(temp2.path))
184 .then((_) => temp.list(recursive: true).singleWhere( 184 .then((_) => temp.list(recursive: true).singleWhere(
185 (entry) => entry is File)) 185 (entry) => entry is File))
186 .then((file) => Expect.isTrue(file.path.endsWith('$y${sep}x'))) 186 .then((file) => Expect.isTrue(file.path.endsWith('$y${sep}x')))
187 .then((_) => temp.list(recursive: true).singleWhere( 187 .then((_) => temp.list(recursive: true).singleWhere(
188 (entry) => entry is Directory)) 188 (entry) => entry is Directory))
189 .then((dir) => Expect.isTrue(dir.path.endsWith('y'))) 189 .then((dir) => Expect.isTrue(dir.path.endsWith('y')))
190 .then((_) => temp.delete(recursive: true)) 190 .then((_) => temp.delete(recursive: true))
191 .then((_) => temp2.delete(recursive: true)); 191 .then((_) => temp2.delete(recursive: true));
192 })); 192 }));
193 } 193 }
194 194
195 195
196 Future testDirectoryListingBrokenLink() { 196 Future testDirectoryListingBrokenLink() {
197 return new Directory('').createTemp().then((temp) { 197 return Directory.createSystemTemp('dart_file_system_async').then((temp) {
198 var x = '${temp.path}${Platform.pathSeparator}x'; 198 var x = '${temp.path}${Platform.pathSeparator}x';
199 var link = '${temp.path}${Platform.pathSeparator}link'; 199 var link = '${temp.path}${Platform.pathSeparator}link';
200 var doesNotExist = 'this_thing_does_not_exist'; 200 var doesNotExist = 'this_thing_does_not_exist';
201 bool sawFile = false; 201 bool sawFile = false;
202 bool sawLink = false; 202 bool sawLink = false;
203 return new File(x).create() 203 return new File(x).create()
204 .then((_) => new Link(link).create(doesNotExist)) 204 .then((_) => new Link(link).create(doesNotExist))
205 .then((_) => temp.list(recursive: true).forEach( 205 .then((_) => temp.list(recursive: true).forEach(
206 (entity) { 206 (entity) {
207 if (entity is File) { 207 if (entity is File) {
(...skipping 20 matching lines...) Expand all
228 testFileExistsCreate() 228 testFileExistsCreate()
229 .then((_) => testFileDelete()) 229 .then((_) => testFileDelete())
230 .then((_) => testFileWriteRead()) 230 .then((_) => testFileWriteRead())
231 .then((_) => testDirectoryExistsCreate()) 231 .then((_) => testDirectoryExistsCreate())
232 .then((_) => testDirectoryDelete()) 232 .then((_) => testDirectoryDelete())
233 .then((_) => testDirectoryListing()) 233 .then((_) => testDirectoryListing())
234 .then((_) => testDirectoryListingBrokenLink()) 234 .then((_) => testDirectoryListingBrokenLink())
235 .then((_) => asyncEnd()); 235 .then((_) => asyncEnd());
236 } 236 }
237 } 237 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698