use std::fs::File;
use std::io::Read;
use std::error::Error;
fn read_file_contents(file:&str) -> String {
let f_opt = File::open(file);
assert!(f_opt.is_ok(), "Couldn't open {} to check contents", file);
let mut f = f_opt.unwrap();
let mut buffer:String = String::new();
loop {
let read_result = f.read_to_string(&mut buffer);
match read_result {
Ok(0) => break,
Ok(_) => continue,
Err(err) =>
panic!(
"Failed to read all contents of {}. Error: {}",
file,
err.description()),
}
}
buffer
}
pub fn assert_file_contains_line(file:&str, expected_line:&str){
let contents = read_file_contents(file);
for line in contents.lines() {
if line == expected_line {
return;
}
}
panic!("Line {} not found in {}", expected_line, file);
}
pub fn assert_file_contents_eq(file:&str, contents:&str){
let actual_contents = read_file_contents(file);
assert_eq!(<String as AsRef<str>>::as_ref(&actual_contents), contents);
}