@@ -5,26 +5,26 @@ use std::fs::{File, remove_file};
5
5
use std:: io:: { Read , Write } ;
6
6
7
7
fn main ( ) {
8
- let path = "miri_test_fs.txt" ;
8
+ let path = std :: env :: temp_dir ( ) . join ( "miri_test_fs.txt" ) ;
9
9
let bytes = b"Hello, World!\n " ;
10
10
// Test creating, writing and closing a file (closing is tested when `file` is dropped).
11
- let mut file = File :: create ( path) . unwrap ( ) ;
11
+ let mut file = File :: create ( & path) . unwrap ( ) ;
12
12
// Writing 0 bytes should not change the file contents.
13
13
file. write ( & mut [ ] ) . unwrap ( ) ;
14
14
15
15
file. write ( bytes) . unwrap ( ) ;
16
16
// Test opening, reading and closing a file.
17
- let mut file = File :: open ( path) . unwrap ( ) ;
17
+ let mut file = File :: open ( & path) . unwrap ( ) ;
18
18
let mut contents = Vec :: new ( ) ;
19
19
// Reading 0 bytes should not move the file pointer.
20
20
file. read ( & mut [ ] ) . unwrap ( ) ;
21
21
// Reading until EOF should get the whole text.
22
22
file. read_to_end ( & mut contents) . unwrap ( ) ;
23
23
assert_eq ! ( bytes, contents. as_slice( ) ) ;
24
24
// Removing file should succeed
25
- remove_file ( path) . unwrap ( ) ;
25
+ remove_file ( & path) . unwrap ( ) ;
26
26
// Opening non-existing file should fail
27
- assert ! ( File :: open( path) . is_err( ) ) ;
27
+ assert ! ( File :: open( & path) . is_err( ) ) ;
28
28
// Removing non-existing file should fail
29
- assert ! ( remove_file( path) . is_err( ) ) ;
29
+ assert ! ( remove_file( & path) . is_err( ) ) ;
30
30
}
0 commit comments