core-utils 0.1.2

A reimplementation of the GNU core utils in the Rust programming language
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]
//fn test_cat_all() {
    //let prog = Command::new(PROG)
                        //.arg("-a")
                        //.arg("tests/items/file.txt")
                        //.arg("tests/items/dir/main.rs")
                        //.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_newline() {
    //let prog = Command::new(PROG)
                        //.arg("-E")
                        //.arg("tests/items/file.txt")
                        //.arg("tests/items/dir/main.rs")
                        //.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");
}