@@ -24,9 +24,17 @@ fn prepare(filename: &str) -> PathBuf {
24
24
path
25
25
}
26
26
27
+ /// Prepare like above, and also write some initial content to the file.
28
+ fn prepare_with_content ( filename : & str , content : & [ u8 ] ) -> PathBuf {
29
+ let path = prepare ( filename) ;
30
+ let mut file = File :: create ( & path) . unwrap ( ) ;
31
+ file. write ( content) . unwrap ( ) ;
32
+ path
33
+ }
34
+
27
35
fn test_file ( ) {
28
- let path = prepare ( "miri_test_fs_file.txt" ) ;
29
36
let bytes = b"Hello, World!\n " ;
37
+ let path = prepare ( "miri_test_fs_file.txt" ) ;
30
38
31
39
// Test creating, writing and closing a file (closing is tested when `file` is dropped).
32
40
let mut file = File :: create ( & path) . unwrap ( ) ;
@@ -50,11 +58,8 @@ fn test_file() {
50
58
}
51
59
52
60
fn test_file_clone ( ) {
53
- let path = prepare ( "miri_test_fs_file_clone.txt" ) ;
54
61
let bytes = b"Hello, World!\n " ;
55
-
56
- let mut file = File :: create ( & path) . unwrap ( ) ;
57
- file. write ( bytes) . unwrap ( ) ;
62
+ let path = prepare_with_content ( "miri_test_fs_file_clone.txt" , bytes) ;
58
63
59
64
// Cloning a file should be successful.
60
65
let file = File :: open ( & path) . unwrap ( ) ;
@@ -69,11 +74,8 @@ fn test_file_clone() {
69
74
}
70
75
71
76
fn test_seek ( ) {
72
- let path = prepare ( "miri_test_fs_seek.txt" ) ;
73
- let bytes = b"Hello, World!\n " ;
74
-
75
- let mut file = File :: create ( & path) . unwrap ( ) ;
76
- file. write ( bytes) . unwrap ( ) ;
77
+ let bytes = b"Hello, entire World!\n " ;
78
+ let path = prepare_with_content ( "miri_test_fs_seek.txt" , bytes) ;
77
79
78
80
let mut file = File :: open ( & path) . unwrap ( ) ;
79
81
let mut contents = Vec :: new ( ) ;
@@ -110,11 +112,8 @@ fn check_metadata(bytes: &[u8], path: &Path) -> Result<()> {
110
112
}
111
113
112
114
fn test_metadata ( ) {
113
- let path = prepare ( "miri_test_fs_metadata.txt" ) ;
114
- let bytes = b"Hello, World!\n " ;
115
-
116
- let mut file = File :: create ( & path) . unwrap ( ) ;
117
- file. write ( bytes) . unwrap ( ) ;
115
+ let bytes = b"Hello, meta-World!\n " ;
116
+ let path = prepare_with_content ( "miri_test_fs_metadata.txt" , bytes) ;
118
117
119
118
// Test that metadata of an absolute path is correct.
120
119
check_metadata ( bytes, & path) . unwrap ( ) ;
@@ -127,12 +126,9 @@ fn test_metadata() {
127
126
}
128
127
129
128
fn test_symlink ( ) {
130
- let path = prepare ( "miri_test_fs_link_target.txt" ) ;
131
- let symlink_path = prepare ( "miri_test_fs_symlink.txt" ) ;
132
129
let bytes = b"Hello, World!\n " ;
133
-
134
- let mut file = File :: create ( & path) . unwrap ( ) ;
135
- file. write ( bytes) . unwrap ( ) ;
130
+ let path = prepare_with_content ( "miri_test_fs_link_target.txt" , bytes) ;
131
+ let symlink_path = prepare ( "miri_test_fs_symlink.txt" ) ;
136
132
137
133
// Creating a symbolic link should succeed.
138
134
std:: os:: unix:: fs:: symlink ( & path, & symlink_path) . unwrap ( ) ;
@@ -153,8 +149,8 @@ fn test_symlink() {
153
149
}
154
150
155
151
fn test_errors ( ) {
156
- let path = prepare ( "miri_test_fs_errors.txt" ) ;
157
152
let bytes = b"Hello, World!\n " ;
153
+ let path = prepare ( "miri_test_fs_errors.txt" ) ;
158
154
159
155
// The following tests also check that the `__errno_location()` shim is working properly.
160
156
// Opening a non-existing file should fail with a "not found" error.
0 commit comments