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/cp";

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

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

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

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

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

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

#[test]
#[should_panic]
fn test_cp_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 cp: {}", e) });
    assert_eq!(prog.status.success(), true);
    println!("{}", String::from_utf8_lossy(&prog.stdout));
}

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

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

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

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

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

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

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

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

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

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