core-utils 0.1.2

A reimplementation of the GNU core utils in the Rust programming language
extern crate rpf;

use std::process::Command;
use rpf::test;

static PROG: &'static str = "target/debug/rm";

#[test]
#[should_panic]
fn test_rm_bad_option() {
    let prog = Command::new(PROG)
                        .arg("--fail")
                        .output()
                        .unwrap_or_else(|e| { panic!("Failed to run test for rm: {}", e) });
    assert_eq!(prog.status.success(), true);
    println!("{}", String::from_utf8_lossy(&prog.stdout));
}

#[test]
fn test_rm_help() {
    let prog = Command::new(PROG)
                        .arg("--help")
                        .output()
                        .unwrap_or_else(|e| { panic!("Failed to run test for rm: {}", e) });
    assert_eq!(prog.status.success(), true);
    println!("{}", String::from_utf8_lossy(&prog.stdout));
}

#[test]
fn test_rm_recursive_success() {
    test::create_dir("tests/things");
    test::create_dir("tests/stuff");
    let prog = Command::new(PROG)
                        .arg("-r")
                        .arg("-v")
                        .arg("tests/things")
                        .arg("tests/stuff")
                        .output()
                        .unwrap_or_else(|e| { panic!("Failed to run test for rm: {}", e) });
    assert_eq!(prog.status.success(), true);
    println!("{}", String::from_utf8_lossy(&prog.stdout));
}

#[test]
#[should_panic]
fn test_rm_recursive_fail_non_exist() {
    let prog = Command::new(PROG)
                        .arg("-r")
                        .arg("-v")
                        .arg("test")
                        .arg("tests/items/file.txt")
                        .output()
                        .unwrap_or_else(|e| { panic!("Failed to run test for rm: {}", e) });
    assert_eq!(prog.status.success(), true);
    println!("{}", String::from_utf8_lossy(&prog.stdout));
}

#[test]
#[should_panic]
fn test_rm_recursive_fail_no_opt() {
    test::create_dir("tests/items/test-no-opt");
    let prog = Command::new(PROG)
                        .arg("-v")
                        .arg("tests/items/test-no-opt")
                        .output()
                        .unwrap_or_else(|e| { panic!("Failed to run test for rm: {}", e) });
    assert_eq!(prog.status.success(), true);
    println!("{}", String::from_utf8_lossy(&prog.stdout));
    test::remove("tests/items/test-no-opt");
}

#[test]
fn test_rm_file_success() {
    test::create_file("tests/items/test-file.txt");
    let prog = Command::new(PROG)
                        .arg("-v")
                        .arg("tests/items/test-file.txt")
                        .output()
                        .unwrap_or_else(|e| { panic!("Failed to run test for rm: {}", e) });
    assert_eq!(prog.status.success(), true);
    println!("{}", String::from_utf8_lossy(&prog.stdout));
}

#[test]
#[should_panic]
fn test_rm_file_fail() {
    let prog = Command::new(PROG)
                        .arg("-v")
                        .arg("tests/items/file-fail.txt")
                        .arg("tests/items/test-fail.txt")
                        .output()
                        .unwrap_or_else(|e| { panic!("Failed to run test for rm: {}", e) });
    assert_eq!(prog.status.success(), true);
    println!("{}", String::from_utf8_lossy(&prog.stdout));
}