OLD | NEW |
---|---|
(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 testDeleteFile() { | |
8 var tmp = new Directory("").createTempSync(); | |
9 var path = "${tmp.path}${Platform.pathSeparator}"; | |
10 | |
11 var file = new File("${path}myFile"); | |
12 | |
13 file.createSync(); | |
14 | |
15 Expect.isTrue(file.existsSync()); | |
16 new File(file.path).deleteSync(); | |
17 Expect.isFalse(file.existsSync()); | |
18 | |
19 file.createSync(); | |
20 | |
21 Expect.isTrue(file.existsSync()); | |
22 Expect.throws(() => new Directory(file.path).deleteSync()); | |
23 Expect.isTrue(file.existsSync()); | |
24 | |
25 Expect.isTrue(file.existsSync()); | |
26 Expect.throws(() => new Directory(file.path).deleteSync(recursive: true)); | |
27 Expect.isTrue(file.existsSync()); | |
28 | |
29 Expect.isTrue(file.existsSync()); | |
30 Expect.throws(() => new Link(file.path).deleteSync()); | |
31 Expect.isTrue(file.existsSync()); | |
32 | |
33 file.deleteSync(); | |
34 Expect.isFalse(file.existsSync()); | |
35 | |
36 tmp.deleteSync(); | |
37 } | |
38 | |
39 void testDeleteDirectory() { | |
40 var dir = new Directory("myDirectory"); | |
41 | |
42 dir.createSync(); | |
43 | |
44 Expect.isTrue(dir.existsSync()); | |
45 new Directory(dir.path).deleteSync(); | |
46 Expect.isFalse(dir.existsSync()); | |
47 | |
48 dir.createSync(); | |
49 | |
50 Expect.isTrue(dir.existsSync()); | |
51 new Directory(dir.path).deleteSync(recursive: true); | |
52 Expect.isFalse(dir.existsSync()); | |
53 | |
54 dir.createSync(); | |
55 | |
56 Expect.isTrue(dir.existsSync()); | |
57 Expect.throws(() => new File(dir.path).deleteSync()); | |
58 Expect.isTrue(dir.existsSync()); | |
59 | |
60 Expect.isTrue(dir.existsSync()); | |
61 Expect.throws(() => new Link(dir.path).deleteSync()); | |
62 Expect.isTrue(dir.existsSync()); | |
63 | |
64 dir.deleteSync(); | |
65 Expect.isFalse(dir.existsSync()); | |
66 } | |
67 | |
68 void testDeleteFileLink() { | |
69 var tmp = new Directory("").createTempSync(); | |
70 var path = "${tmp.path}${Platform.pathSeparator}"; | |
71 | |
72 var file = new File("${path}myFile"); | |
73 file.createSync(); | |
74 | |
75 var link = new Link("${path}myLink"); | |
76 | |
77 link.createSync(file.path); | |
78 | |
79 Expect.isTrue(link.existsSync()); | |
80 new File(link.path).deleteSync(); | |
81 Expect.isFalse(link.existsSync()); | |
82 | |
83 link.createSync(file.path); | |
84 | |
85 Expect.isTrue(link.existsSync()); | |
86 new Link(link.path).deleteSync(); | |
87 Expect.isFalse(link.existsSync()); | |
Søren Gjesse
2013/04/05 12:52:50
Add
Expect.isFalse(new File(link.path).existsSync
Anders Johnsen
2013/04/08 06:50:49
These kinds of 'exists' tests are tested in the fi
| |
88 | |
89 link.createSync(file.path); | |
90 | |
91 Expect.isTrue(link.existsSync()); | |
92 Expect.throws(() => new Directory(link.path).deleteSync()); | |
93 Expect.isTrue(link.existsSync()); | |
Søren Gjesse
2013/04/05 12:52:50
Add
Expect.isTrue(new File(link.path).existsSync(
Anders Johnsen
2013/04/08 06:50:49
Ditto
| |
94 | |
95 Expect.isTrue(link.existsSync()); | |
96 Expect.throws(() => new Directory(link.path).deleteSync(recursive: true)); | |
97 Expect.isTrue(link.existsSync()); | |
98 | |
99 link.deleteSync(); | |
100 Expect.isFalse(link.existsSync()); | |
101 | |
102 Expect.isTrue(file.existsSync()); | |
103 file.deleteSync(); | |
104 Expect.isFalse(file.existsSync()); | |
105 | |
106 tmp.deleteSync(); | |
107 } | |
108 | |
109 void testDeleteDirectoryLink() { | |
110 var tmp = new Directory("").createTempSync(); | |
111 var path = "${tmp.path}${Platform.pathSeparator}"; | |
112 | |
113 var directory = new Directory("${path}myDirectory"); | |
114 directory.createSync(); | |
115 | |
116 var link = new Link("${path}myLink"); | |
117 | |
118 link.createSync(directory.path); | |
119 | |
120 Expect.isTrue(link.existsSync()); | |
121 new Link(link.path).deleteSync(); | |
122 Expect.isFalse(link.existsSync()); | |
123 | |
124 link.createSync(directory.path); | |
125 | |
126 Expect.isTrue(link.existsSync()); | |
127 new Directory(link.path).deleteSync(); | |
128 Expect.isFalse(link.existsSync()); | |
129 | |
130 link.createSync(directory.path); | |
131 | |
132 Expect.isTrue(link.existsSync()); | |
133 new Directory(link.path).deleteSync(recursive: true); | |
134 Expect.isFalse(link.existsSync()); | |
135 | |
136 link.createSync(directory.path); | |
137 | |
138 Expect.isTrue(link.existsSync()); | |
139 Expect.throws(() => new File(link.path).deleteSync()); | |
140 Expect.isTrue(link.existsSync()); | |
141 | |
142 link.deleteSync(); | |
143 Expect.isFalse(link.existsSync()); | |
144 | |
145 Expect.isTrue(directory.existsSync()); | |
146 directory.deleteSync(); | |
147 Expect.isFalse(directory.existsSync()); | |
148 | |
149 tmp.deleteSync(); | |
150 } | |
151 | |
152 void testDeleteBrokenLink() { | |
153 var tmp = new Directory("").createTempSync(); | |
154 var path = "${tmp.path}${Platform.pathSeparator}"; | |
155 | |
156 var directory = new Directory("${path}myDirectory"); | |
157 directory.createSync(); | |
158 | |
159 var link = new Link("${path}myLink"); | |
160 | |
161 link.createSync(directory.path); | |
162 directory.deleteSync(); | |
163 | |
164 Expect.isTrue(link.existsSync()); | |
165 new Link(link.path).deleteSync(); | |
166 Expect.isFalse(link.existsSync()); | |
167 | |
168 directory.createSync(); | |
169 link.createSync(directory.path); | |
170 directory.deleteSync(); | |
171 | |
172 Expect.isTrue(link.existsSync()); | |
173 Expect.throws(() => new Directory(link.path).deleteSync()); | |
174 Expect.isTrue(link.existsSync()); | |
175 | |
176 Expect.isTrue(link.existsSync()); | |
177 Expect.throws(() => new Directory(link.path).deleteSync(recursive: true)); | |
178 Expect.isTrue(link.existsSync()); | |
179 | |
180 Expect.isTrue(link.existsSync()); | |
181 Expect.throws(() => new File(link.path).deleteSync()); | |
182 Expect.isTrue(link.existsSync()); | |
183 | |
184 link.deleteSync(); | |
185 Expect.isFalse(link.existsSync()); | |
186 | |
187 tmp.deleteSync(); | |
188 } | |
189 | |
190 void main() { | |
191 testDeleteFile(); | |
192 testDeleteDirectory(); | |
193 // Not available on Windows. | |
Søren Gjesse
2013/04/05 12:52:50
Just use
if (Platform.operatingSystem != 'wind
Anders Johnsen
2013/04/08 06:50:49
Done.
| |
194 //testDeleteFileLink(); | |
195 testDeleteDirectoryLink(); | |
196 testDeleteBrokenLink(); | |
197 } | |
OLD | NEW |