1
1
//@ignore-target-windows: File handling is not implemented yet
2
2
//@compile-flags: -Zmiri-disable-isolation
3
3
4
- // If this test is failing for you locally, you can try
5
- // 1. Deleting the files `/tmp/miri_*`
6
- // 2. Setting `MIRI_TEMP` or `TMPDIR` to a different directory, without the `miri_*` files
7
-
8
4
#![ feature( io_error_more) ]
9
5
#![ feature( io_error_uncategorized) ]
10
6
11
7
use std:: collections:: HashMap ;
12
8
use std:: ffi:: OsString ;
13
9
use std:: fs:: {
14
- canonicalize, create_dir, read_dir, read_link , remove_dir, remove_dir_all, remove_file, rename,
15
- File , OpenOptions ,
10
+ canonicalize, create_dir, read_dir, remove_dir, remove_dir_all, remove_file, rename, File ,
11
+ OpenOptions ,
16
12
} ;
17
13
use std:: io:: { Error , ErrorKind , IsTerminal , Read , Result , Seek , SeekFrom , Write } ;
18
- use std:: path:: { Path , PathBuf } ;
14
+ use std:: path:: Path ;
19
15
20
16
#[ path = "../../utils/mod.rs" ]
21
17
mod utils;
@@ -29,38 +25,13 @@ fn main() {
29
25
test_metadata ( ) ;
30
26
test_file_set_len ( ) ;
31
27
test_file_sync ( ) ;
32
- test_symlink ( ) ;
33
28
test_errors ( ) ;
34
29
test_rename ( ) ;
35
30
test_directory ( ) ;
36
31
test_canonicalize ( ) ;
37
32
test_from_raw_os_error ( ) ;
38
33
}
39
34
40
- /// Prepare: compute filename and make sure the file does not exist.
41
- fn prepare ( filename : & str ) -> PathBuf {
42
- let path = utils:: tmp ( ) . join ( filename) ;
43
- // Clean the paths for robustness.
44
- remove_file ( & path) . ok ( ) ;
45
- path
46
- }
47
-
48
- /// Prepare directory: compute directory name and make sure it does not exist.
49
- fn prepare_dir ( dirname : & str ) -> PathBuf {
50
- let path = utils:: tmp ( ) . join ( & dirname) ;
51
- // Clean the directory for robustness.
52
- remove_dir_all ( & path) . ok ( ) ;
53
- path
54
- }
55
-
56
- /// Prepare like above, and also write some initial content to the file.
57
- fn prepare_with_content ( filename : & str , content : & [ u8 ] ) -> PathBuf {
58
- let path = prepare ( filename) ;
59
- let mut file = File :: create ( & path) . unwrap ( ) ;
60
- file. write ( content) . unwrap ( ) ;
61
- path
62
- }
63
-
64
35
fn test_path_conversion ( ) {
65
36
let tmp = utils:: tmp ( ) ;
66
37
assert ! ( tmp. is_absolute( ) , "{:?} is not absolute" , tmp) ;
@@ -69,7 +40,7 @@ fn test_path_conversion() {
69
40
70
41
fn test_file ( ) {
71
42
let bytes = b"Hello, World!\n " ;
72
- let path = prepare ( "miri_test_fs_file.txt" ) ;
43
+ let path = utils :: prepare ( "miri_test_fs_file.txt" ) ;
73
44
74
45
// Test creating, writing and closing a file (closing is tested when `file` is dropped).
75
46
let mut file = File :: create ( & path) . unwrap ( ) ;
@@ -96,7 +67,7 @@ fn test_file() {
96
67
97
68
fn test_file_clone ( ) {
98
69
let bytes = b"Hello, World!\n " ;
99
- let path = prepare_with_content ( "miri_test_fs_file_clone.txt" , bytes) ;
70
+ let path = utils :: prepare_with_content ( "miri_test_fs_file_clone.txt" , bytes) ;
100
71
101
72
// Cloning a file should be successful.
102
73
let file = File :: open ( & path) . unwrap ( ) ;
@@ -111,7 +82,7 @@ fn test_file_clone() {
111
82
}
112
83
113
84
fn test_file_create_new ( ) {
114
- let path = prepare ( "miri_test_fs_file_create_new.txt" ) ;
85
+ let path = utils :: prepare ( "miri_test_fs_file_create_new.txt" ) ;
115
86
116
87
// Creating a new file that doesn't yet exist should succeed.
117
88
OpenOptions :: new ( ) . write ( true ) . create_new ( true ) . open ( & path) . unwrap ( ) ;
@@ -129,7 +100,7 @@ fn test_file_create_new() {
129
100
130
101
fn test_seek ( ) {
131
102
let bytes = b"Hello, entire World!\n " ;
132
- let path = prepare_with_content ( "miri_test_fs_seek.txt" , bytes) ;
103
+ let path = utils :: prepare_with_content ( "miri_test_fs_seek.txt" , bytes) ;
133
104
134
105
let mut file = File :: open ( & path) . unwrap ( ) ;
135
106
let mut contents = Vec :: new ( ) ;
@@ -168,7 +139,7 @@ fn check_metadata(bytes: &[u8], path: &Path) -> Result<()> {
168
139
169
140
fn test_metadata ( ) {
170
141
let bytes = b"Hello, meta-World!\n " ;
171
- let path = prepare_with_content ( "miri_test_fs_metadata.txt" , bytes) ;
142
+ let path = utils :: prepare_with_content ( "miri_test_fs_metadata.txt" , bytes) ;
172
143
173
144
// Test that metadata of an absolute path is correct.
174
145
check_metadata ( bytes, & path) . unwrap ( ) ;
@@ -182,7 +153,7 @@ fn test_metadata() {
182
153
183
154
fn test_file_set_len ( ) {
184
155
let bytes = b"Hello, World!\n " ;
185
- let path = prepare_with_content ( "miri_test_fs_set_len.txt" , bytes) ;
156
+ let path = utils :: prepare_with_content ( "miri_test_fs_set_len.txt" , bytes) ;
186
157
187
158
// Test extending the file
188
159
let mut file = OpenOptions :: new ( ) . read ( true ) . write ( true ) . open ( & path) . unwrap ( ) ;
@@ -208,7 +179,7 @@ fn test_file_set_len() {
208
179
209
180
fn test_file_sync ( ) {
210
181
let bytes = b"Hello, World!\n " ;
211
- let path = prepare_with_content ( "miri_test_fs_sync.txt" , bytes) ;
182
+ let path = utils :: prepare_with_content ( "miri_test_fs_sync.txt" , bytes) ;
212
183
213
184
// Test that we can call sync_data and sync_all (can't readily test effects of this operation)
214
185
let file = OpenOptions :: new ( ) . write ( true ) . open ( & path) . unwrap ( ) ;
@@ -223,38 +194,9 @@ fn test_file_sync() {
223
194
remove_file ( & path) . unwrap ( ) ;
224
195
}
225
196
226
- fn test_symlink ( ) {
227
- let bytes = b"Hello, World!\n " ;
228
- let path = prepare_with_content ( "miri_test_fs_link_target.txt" , bytes) ;
229
- let symlink_path = prepare ( "miri_test_fs_symlink.txt" ) ;
230
-
231
- // Creating a symbolic link should succeed.
232
- #[ cfg( unix) ]
233
- std:: os:: unix:: fs:: symlink ( & path, & symlink_path) . unwrap ( ) ;
234
- #[ cfg( windows) ]
235
- std:: os:: windows:: fs:: symlink_file ( & path, & symlink_path) . unwrap ( ) ;
236
- // Test that the symbolic link has the same contents as the file.
237
- let mut symlink_file = File :: open ( & symlink_path) . unwrap ( ) ;
238
- let mut contents = Vec :: new ( ) ;
239
- symlink_file. read_to_end ( & mut contents) . unwrap ( ) ;
240
- assert_eq ! ( bytes, contents. as_slice( ) ) ;
241
-
242
- // Test that metadata of a symbolic link (i.e., the file it points to) is correct.
243
- check_metadata ( bytes, & symlink_path) . unwrap ( ) ;
244
- // Test that the metadata of a symbolic link is correct when not following it.
245
- assert ! ( symlink_path. symlink_metadata( ) . unwrap( ) . file_type( ) . is_symlink( ) ) ;
246
- // Check that we can follow the link.
247
- assert_eq ! ( read_link( & symlink_path) . unwrap( ) , path) ;
248
- // Removing symbolic link should succeed.
249
- remove_file ( & symlink_path) . unwrap ( ) ;
250
-
251
- // Removing file should succeed.
252
- remove_file ( & path) . unwrap ( ) ;
253
- }
254
-
255
197
fn test_errors ( ) {
256
198
let bytes = b"Hello, World!\n " ;
257
- let path = prepare ( "miri_test_fs_errors.txt" ) ;
199
+ let path = utils :: prepare ( "miri_test_fs_errors.txt" ) ;
258
200
259
201
// The following tests also check that the `__errno_location()` shim is working properly.
260
202
// Opening a non-existing file should fail with a "not found" error.
@@ -269,8 +211,8 @@ fn test_errors() {
269
211
270
212
fn test_rename ( ) {
271
213
// Renaming a file should succeed.
272
- let path1 = prepare ( "miri_test_fs_rename_source.txt" ) ;
273
- let path2 = prepare ( "miri_test_fs_rename_destination.txt" ) ;
214
+ let path1 = utils :: prepare ( "miri_test_fs_rename_source.txt" ) ;
215
+ let path2 = utils :: prepare ( "miri_test_fs_rename_destination.txt" ) ;
274
216
275
217
let file = File :: create ( & path1) . unwrap ( ) ;
276
218
drop ( file) ;
@@ -289,7 +231,7 @@ fn test_rename() {
289
231
}
290
232
291
233
fn test_canonicalize ( ) {
292
- let dir_path = prepare_dir ( "miri_test_fs_dir" ) ;
234
+ let dir_path = utils :: prepare_dir ( "miri_test_fs_dir" ) ;
293
235
create_dir ( & dir_path) . unwrap ( ) ;
294
236
let path = dir_path. join ( "test_file" ) ;
295
237
drop ( File :: create ( & path) . unwrap ( ) ) ;
@@ -301,7 +243,7 @@ fn test_canonicalize() {
301
243
}
302
244
303
245
fn test_directory ( ) {
304
- let dir_path = prepare_dir ( "miri_test_fs_dir" ) ;
246
+ let dir_path = utils :: prepare_dir ( "miri_test_fs_dir" ) ;
305
247
// Creating a directory should succeed.
306
248
create_dir ( & dir_path) . unwrap ( ) ;
307
249
// Test that the metadata of a directory is correct.
0 commit comments