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