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

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

Issue 13654002: Change how File/Directory/Link .delete works. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix windows error codes. Created 7 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 unified diff | Download patch | Annotate | Revision Log
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 void testFileExistsSync() {
8 var tmp = new Directory("").createTempSync();
9 var path = "${tmp.path}${Platform.pathSeparator}";
10
11 var file = new File("${path}myFile");
12 file.createSync();
13
14 Expect.isTrue(new File(file.path).existsSync());
15 Expect.isFalse(new Directory(file.path).existsSync());
16 Expect.isFalse(new Link(file.path).existsSync());
17
18 file.deleteSync();
19 Expect.isFalse(file.existsSync());
20
21 tmp.deleteSync();
22 }
23
24 void testFileExists() {
25 new Directory("").createTemp().then((tmp) {
26 var path = "${tmp.path}${Platform.pathSeparator}";
27 var file = new File("${path}myFile");
28 return file.create()
29 .then((_) => new File(file.path).exists().then(Expect.isTrue))
30 .then((_) => new Directory(file.path).exists().then(Expect.isFalse))
31 .then((_) => new Link(file.path).exists().then(Expect.isFalse))
32
33 .then((_) => file.delete())
34 .then((_) => tmp.delete());
35 });
36 }
37
38 void testDirectoryExistsSync() {
39 var tmp = new Directory("").createTempSync();
40 var path = "${tmp.path}${Platform.pathSeparator}";
41
42 var dir = new Directory("${path}myDirectory");
43 dir.createSync();
44
45 Expect.isFalse(new File(dir.path).existsSync());
46 Expect.isTrue(new Directory(dir.path).existsSync());
47 Expect.isFalse(new Link(dir.path).existsSync());
48
49 dir.deleteSync();
50 Expect.isFalse(dir.existsSync());
51
52 tmp.deleteSync();
53 }
54
55 void testDirectoryExists() {
56 new Directory("").createTemp().then((tmp) {
57 var path = "${tmp.path}${Platform.pathSeparator}";
58 var dir = new Directory("${path}myDirectory");
59 return dir.create()
60 .then((_) => new File(dir.path).exists().then(Expect.isFalse))
61 .then((_) => new Directory(dir.path).exists().then(Expect.isTrue))
62 .then((_) => new Link(dir.path).exists().then(Expect.isFalse))
63
64 .then((_) => dir.delete())
65 .then((_) => tmp.delete());
66 });
67 }
68
69 void testFileLinkExistsSync() {
70 var tmp = new Directory("").createTempSync();
71 var path = "${tmp.path}${Platform.pathSeparator}";
72
73 var file = new File("${path}myFile");
74 file.createSync();
75
76 var link = new Link("${path}myLink");
77 link.createSync(file.path);
78
79 Expect.isTrue(new File(link.path).existsSync());
80 Expect.isFalse(new Directory(link.path).existsSync());
81 Expect.isTrue(new Link(link.path).existsSync());
82
83 link.deleteSync();
84 Expect.isFalse(link.existsSync());
85
86 file.deleteSync();
87 Expect.isFalse(file.existsSync());
88
89 tmp.deleteSync();
90 }
91
92 void testFileLinkExists() {
93 new Directory("").createTemp().then((tmp) {
94 var path = "${tmp.path}${Platform.pathSeparator}";
95 var file = new File("${path}myFile");
96 var link = new Link("${path}myLink");
97 return file.create()
98 .then((_) => link.create(file.path))
99
100 .then((_) => new File(link.path).exists().then(Expect.isTrue))
101 .then((_) => new Directory(link.path).exists().then(Expect.isFalse))
102 .then((_) => new Link(link.path).exists().then(Expect.isTrue))
103
104 .then((_) => link.delete())
105 .then((_) => file.delete())
106 .then((_) => tmp.delete());
107 });
108 }
109
110 void testDirectoryLinkExistsSync() {
111 var tmp = new Directory("").createTempSync();
112 var path = "${tmp.path}${Platform.pathSeparator}";
113
114 var directory = new Directory("${path}myDirectory");
115 directory.createSync();
116
117 var link = new Link("${path}myLink");
118 link.createSync(directory.path);
119
120 Expect.isFalse(new File(link.path).existsSync());
121 Expect.isTrue(new Directory(link.path).existsSync());
122 Expect.isTrue(new Link(link.path).existsSync());
123
124 link.deleteSync();
125 Expect.isFalse(link.existsSync());
126
127 directory.deleteSync();
128 Expect.isFalse(directory.existsSync());
129
130 tmp.deleteSync();
131 }
132
133 void testDirectoryLinkExists() {
134 new Directory("").createTemp().then((tmp) {
135 var path = "${tmp.path}${Platform.pathSeparator}";
136 var dir = new Directory("${path}myDir");
137 var link = new Link("${path}myLink");
138 return dir.create()
139 .then((_) => link.create(dir.path))
140
141 .then((_) => new File(link.path).exists().then(Expect.isFalse))
142 .then((_) => new Directory(link.path).exists().then(Expect.isTrue))
143 .then((_) => new Link(link.path).exists().then(Expect.isTrue))
144
145 .then((_) => link.delete())
146 .then((_) => dir.delete())
147 .then((_) => tmp.delete());
148 });
149 }
150
151 void testBrokenLinkExistsSync() {
152 var tmp = new Directory("").createTempSync();
153 var path = "${tmp.path}${Platform.pathSeparator}";
154
155 var directory = new Directory("${path}myDirectory");
156 directory.createSync();
157
158 var link = new Link("${path}myLink");
159 link.createSync(directory.path);
160 directory.deleteSync();
161
162 Expect.isFalse(new File(link.path).existsSync());
163 Expect.isFalse(new Directory(link.path).existsSync());
164 Expect.isTrue(new Link(link.path).existsSync());
165
166 link.deleteSync();
167 Expect.isFalse(link.existsSync());
168
169 tmp.deleteSync();
170 }
171
172 void testBrokenLinkExists() {
173 new Directory("").createTemp().then((tmp) {
174 var path = "${tmp.path}${Platform.pathSeparator}";
175 var dir = new Directory("${path}myDir");
176 var link = new Link("${path}myLink");
177 return dir.create()
178 .then((_) => link.create(dir.path))
179 .then((_) => dir.delete())
180
181 .then((_) => new File(link.path).exists().then(Expect.isFalse))
182 .then((_) => new Directory(link.path).exists().then(Expect.isFalse))
183 .then((_) => new Link(link.path).exists().then(Expect.isTrue))
184
185 .then((_) => link.delete())
186 .then((_) => tmp.delete());
187 });
188 }
189
190 void main() {
191 testFileExistsSync();
192 testFileExists();
193 testDirectoryExistsSync();
194 testDirectoryExists();
195 if (Platform.operatingSystem != 'windows') {
196 testFileLinkExistsSync();
197 testFileLinkExists();
198 }
199 testDirectoryLinkExistsSync();
200 testDirectoryLinkExists();
201 testBrokenLinkExistsSync();
202 testBrokenLinkExists();
203 }
204
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698