1 // ignore-windows: File handling is not implemented yet
2 // compile-flags: -Zmiri-disable-isolation
5 use std::io::{ Read, Write };
8 // FIXME: remove the file and delete it when `rm` is implemented.
9 let path = "./tests/hello.txt";
10 let bytes = b"Hello, World!\n";
11 // Test creating, writing and closing a file (closing is tested when `file` is dropped).
12 let mut file = File::create(path).unwrap();
13 file.write(bytes).unwrap();
14 // Test opening, reading and closing a file.
15 let mut file = File::open(path).unwrap();
16 let mut contents = Vec::new();
17 // Reading 0 bytes should not fill `contents`.
18 file.read(&mut contents).unwrap();
19 assert!(contents.is_empty());
20 // Reading until EOF should get the whole text.
21 file.read_to_end(&mut contents).unwrap();
22 assert_eq!(bytes, contents.as_slice());