rust/tests/run-pass/file_read.rs

20 lines
679 B
Rust
Raw Normal View History

2019-09-24 17:28:00 -05:00
// ignore-windows: File handling is not implemented yet
// compile-flags: -Zmiri-disable-isolation
use std::fs::File;
2019-09-30 11:46:07 -05:00
use std::io::{ Read, Write };
2019-09-24 17:28:00 -05:00
fn main() {
2019-09-30 11:46:07 -05:00
// FIXME: remove the file and delete it when `rm` is implemented.
// Test creating, writing and closing a file (closing is tested when `file` is dropped).
let mut file = File::create("./tests/hello.txt").unwrap();
file.write(b"Hello, World!\n").unwrap();
// Test opening, reading and closing a file.
2019-09-24 17:28:00 -05:00
let mut file = File::open("./tests/hello.txt").unwrap();
let mut contents = String::new();
file.read_to_string(&mut contents).unwrap();
assert_eq!("Hello, World!\n", contents);
}