use std::fs::File;
use std::io::{stderr, stdout, Read, Write};
use io_redirect::redirect_std_to_path;
fn main() {
let tempdir = tempfile::tempdir().unwrap();
let log_path = tempdir.path().join("log.txt");
redirect_std_to_path(log_path.as_path(), true).unwrap();
print!("Hello to stdout!");
stdout().flush().unwrap();
eprint!("Hello to stderr!");
stderr().flush().unwrap();
let mut dst_contents = String::new();
File::open(&log_path).unwrap().read_to_string(&mut dst_contents).unwrap();
assert_eq!(dst_contents, "Hello to stdout!Hello to stderr!");
}