2015-11-16 05:25:01 +00:00
|
|
|
use common::util::*;
|
|
|
|
static UTIL_NAME: &'static str = "cp";
|
2016-07-29 21:26:32 +00:00
|
|
|
fn at_and_ucmd() -> (AtPath, UCommand) {
|
|
|
|
let ts = TestScenario::new(UTIL_NAME);
|
|
|
|
let ucmd = ts.ucmd();
|
|
|
|
(ts.fixtures, ucmd)
|
|
|
|
}
|
2015-11-16 05:25:01 +00:00
|
|
|
|
|
|
|
static TEST_HELLO_WORLD_SOURCE: &'static str = "hello_world.txt";
|
|
|
|
static TEST_HELLO_WORLD_DEST: &'static str = "copy_of_hello_world.txt";
|
2016-07-15 17:17:30 +00:00
|
|
|
static TEST_COPY_TO_FOLDER: &'static str = "hello_dir/";
|
|
|
|
static TEST_COPY_TO_FOLDER_FILE: &'static str = "hello_dir/hello_world.txt";
|
|
|
|
static TEST_COPY_FROM_FOLDER_FILE: &'static str = "hello_dir_with_file/hello_world.txt";
|
2015-11-16 05:25:01 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_cp_cp() {
|
2016-07-29 21:26:32 +00:00
|
|
|
let (at, mut ucmd) = at_and_ucmd();
|
2015-11-16 05:25:01 +00:00
|
|
|
// Invoke our binary to make the copy.
|
|
|
|
let result = ucmd.arg(TEST_HELLO_WORLD_SOURCE)
|
|
|
|
.arg(TEST_HELLO_WORLD_DEST)
|
|
|
|
.run();
|
|
|
|
|
|
|
|
// Check that the exit code represents a successful copy.
|
|
|
|
let exit_success = result.success;
|
2016-07-15 17:17:30 +00:00
|
|
|
assert!(exit_success);
|
2015-11-16 05:25:01 +00:00
|
|
|
|
|
|
|
// Check the content of the destination file that was copied.
|
|
|
|
assert_eq!(at.read(TEST_HELLO_WORLD_DEST), "Hello, World!\n");
|
|
|
|
}
|
2016-07-15 17:17:30 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_cp_with_dirs_t() {
|
2016-07-29 21:26:32 +00:00
|
|
|
let (at, mut ucmd) = at_and_ucmd();
|
2016-07-15 17:17:30 +00:00
|
|
|
|
|
|
|
//using -t option
|
2016-07-29 21:26:32 +00:00
|
|
|
let result_to_dir_t = ucmd
|
2016-07-15 17:17:30 +00:00
|
|
|
.arg("-t")
|
|
|
|
.arg(TEST_COPY_TO_FOLDER)
|
|
|
|
.arg(TEST_HELLO_WORLD_SOURCE)
|
|
|
|
.run();
|
|
|
|
assert!(result_to_dir_t.success);
|
|
|
|
assert_eq!(at.read(TEST_COPY_TO_FOLDER_FILE), "Hello, World!\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_cp_with_dirs() {
|
2016-07-29 21:26:32 +00:00
|
|
|
let scene = TestScenario::new(UTIL_NAME);
|
|
|
|
let at = &scene.fixtures;
|
2016-07-15 17:17:30 +00:00
|
|
|
|
|
|
|
//using -t option
|
2016-07-29 21:26:32 +00:00
|
|
|
let result_to_dir = scene.ucmd()
|
2016-07-15 17:17:30 +00:00
|
|
|
.arg(TEST_HELLO_WORLD_SOURCE)
|
|
|
|
.arg(TEST_COPY_TO_FOLDER)
|
|
|
|
.run();
|
2016-07-15 19:29:47 +00:00
|
|
|
assert!(result_to_dir.success);
|
2016-07-15 17:17:30 +00:00
|
|
|
assert_eq!(at.read(TEST_COPY_TO_FOLDER_FILE), "Hello, World!\n");
|
|
|
|
|
2016-07-29 21:26:32 +00:00
|
|
|
let result_from_dir = scene.ucmd()
|
2016-07-15 17:17:30 +00:00
|
|
|
.arg(TEST_COPY_FROM_FOLDER_FILE)
|
|
|
|
.arg(TEST_HELLO_WORLD_DEST)
|
|
|
|
.run();
|
2016-07-15 19:29:47 +00:00
|
|
|
assert!(result_from_dir.success);
|
2016-07-15 17:17:30 +00:00
|
|
|
assert_eq!(at.read(TEST_HELLO_WORLD_DEST), "Hello, World!\n");
|
2016-07-29 21:26:32 +00:00
|
|
|
}
|