2015-05-29 17:47:00 +00:00
|
|
|
use std::fs::File;
|
2015-05-05 23:42:38 +00:00
|
|
|
use std::io::Read;
|
2015-05-29 17:47:00 +00:00
|
|
|
use std::path::Path;
|
2015-05-05 23:42:38 +00:00
|
|
|
use std::process::Command;
|
2015-05-29 17:47:00 +00:00
|
|
|
use util::*;
|
2014-10-13 20:26:14 +00:00
|
|
|
|
2015-05-29 17:47:00 +00:00
|
|
|
static PROGNAME: &'static str = "./cp";
|
2014-10-13 20:26:14 +00:00
|
|
|
static TEST_HELLO_WORLD_SOURCE: &'static str = "hello_world.txt";
|
|
|
|
static TEST_HELLO_WORLD_DEST: &'static str = "copy_of_hello_world.txt";
|
|
|
|
|
2015-05-29 17:47:00 +00:00
|
|
|
#[path = "common/util.rs"]
|
|
|
|
#[macro_use]
|
|
|
|
mod util;
|
2014-10-13 20:26:14 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_cp_cp() {
|
|
|
|
// Invoke our binary to make the copy.
|
2015-05-29 17:47:00 +00:00
|
|
|
let prog = Command::new(PROGNAME)
|
2014-10-13 20:26:14 +00:00
|
|
|
.arg(TEST_HELLO_WORLD_SOURCE)
|
|
|
|
.arg(TEST_HELLO_WORLD_DEST)
|
|
|
|
.status();
|
|
|
|
|
|
|
|
// Check that the exit code represents a successful copy.
|
|
|
|
let exit_success = prog.unwrap().success();
|
|
|
|
assert_eq!(exit_success, true);
|
|
|
|
|
|
|
|
// Check the content of the destination file that was copied.
|
2015-05-05 23:42:38 +00:00
|
|
|
let mut contents = String::new();
|
|
|
|
let mut f = File::open(Path::new(TEST_HELLO_WORLD_DEST)).unwrap();
|
|
|
|
let _ = f.read_to_string(&mut contents);
|
|
|
|
assert_eq!(contents, "Hello, World!\n");
|
2014-10-13 20:26:14 +00:00
|
|
|
|
|
|
|
cleanup(TEST_HELLO_WORLD_SOURCE);
|
|
|
|
cleanup(TEST_HELLO_WORLD_DEST);
|
|
|
|
}
|