extern crate rpf;
use rpf::test;
use std::fs::File;
use std::io::prelude::*;
use std::process::Command;
static PROG: &'static str = "target/debug/cat";
#[test]
#[should_panic]
fn test_cat_bad_option() {
let prog = Command::new(PROG)
.arg("--fail")
.output()
.unwrap_or_else(|e| { panic!("Failed to run test for cat: {}", e) });
assert_eq!(prog.status.success(), true);
println!("{}", String::from_utf8_lossy(&prog.stdout));
}
#[test]
fn test_cat_help() {
let prog = Command::new(PROG)
.arg("--help")
.output()
.unwrap_or_else(|e| { panic!("Failed to run test for cat: {}", e) });
assert_eq!(prog.status.success(), true);
println!("{}", String::from_utf8_lossy(&prog.stdout));
}
#[test]
#[should_panic]
fn test_cat_fail() {
let prog = Command::new(PROG)
.arg("tests/items/file-fail.txt")
.output()
.unwrap_or_else(|e| { panic!("Failed to run test for cat: {}", e) });
assert_eq!(prog.status.success(), true);
println!("{}", String::from_utf8_lossy(&prog.stdout));
}
#[test]
fn test_cat_binary_success() {
let prog = Command::new(PROG)
.arg("tests/items/binary-file")
.output()
.unwrap_or_else(|e| { panic!("Failed to run test for cat: {}", e) });
let mut file = File::create("binary-test-file").unwrap();
file.write_all(&prog.stdout).unwrap();
let diff = Command::new("diff")
.arg("tests/items/binary-file")
.arg("binary-file-test")
.output()
.unwrap_or_else(|e| { panic!("Failed to run test for cat: {}", e) });
assert_eq!(prog.status.success(), true);
println!("{}", String::from_utf8_lossy(&diff.stdout));
println!("{}", String::from_utf8_lossy(&prog.stdout));
test::remove("binary-test-file");
}