rewrite tests for cargo compat, decoupled directory, output handling

This commit is contained in:
Nathan Ross
2015-11-16 00:25:01 -05:00
parent b20b2cca19
commit a21c54e2cd
165 changed files with 4315 additions and 3538 deletions
+13
View File
@@ -157,6 +157,19 @@ wc = { optional=true, path="src/wc" }
whoami = { optional=true, path="src/whoami" }
yes = { optional=true, path="src/yes" }
[dev-dependencies]
time = "*"
kernel32-sys = "*"
winapi = "*"
filetime = "*"
libc = "*"
memchr = "*"
primal = "*"
aho-corasick= "*"
regex-syntax= "*"
regex="*"
rand="*"
tempdir="*"
[[bin]]
name="uutils"
+1 -1
View File
@@ -18,7 +18,7 @@ LIBDIR ?= /lib
BASEDIR ?= $(shell pwd)
SRCDIR := $(BASEDIR)/src
BUILDDIR := $(BASEDIR)/build
TESTDIR := $(BASEDIR)/test
TESTDIR := $(BASEDIR)/tests
TEMPDIR := $(BASEDIR)/tmp
# Flags
-62
View File
@@ -1,62 +0,0 @@
use std::process::Command;
use util::*;
static PROGNAME: &'static str = "./base64";
#[path = "common/util.rs"]
#[macro_use]
mod util;
#[test]
fn test_encode() {
let input = "hello, world!";
let mut cmd = Command::new(PROGNAME);
let result = run_piped_stdin(&mut cmd, input.as_bytes());
assert_empty_stderr!(result);
assert!(result.success);
assert_eq!(result.stdout, "aGVsbG8sIHdvcmxkIQ==\n");
}
#[test]
fn test_decode() {
let input = "aGVsbG8sIHdvcmxkIQ==";
let mut cmd = Command::new(PROGNAME);
let result = run_piped_stdin(&mut cmd.arg("-d"), input.as_bytes());
assert_empty_stderr!(result);
assert!(result.success);
assert_eq!(result.stdout, "hello, world!");
}
#[test]
fn test_garbage() {
let input = "aGVsbG8sIHdvcmxkIQ==\0";
let mut cmd = Command::new(PROGNAME);
let result = run_piped_stdin(&mut cmd.arg("-d"), input.as_bytes());
assert!(!result.success);
assert_eq!(result.stderr, "base64: error: invalid character (Invalid character '0' at position 20)\n");
}
#[test]
fn test_ignore_garbage() {
let input = "aGVsbG8sIHdvcmxkIQ==\0";
let mut cmd = Command::new(PROGNAME);
let result = run_piped_stdin(&mut cmd.arg("-d").arg("-i"), input.as_bytes());
assert_empty_stderr!(result);
assert!(result.success);
assert_eq!(result.stdout, "hello, world!");
}
#[test]
fn test_wrap() {
let input = "The quick brown fox jumps over the lazy dog.";
let mut cmd = Command::new(PROGNAME);
let result = run_piped_stdin(&mut cmd.arg("-w").arg("20"), input.as_bytes());
assert_empty_stderr!(result);
assert!(result.success);
assert_eq!(result.stdout, "VGhlIHF1aWNrIGJyb3du\nIGZveCBqdW1wcyBvdmVy\nIHRoZSBsYXp5IGRvZy4=\n");
}
-54
View File
@@ -1,54 +0,0 @@
use std::process::Command;
use std::str;
static PROGNAME: &'static str = "./basename";
#[test]
fn test_directory() {
let dir = "/root/alpha/beta/gamma/delta/epsilon/omega/";
let po = Command::new(PROGNAME)
.arg(dir)
.output()
.unwrap_or_else(|err| panic!("{}", err));
let out = str::from_utf8(&po.stdout[..]).unwrap().trim_right();
assert_eq!(out, "omega");
}
#[test]
fn test_file() {
let file = "/etc/passwd";
let po = Command::new(PROGNAME)
.arg(file)
.output()
.unwrap_or_else(|err| panic!("{}", err));
let out = str::from_utf8(&po.stdout[..]).unwrap().trim_right();
assert_eq!(out, "passwd");
}
#[test]
fn test_remove_suffix() {
let path = "/usr/local/bin/reallylongexecutable.exe";
let po = Command::new(PROGNAME)
.arg(path)
.arg(".exe")
.output()
.unwrap_or_else(|err| panic!("{}", err));
let out = str::from_utf8(&po.stdout[..]).unwrap().trim_right();
assert_eq!(out, "reallylongexecutable");
}
#[test]
fn test_dont_remove_suffix() {
let path = "/foo/bar/baz";
let po = Command::new(PROGNAME)
.arg(path)
.arg("baz")
.output()
.unwrap_or_else(|err| panic!("{}", err));
let out = str::from_utf8(&po.stdout[..]).unwrap().trim_right();
assert_eq!(out, "baz");
}
-60
View File
@@ -1,60 +0,0 @@
use std::io::Write;
use std::process::Command;
use std::process::Stdio;
use std::str;
static PROGNAME: &'static str = "./cat";
#[test]
fn test_output_multi_files_print_all_chars() {
let po = match Command::new(PROGNAME)
.arg("alpha.txt")
.arg("256.txt")
.arg("-A")
.arg("-n").output() {
Ok(p) => p,
Err(err) => panic!("{}", err),
};
let out = str::from_utf8(&po.stdout[..]).unwrap();
assert_eq!(out,
" 1\tabcde$\n 2\tfghij$\n 3\tklmno$\n 4\tpqrst$\n 5\tuvwxyz$\n 6\t^@^A^B^C^D^E^F^G^H^I$\n 7\t^K^L^M^N^O^P^Q^R^S^T^U^V^W^X^Y^Z^[^\\^]^^^_ !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~^?M-^@M-^AM-^BM-^CM-^DM-^EM-^FM-^GM-^HM-^IM-^JM-^KM-^LM-^MM-^NM-^OM-^PM-^QM-^RM-^SM-^TM-^UM-^VM-^WM-^XM-^YM-^ZM-^[M-^\\M-^]M-^^M-^_M- M-!M-\"M-#M-$M-%M-&M-\'M-(M-)M-*M-+M-,M--M-.M-/M-0M-1M-2M-3M-4M-5M-6M-7M-8M-9M-:M-;M-<M-=M->M-?M-@M-AM-BM-CM-DM-EM-FM-GM-HM-IM-JM-KM-LM-MM-NM-OM-PM-QM-RM-SM-TM-UM-VM-WM-XM-YM-ZM-[M-\\M-]M-^M-_M-`M-aM-bM-cM-dM-eM-fM-gM-hM-iM-jM-kM-lM-mM-nM-oM-pM-qM-rM-sM-tM-uM-vM-wM-xM-yM-zM-{M-|M-}M-~M-^?");
}
#[test]
fn test_stdin_squeeze() {
let mut process = Command::new(PROGNAME)
.arg("-A")
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.spawn()
.unwrap_or_else(|e| panic!("{}", e));
process.stdin.take().unwrap_or_else(|| panic!("Could not grab child process stdin"))
.write_all("\x00\x01\x02".as_bytes()).unwrap_or_else(|e| panic!("{}", e));
let po = process.wait_with_output().unwrap_or_else(|e| panic!("{}", e));
let out = str::from_utf8(&po.stdout[..]).unwrap_or_else(|e| panic!("{}", e));
assert_eq!(out, "^@^A^B");
}
#[test]
fn test_stdin_number_non_blank() {
let mut process = Command::new(PROGNAME)
.arg("-b")
.arg("-")
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.spawn()
.unwrap_or_else(|e| panic!("{}", e));
process.stdin.take().unwrap_or_else(|| panic!("Could not grab child process stdin"))
.write_all("\na\nb\n\n\nc".as_bytes()).unwrap_or_else(|e| panic!("{}", e));
let po = process.wait_with_output().unwrap_or_else(|e| panic!("{}", e));
let out = str::from_utf8(&po.stdout[..]).unwrap_or_else(|e| panic!("{}", e));
assert_eq!(out, "\n 1\ta\n 2\tb\n\n\n 3\tc");
}
-39
View File
@@ -1,39 +0,0 @@
use std::process::Command;
use util::*;
static PROGNAME: &'static str = "./cksum";
#[path = "common/util.rs"]
#[macro_use]
mod util;
#[test]
fn test_single_file() {
let mut cmd = Command::new(PROGNAME);
let result = run(&mut cmd.arg("lorem_ipsum.txt"));
assert_empty_stderr!(result);
assert!(result.success);
assert_eq!(result.stdout, get_file_contents("single_file.expected"));
}
#[test]
fn test_multiple_files() {
let mut cmd = Command::new(PROGNAME);
let result = run(&mut cmd.arg("lorem_ipsum.txt").arg("alice_in_wonderland.txt"));
assert_empty_stderr!(result);
assert!(result.success);
assert_eq!(result.stdout, get_file_contents("multiple_files.expected"));
}
#[test]
fn test_stdin() {
let input = get_file_contents("lorem_ipsum.txt");
let mut cmd = Command::new(PROGNAME);
let result = run_piped_stdin(&mut cmd, input);
assert_empty_stderr!(result);
assert!(result.success);
assert_eq!(result.stdout, get_file_contents("stdin.expected"));
}
-152
View File
@@ -1,152 +0,0 @@
#![allow(dead_code)]
use std::env;
use std::fs::{self, File};
use std::io::{Read, Write};
#[cfg(unix)]
use std::os::unix::fs::symlink as symlink_file;
#[cfg(windows)]
use std::os::windows::fs::symlink_file;
use std::path::Path;
use std::process::{Command, Stdio};
use std::str::from_utf8;
#[macro_export]
macro_rules! assert_empty_stderr(
($cond:expr) => (
if $cond.stderr.len() > 0 {
panic!(format!("stderr: {}", $cond.stderr))
}
);
);
pub struct CmdResult {
pub success: bool,
pub stdout: String,
pub stderr: String,
}
pub fn run(cmd: &mut Command) -> CmdResult {
let prog = cmd.output().unwrap();
CmdResult {
success: prog.status.success(),
stdout: from_utf8(&prog.stdout).unwrap().to_string(),
stderr: from_utf8(&prog.stderr).unwrap().to_string(),
}
}
pub fn run_piped_stdin<T: AsRef<[u8]>>(cmd: &mut Command, input: T)-> CmdResult {
let mut command = cmd
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()
.unwrap();
command.stdin
.take()
.unwrap_or_else(|| panic!("Could not take child process stdin"))
.write_all(input.as_ref())
.unwrap_or_else(|e| panic!("{}", e));
let prog = command.wait_with_output().unwrap();
CmdResult {
success: prog.status.success(),
stdout: from_utf8(&prog.stdout).unwrap().to_string(),
stderr: from_utf8(&prog.stderr).unwrap().to_string(),
}
}
pub fn get_file_contents(name: &str) -> String {
let mut f = File::open(Path::new(name)).unwrap();
let mut contents = String::new();
let _ = f.read_to_string(&mut contents);
contents
}
pub fn set_file_contents(name: &str, contents: &str) {
let mut f = File::open(Path::new(name)).unwrap();
let _ = f.write(contents.as_bytes());
}
pub fn mkdir(dir: &str) {
fs::create_dir(Path::new(dir)).unwrap();
}
pub fn mkdir_all(dir: &str) {
fs::create_dir_all(Path::new(dir)).unwrap();
}
pub fn make_file(name: &str) -> File {
match File::create(Path::new(name)) {
Ok(f) => f,
Err(e) => panic!("{}", e)
}
}
pub fn touch(file: &str) {
File::create(Path::new(file)).unwrap();
}
pub fn symlink(src: &str, dst: &str) {
symlink_file(src, dst).unwrap();
}
pub fn is_symlink(path: &str) -> bool {
match fs::symlink_metadata(path) {
Ok(m) => m.file_type().is_symlink(),
Err(_) => false
}
}
pub fn resolve_link(path: &str) -> String {
match fs::read_link(path) {
Ok(p) => p.to_str().unwrap().to_owned(),
Err(_) => "".to_string()
}
}
pub fn metadata(path: &str) -> fs::Metadata {
match fs::metadata(path) {
Ok(m) => m,
Err(e) => panic!("{}", e)
}
}
pub fn file_exists(path: &str) -> bool {
match fs::metadata(path) {
Ok(m) => m.is_file(),
Err(_) => false
}
}
pub fn dir_exists(path: &str) -> bool {
match fs::metadata(path) {
Ok(m) => m.is_dir(),
Err(_) => false
}
}
pub fn cleanup(path: &'static str) {
let p = Path::new(path);
match fs::metadata(p) {
Ok(m) => if m.is_file() {
fs::remove_file(&p).unwrap();
} else {
fs::remove_dir(&p).unwrap();
},
Err(_) => {}
}
}
pub fn current_directory() -> String {
env::current_dir().unwrap().into_os_string().into_string().unwrap()
}
pub fn repeat_str(s: &str, n: u32) -> String {
let mut repeated = String::new();
for _ in 0 .. n {
repeated.push_str(s);
}
repeated
}
-35
View File
@@ -1,35 +0,0 @@
use std::fs::File;
use std::io::Read;
use std::path::Path;
use std::process::Command;
use util::*;
static PROGNAME: &'static str = "./cp";
static TEST_HELLO_WORLD_SOURCE: &'static str = "hello_world.txt";
static TEST_HELLO_WORLD_DEST: &'static str = "copy_of_hello_world.txt";
#[path = "common/util.rs"]
#[macro_use]
mod util;
#[test]
fn test_cp_cp() {
// Invoke our binary to make the copy.
let prog = Command::new(PROGNAME)
.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.
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");
cleanup(TEST_HELLO_WORLD_SOURCE);
cleanup(TEST_HELLO_WORLD_DEST);
}
-58
View File
@@ -1,58 +0,0 @@
use std::process::Command;
use util::*;
static PROGNAME: &'static str = "./cut";
static INPUT: &'static str = "lists.txt";
#[path = "common/util.rs"]
#[macro_use]
mod util;
#[test]
fn test_prefix() {
let mut cmd = Command::new(PROGNAME);
let result = run(&mut cmd.args(&["-c", "-10", INPUT]));
assert_eq!(result.stdout, get_file_contents("lists_prefix.expected"));
}
#[test]
fn test_char_range() {
let mut cmd = Command::new(PROGNAME);
let result = run(&mut cmd.args(&["-c", "4-10", INPUT]));
assert_eq!(result.stdout, get_file_contents("lists_char_range.expected"));
}
#[test]
fn test_column_to_end_of_line() {
let mut cmd = Command::new(PROGNAME);
let result = run(&mut cmd.args(&["-d", ":", "-f", "5-", INPUT]));
assert_eq!(result.stdout, get_file_contents("lists_column_to_end_of_line.expected"));
}
#[test]
fn test_specific_field() {
let mut cmd = Command::new(PROGNAME);
let result = run(&mut cmd.args(&["-d", " ", "-f", "3", INPUT]));
assert_eq!(result.stdout, get_file_contents("lists_specific_field.expected"));
}
#[test]
fn test_multiple_fields() {
let mut cmd = Command::new(PROGNAME);
let result = run(&mut cmd.args(&["-d", ":", "-f", "1,3", INPUT]));
assert_eq!(result.stdout, get_file_contents("lists_multiple_fields.expected"));
}
#[test]
fn test_tail() {
let mut cmd = Command::new(PROGNAME);
let result = run(&mut cmd.args(&["-d", ":", "--complement", "-f", "1", INPUT]));
assert_eq!(result.stdout, get_file_contents("lists_tail.expected"));
}
#[test]
fn test_change_delimiter() {
let mut cmd = Command::new(PROGNAME);
let result = run(&mut cmd.args(&["-d", ":", "--complement", "--output-delimiter=#", "-f", "1", INPUT]));
assert_eq!(result.stdout, get_file_contents("lists_change_delimiter.expected"));
}
-28
View File
@@ -1,28 +0,0 @@
use std::process::Command;
use std::str;
static PROGNAME: &'static str = "./dirname";
#[test]
fn test_path_with_trailing_slashes() {
let dir = "/root/alpha/beta/gamma/delta/epsilon/omega//";
let po = Command::new(PROGNAME)
.arg(dir)
.output()
.unwrap_or_else(|err| panic!("{}", err));
let out = str::from_utf8(&po.stdout[..]).unwrap().trim_right();
assert_eq!(out, "/root/alpha/beta/gamma/delta/epsilon");
}
#[test]
fn test_path_without_trailing_slashes() {
let dir = "/root/alpha/beta/gamma/delta/epsilon/omega";
let po = Command::new(PROGNAME)
.arg(dir)
.output()
.unwrap_or_else(|err| panic!("{}", err));
let out = str::from_utf8(&po.stdout[..]).unwrap().trim_right();
assert_eq!(out, "/root/alpha/beta/gamma/delta/epsilon");
}
-50
View File
@@ -1,50 +0,0 @@
use std::process::Command;
use std::str;
static PROGNAME: &'static str = "./echo";
#[test]
fn test_default() {
let po = Command::new(PROGNAME)
.output()
.unwrap_or_else(|err| panic!("{}", err));
let out = str::from_utf8(&po.stdout[..]).unwrap();
assert_eq!(out, "\n");
}
#[test]
fn test_no_trailing_newline() {
let po = Command::new(PROGNAME)
.arg("-n")
.arg("hello_world")
.output()
.unwrap_or_else(|err| panic!("{}", err));
let out = str::from_utf8(&po.stdout[..]).unwrap();
assert_eq!(out, "hello_world");
}
#[test]
fn test_enable_escapes() {
let po = Command::new(PROGNAME)
.arg("-e")
.arg("\\\\\\t\\r")
.output()
.unwrap_or_else(|err| panic!("{}", err));
let out = str::from_utf8(&po.stdout[..]).unwrap();
assert_eq!(out, "\\\t\r\n");
}
#[test]
fn test_disable_escapes() {
let po = Command::new(PROGNAME)
.arg("-E")
.arg("\\b\\c\\e")
.output()
.unwrap_or_else(|err| panic!("{}", err));
let out = str::from_utf8(&po.stdout[..]).unwrap();
assert_eq!(out, "\\b\\c\\e\n");
}
-74
View File
@@ -1,74 +0,0 @@
use std::process::Command;
use std::str;
static PROGNAME: &'static str = "./env";
#[test]
fn test_single_name_value_pair() {
let po = Command::new(PROGNAME)
.arg("FOO=bar")
.output()
.unwrap_or_else(|err| panic!("{}", err));
let out = str::from_utf8(&po.stdout[..]).unwrap();
assert!(out.lines().any(|line| line == "FOO=bar"));
}
#[test]
fn test_multiple_name_value_pairs() {
let po = Command::new(PROGNAME)
.arg("FOO=bar")
.arg("ABC=xyz")
.output()
.unwrap_or_else(|err| panic!("{}", err));
let out = str::from_utf8(&po.stdout[..]).unwrap();
assert_eq!(out.lines().filter(|&line| line == "FOO=bar" || line == "ABC=xyz").count(), 2);
}
#[test]
fn test_ignore_environment() {
let po = Command::new(PROGNAME)
.arg("-i")
.output()
.unwrap_or_else(|err| panic!("{}", err));
let out = str::from_utf8(&po.stdout[..]).unwrap();
assert_eq!(out, "");
let po = Command::new(PROGNAME)
.arg("-")
.output()
.unwrap_or_else(|err| panic!("{}", err));
let out = str::from_utf8(&po.stdout[..]).unwrap();
assert_eq!(out, "");
}
#[test]
fn test_null_delimiter() {
let po = Command::new(PROGNAME)
.arg("-i")
.arg("--null")
.arg("FOO=bar")
.arg("ABC=xyz")
.output()
.unwrap_or_else(|err| panic!("{}", err));
let out = str::from_utf8(&po.stdout[..]).unwrap();
assert_eq!(out, "FOO=bar\0ABC=xyz\0");
}
#[test]
fn test_unset_variable() {
// This test depends on the HOME variable being pre-defined by the
// default shell
let po = Command::new(PROGNAME)
.arg("-u")
.arg("HOME")
.output()
.unwrap_or_else(|err| panic!("{}", err));
let out = str::from_utf8(&po.stdout[..]).unwrap();
assert_eq!(out.lines().any(|line| line.starts_with("HOME=")), false);
}
-534
View File
File diff suppressed because it is too large Load Diff
-9
View File
@@ -1,9 +0,0 @@
use std::process::Command;
static PROGNAME: &'static str = "./false";
#[test]
fn test_exit_code() {
let exit_status = Command::new(PROGNAME).status().unwrap().success();
assert_eq!(exit_status, false);
}
-53
View File
@@ -1,53 +0,0 @@
use std::fs::File;
use std::io::Read;
use std::path::Path;
use std::process::Command;
static PROGNAME: &'static str = "./fold";
#[test]
fn test_default_80_column_wrap() {
let po = Command::new(PROGNAME)
.arg("lorem_ipsum.txt")
.output()
.unwrap_or_else(|err| panic!("{}", err));
fold_helper(po.stdout, "lorem_ipsum_80_column.expected");
}
#[test]
fn test_40_column_hard_cutoff() {
let po = Command::new(PROGNAME)
.arg("-w")
.arg("40")
.arg("lorem_ipsum.txt")
.output()
.unwrap_or_else(|err| panic!("{}", err));
fold_helper(po.stdout, "lorem_ipsum_40_column_hard.expected");
}
#[test]
fn test_40_column_word_boundary() {
let po = Command::new(PROGNAME)
.arg("-s")
.arg("-w")
.arg("40")
.arg("lorem_ipsum.txt")
.output()
.unwrap_or_else(|err| panic!("{}", err));
fold_helper(po.stdout, "lorem_ipsum_40_column_word.expected");
}
fn fold_helper(output: Vec<u8>, filename: &str) {
let mut f = File::open(Path::new(filename)).unwrap_or_else(|err| {
panic!("{}", err)
});
let mut expected = vec!();
match f.read_to_end(&mut expected) {
Ok(_) => {},
Err(err) => panic!("{}", err)
}
assert_eq!(String::from_utf8(output).unwrap(), String::from_utf8(expected).unwrap());
}
-72
View File
@@ -1,72 +0,0 @@
use std::process::Command;
use util::*;
static PROGNAME: &'static str = "./head";
static INPUT: &'static str = "lorem_ipsum.txt";
#[path = "common/util.rs"]
#[macro_use]
mod util;
#[test]
fn test_stdin_default() {
let mut cmd = Command::new(PROGNAME);
let result = run_piped_stdin(&mut cmd, get_file_contents(INPUT));
assert_eq!(result.stdout, get_file_contents("lorem_ipsum_default.expected"));
}
#[test]
fn test_stdin_1_line_obsolete() {
let mut cmd = Command::new(PROGNAME);
let result = run_piped_stdin(&mut cmd.args(&["-1"]), get_file_contents(INPUT));
assert_eq!(result.stdout, get_file_contents("lorem_ipsum_1_line.expected"));
}
#[test]
fn test_stdin_1_line() {
let mut cmd = Command::new(PROGNAME);
let result = run_piped_stdin(&mut cmd.args(&["-n", "1"]), get_file_contents(INPUT));
assert_eq!(result.stdout, get_file_contents("lorem_ipsum_1_line.expected"));
}
#[test]
fn test_stdin_5_chars() {
let mut cmd = Command::new(PROGNAME);
let result = run_piped_stdin(&mut cmd.args(&["-c", "5"]), get_file_contents(INPUT));
assert_eq!(result.stdout, get_file_contents("lorem_ipsum_5_chars.expected"));
}
#[test]
fn test_single_default() {
let mut cmd = Command::new(PROGNAME);
let result = run(&mut cmd.arg(INPUT));
assert_eq!(result.stdout, get_file_contents("lorem_ipsum_default.expected"));
}
#[test]
fn test_single_1_line_obsolete() {
let mut cmd = Command::new(PROGNAME);
let result = run(&mut cmd.args(&["-1", INPUT]));
assert_eq!(result.stdout, get_file_contents("lorem_ipsum_1_line.expected"));
}
#[test]
fn test_single_1_line() {
let mut cmd = Command::new(PROGNAME);
let result = run(&mut cmd.args(&["-n", "1", INPUT]));
assert_eq!(result.stdout, get_file_contents("lorem_ipsum_1_line.expected"));
}
#[test]
fn test_single_5_chars() {
let mut cmd = Command::new(PROGNAME);
let result = run(&mut cmd.args(&["-c", "5", INPUT]));
assert_eq!(result.stdout, get_file_contents("lorem_ipsum_5_chars.expected"));
}
#[test]
fn test_verbose() {
let mut cmd = Command::new(PROGNAME);
let result = run(&mut cmd.args(&["-v", INPUT]));
assert_eq!(result.stdout, get_file_contents("lorem_ipsum_verbose.expected"));
}
-49
View File
@@ -1,49 +0,0 @@
extern crate libc;
use std::process::Command;
use util::*;
static PROGNAME: &'static str = "./link";
#[path = "common/util.rs"]
#[macro_use]
mod util;
#[test]
fn test_link_existing_file() {
let file = "test_link_existing_file";
let link = "test_link_existing_file_link";
touch(file);
set_file_contents(file, "foobar");
assert!(file_exists(file));
let result = run(Command::new(PROGNAME).args(&[file, link]));
assert_empty_stderr!(result);
assert!(result.success);
assert!(file_exists(file));
assert!(file_exists(link));
assert_eq!(get_file_contents(file), get_file_contents(link));
}
#[test]
fn test_link_no_circular() {
let link = "test_link_no_circular";
let result = run(Command::new(PROGNAME).args(&[link, link]));
assert_eq!(result.stderr, "link: error: No such file or directory (os error 2)\n");
assert!(!result.success);
assert!(!file_exists(link));
}
#[test]
fn test_link_nonexistent_file() {
let file = "test_link_nonexistent_file";
let link = "test_link_nonexistent_file_link";
let result = run(Command::new(PROGNAME).args(&[file, link]));
assert_eq!(result.stderr, "link: error: No such file or directory (os error 2)\n");
assert!(!result.success);
assert!(!file_exists(file));
assert!(!file_exists(link));
}
-354
View File
@@ -1,354 +0,0 @@
extern crate libc;
use std::process::Command;
use util::*;
static PROGNAME: &'static str = "./ln";
#[path = "common/util.rs"]
#[macro_use]
mod util;
#[test]
fn test_symlink_existing_file() {
let file = "test_symlink_existing_file";
let link = "test_symlink_existing_file_link";
touch(file);
let result = run(Command::new(PROGNAME).args(&["-s", file, link]));
assert_empty_stderr!(result);
assert!(result.success);
assert!(file_exists(file));
assert!(is_symlink(link));
assert_eq!(resolve_link(link), file);
}
#[test]
fn test_symlink_dangling_file() {
let file = "test_symlink_dangling_file";
let link = "test_symlink_dangling_file_link";
let result = run(Command::new(PROGNAME).args(&["-s", file, link]));
assert_empty_stderr!(result);
assert!(result.success);
assert!(!file_exists(file));
assert!(is_symlink(link));
assert_eq!(resolve_link(link), file);
}
#[test]
fn test_symlink_existing_directory() {
let dir = "test_symlink_existing_dir";
let link = "test_symlink_existing_dir_link";
mkdir(dir);
let result = run(Command::new(PROGNAME).args(&["-s", dir, link]));
assert_empty_stderr!(result);
assert!(result.success);
assert!(dir_exists(dir));
assert!(is_symlink(link));
assert_eq!(resolve_link(link), dir);
}
#[test]
fn test_symlink_dangling_directory() {
let dir = "test_symlink_dangling_dir";
let link = "test_symlink_dangling_dir_link";
let result = run(Command::new(PROGNAME).args(&["-s", dir, link]));
assert_empty_stderr!(result);
assert!(result.success);
assert!(!dir_exists(dir));
assert!(is_symlink(link));
assert_eq!(resolve_link(link), dir);
}
#[test]
fn test_symlink_circular() {
let link = "test_symlink_circular";
let result = run(Command::new(PROGNAME).args(&["-s", link]));
assert_empty_stderr!(result);
assert!(result.success);
assert!(is_symlink(link));
assert_eq!(resolve_link(link), link);
}
#[test]
fn test_symlink_dont_overwrite() {
let file = "test_symlink_dont_overwrite";
let link = "test_symlink_dont_overwrite_link";
touch(file);
touch(link);
let result = run(Command::new(PROGNAME).args(&["-s", file, link]));
assert!(!result.success);
assert!(file_exists(file));
assert!(file_exists(link));
assert!(!is_symlink(link));
}
#[test]
fn test_symlink_overwrite_force() {
let file_a = "test_symlink_overwrite_force_a";
let file_b = "test_symlink_overwrite_force_b";
let link = "test_symlink_overwrite_force_link";
// Create symlink
symlink(file_a, link);
assert!(is_symlink(link));
assert_eq!(resolve_link(link), file_a);
// Force overwrite of existing symlink
let result = run(Command::new(PROGNAME).args(&["--force", "-s", file_b, link]));
assert!(result.success);
assert!(is_symlink(link));
assert_eq!(resolve_link(link), file_b);
}
#[test]
fn test_symlink_interactive() {
let file = "test_symlink_interactive_file";
let link = "test_symlink_interactive_file_link";
touch(file);
touch(link);
let result1 = run_piped_stdin(Command::new(PROGNAME).args(&["-i", "-s", file, link]), b"n");
assert_empty_stderr!(result1);
assert!(result1.success);
assert!(file_exists(file));
assert!(!is_symlink(link));
let result2 = run_piped_stdin(Command::new(PROGNAME).args(&["-i", "-s", file, link]), b"Yesh");
assert_empty_stderr!(result2);
assert!(result2.success);
assert!(file_exists(file));
assert!(is_symlink(link));
assert_eq!(resolve_link(link), file);
}
#[test]
fn test_symlink_simple_backup() {
let file = "test_symlink_simple_backup";
let link = "test_symlink_simple_backup_link";
touch(file);
symlink(file, link);
assert!(file_exists(file));
assert!(is_symlink(link));
assert_eq!(resolve_link(link), file);
let result = run(Command::new(PROGNAME).args(&["-b", "-s", file, link]));
assert_empty_stderr!(result);
assert!(result.success);
assert!(file_exists(file));
assert!(is_symlink(link));
assert_eq!(resolve_link(link), file);
let backup = &format!("{}~", link);
assert!(is_symlink(backup));
assert_eq!(resolve_link(backup), file);
}
#[test]
fn test_symlink_custom_backup_suffix() {
let file = "test_symlink_custom_backup_suffix";
let link = "test_symlink_custom_backup_suffix_link";
let suffix = "super-suffix-of-the-century";
touch(file);
symlink(file, link);
assert!(file_exists(file));
assert!(is_symlink(link));
assert_eq!(resolve_link(link), file);
let arg = &format!("--suffix={}", suffix);
let result = run(Command::new(PROGNAME).args(&["-b", arg, "-s", file, link]));
assert_empty_stderr!(result);
assert!(result.success);
assert!(file_exists(file));
assert!(is_symlink(link));
assert_eq!(resolve_link(link), file);
let backup = &format!("{}{}", link, suffix);
assert!(is_symlink(backup));
assert_eq!(resolve_link(backup), file);
}
#[test]
fn test_symlink_backup_numbering() {
let file = "test_symlink_backup_numbering";
let link = "test_symlink_backup_numbering_link";
touch(file);
symlink(file, link);
assert!(file_exists(file));
assert!(is_symlink(link));
assert_eq!(resolve_link(link), file);
let result = run(Command::new(PROGNAME).args(&["-s", "--backup=t", file, link]));
assert_empty_stderr!(result);
assert!(result.success);
assert!(file_exists(file));
assert!(is_symlink(link));
assert_eq!(resolve_link(link), file);
let backup = &format!("{}.~1~", link);
assert!(is_symlink(backup));
assert_eq!(resolve_link(backup), file);
}
#[test]
fn test_symlink_existing_backup() {
let file = "test_symlink_existing_backup";
let link = "test_symlink_existing_backup_link";
let link_backup = "test_symlink_existing_backup_link.~1~";
let resulting_backup = "test_symlink_existing_backup_link.~2~";
// Create symlink and verify
touch(file);
symlink(file, link);
assert!(file_exists(file));
assert!(is_symlink(link));
assert_eq!(resolve_link(link), file);
// Create backup symlink and verify
symlink(file, link_backup);
assert!(file_exists(file));
assert!(is_symlink(link_backup));
assert_eq!(resolve_link(link_backup), file);
let result = run(Command::new(PROGNAME).args(&["-s", "--backup=nil", file, link]));
assert_empty_stderr!(result);
assert!(result.success);
assert!(file_exists(file));
assert!(is_symlink(link_backup));
assert_eq!(resolve_link(link_backup), file);
assert!(is_symlink(resulting_backup));
assert_eq!(resolve_link(resulting_backup), file);
}
#[test]
fn test_symlink_target_dir() {
let dir = "test_ln_target_dir_dir";
let file_a = "test_ln_target_dir_file_a";
let file_b = "test_ln_target_dir_file_b";
touch(file_a);
touch(file_b);
mkdir(dir);
let result = run(Command::new(PROGNAME).args(&["-s", "-t", dir, file_a, file_b]));
assert_empty_stderr!(result);
assert!(result.success);
let file_a_link = &format!("{}/{}", dir, file_a);
assert!(is_symlink(file_a_link));
assert_eq!(resolve_link(file_a_link), file_a);
let file_b_link = &format!("{}/{}", dir, file_b);
assert!(is_symlink(file_b_link));
assert_eq!(resolve_link(file_b_link), file_b);
}
#[test]
fn test_symlink_overwrite_dir() {
let path_a = "test_symlink_overwrite_dir_a";
let path_b = "test_symlink_overwrite_dir_b";
touch(path_a);
mkdir(path_b);
let result = run(Command::new(PROGNAME).args(&["-s", "-T", path_a, path_b]));
assert_empty_stderr!(result);
assert!(result.success);
assert!(file_exists(path_a));
assert!(is_symlink(path_b));
assert_eq!(resolve_link(path_b), path_a);
}
#[test]
fn test_symlink_overwrite_nonempty_dir() {
let path_a = "test_symlink_overwrite_nonempty_dir_a";
let path_b = "test_symlink_overwrite_nonempty_dir_b";
let dummy = "test_symlink_overwrite_nonempty_dir_b/file";
touch(path_a);
mkdir(path_b);
touch(dummy);
let result = run(Command::new(PROGNAME).args(&["-v", "-T", "-s", path_a, path_b]));
// Not same error as GNU; the error message is a Rust builtin
// TODO: test (and implement) correct error message (or at least decide whether to do so)
// Current: "ln: error: Directory not empty (os error 66)"
// GNU: "ln: cannot link 'a' to 'b': Directory not empty"
assert!(result.stderr.len() > 0);
// Verbose output for the link should not be shown on failure
assert!(result.stdout.len() == 0);
assert!(!result.success);
assert!(file_exists(path_a));
assert!(dir_exists(path_b));
}
#[test]
fn test_symlink_errors() {
let dir = "test_symlink_errors_dir";
let file_a = "test_symlink_errors_file_a";
let file_b = "test_symlink_errors_file_b";
mkdir(dir);
touch(file_a);
touch(file_b);
// $ ln -T -t a b
// ln: cannot combine --target-directory (-t) and --no-target-directory (-T)
let result = run(Command::new(PROGNAME).args(&["-T", "-t", dir, file_a, file_b]));
assert_eq!(result.stderr,
"ln: error: cannot combine --target-directory (-t) and --no-target-directory (-T)\n");
assert!(!result.success);
}
#[test]
fn test_symlink_verbose() {
let file_a = "test_symlink_verbose_file_a";
let file_b = "test_symlink_verbose_file_b";
touch(file_a);
let result = run(Command::new(PROGNAME).args(&["-v", file_a, file_b]));
assert_empty_stderr!(result);
assert_eq!(result.stdout,
format!("'{}' -> '{}'\n", file_b, file_a));
assert!(result.success);
touch(file_b);
let result = run(Command::new(PROGNAME).args(&["-v", "-b", file_a, file_b]));
assert_empty_stderr!(result);
assert_eq!(result.stdout,
format!("'{}' -> '{}' (backup: '{}~')\n", file_b, file_a, file_b));
assert!(result.success);
}
-58
View File
@@ -1,58 +0,0 @@
use std::process::Command;
use util::*;
static PROGNAME: &'static str = "./mkdir";
static TEST_DIR1: &'static str = "mkdir_test1";
static TEST_DIR2: &'static str = "mkdir_test2";
static TEST_DIR3: &'static str = "mkdir_test3";
static TEST_DIR4: &'static str = "mkdir_test4/mkdir_test4_1";
static TEST_DIR5: &'static str = "mkdir_test5/mkdir_test5_1";
#[path = "common/util.rs"]
#[macro_use]
mod util;
#[test]
fn test_mkdir_mkdir() {
let mut cmd = Command::new(PROGNAME);
let exit_success = run(&mut cmd.arg(TEST_DIR1)).success;
cleanup(TEST_DIR1);
assert_eq!(exit_success, true);
}
#[test]
fn test_mkdir_dup_dir() {
let mut cmd = Command::new(PROGNAME);
let exit_success = run(&mut cmd.arg(TEST_DIR2)).success;
if !exit_success {
cleanup(TEST_DIR2);
panic!();
}
let exit_success2 = run(&mut cmd.arg(TEST_DIR2)).success;
cleanup(TEST_DIR2);
assert_eq!(exit_success2, false);
}
#[test]
fn test_mkdir_mode() {
let mut cmd = Command::new(PROGNAME);
let exit_success = run(&mut cmd.arg("-m").arg("755").arg(TEST_DIR3)).success;
cleanup(TEST_DIR3);
assert_eq!(exit_success, true);
}
#[test]
fn test_mkdir_parent() {
let mut cmd = Command::new(PROGNAME);
let exit_success = run(&mut cmd.arg("-p").arg(TEST_DIR4)).success;
cleanup(TEST_DIR4);
assert_eq!(exit_success, true);
}
#[test]
fn test_mkdir_no_parent() {
let mut cmd = Command::new(PROGNAME);
let exit_success = run(&mut cmd.arg(TEST_DIR5)).success;
cleanup(TEST_DIR5);
assert_eq!(exit_success, false);
}
-446
View File
@@ -1,446 +0,0 @@
extern crate libc;
extern crate time;
extern crate kernel32;
extern crate winapi;
extern crate filetime;
use filetime::*;
use std::process::Command;
use util::*;
static PROGNAME: &'static str = "./mv";
#[path = "common/util.rs"]
#[macro_use]
mod util;
#[test]
fn test_mv_rename_dir() {
let dir1 = "test_mv_rename_dir";
let dir2 = "test_mv_rename_dir2";
mkdir(dir1);
let result = run(Command::new(PROGNAME).arg(dir1).arg(dir2));
assert_empty_stderr!(result);
assert!(result.success);
assert!(dir_exists(dir2));
}
#[test]
fn test_mv_rename_file() {
let file1 = "test_mv_rename_file";
let file2 = "test_mv_rename_file2";
touch(file1);
let result = run(Command::new(PROGNAME).arg(file1).arg(file2));
assert_empty_stderr!(result);
assert!(result.success);
assert!(file_exists(file2));
}
#[test]
fn test_mv_move_file_into_dir() {
let dir = "test_mv_move_file_into_dir_dir";
let file = "test_mv_move_file_into_dir_file";
mkdir(dir);
touch(file);
let result = run(Command::new(PROGNAME).arg(file).arg(dir));
assert_empty_stderr!(result);
assert!(result.success);
assert!(file_exists(&format!("{}/{}", dir, file)));
}
#[test]
fn test_mv_strip_slashes() {
let dir = "test_mv_strip_slashes_dir";
let file = "test_mv_strip_slashes_file";
let mut source = file.to_owned();
source.push_str("/");
mkdir(dir);
touch(file);
let result = run(Command::new(PROGNAME).arg(&source).arg(dir));
assert!(!result.success);
assert!(!file_exists(&format!("{}/{}", dir, file)));
let result = run(Command::new(PROGNAME).arg("--strip-trailing-slashes").arg(source).arg(dir));
assert_empty_stderr!(result);
assert!(result.success);
assert!(file_exists(&format!("{}/{}", dir, file)));
}
#[test]
fn test_mv_multiple_files() {
let target_dir = "test_mv_multiple_files_dir";
let file_a = "test_mv_multiple_file_a";
let file_b = "test_mv_multiple_file_b";
mkdir(target_dir);
touch(file_a);
touch(file_b);
let result = run(Command::new(PROGNAME).arg(file_a).arg(file_b).arg(target_dir));
assert_empty_stderr!(result);
assert!(result.success);
assert!(file_exists(&format!("{}/{}", target_dir, file_a)));
assert!(file_exists(&format!("{}/{}", target_dir, file_b)));
}
#[test]
fn test_mv_multiple_folders() {
let target_dir = "test_mv_multiple_dirs_dir";
let dir_a = "test_mv_multiple_dir_a";
let dir_b = "test_mv_multiple_dir_b";
mkdir(target_dir);
mkdir(dir_a);
mkdir(dir_b);
let result = run(Command::new(PROGNAME).arg(dir_a).arg(dir_b).arg(target_dir));
assert_empty_stderr!(result);
assert!(result.success);
assert!(dir_exists(&format!("{}/{}", target_dir, dir_a)));
assert!(dir_exists(&format!("{}/{}", target_dir, dir_b)));
}
#[test]
fn test_mv_interactive() {
let file_a = "test_mv_interactive_file_a";
let file_b = "test_mv_interactive_file_b";
touch(file_a);
touch(file_b);
let result1 = run_piped_stdin(Command::new(PROGNAME).arg("-i").arg(file_a).arg(file_b), b"n");
assert_empty_stderr!(result1);
assert!(result1.success);
assert!(file_exists(file_a));
assert!(file_exists(file_b));
let result2 = run_piped_stdin(Command::new(PROGNAME).arg("-i").arg(file_a).arg(file_b), b"Yesh");
assert_empty_stderr!(result2);
assert!(result2.success);
assert!(!file_exists(file_a));
assert!(file_exists(file_b));
}
#[test]
fn test_mv_no_clobber() {
let file_a = "test_mv_no_clobber_file_a";
let file_b = "test_mv_no_clobber_file_b";
touch(file_a);
touch(file_b);
let result = run(Command::new(PROGNAME).arg("-n").arg(file_a).arg(file_b));
assert_empty_stderr!(result);
assert!(result.success);
assert!(file_exists(file_a));
assert!(file_exists(file_b));
}
#[test]
fn test_mv_replace_file() {
let file_a = "test_mv_replace_file_a";
let file_b = "test_mv_replace_file_b";
touch(file_a);
touch(file_b);
let result = run(Command::new(PROGNAME).arg(file_a).arg(file_b));
assert_empty_stderr!(result);
assert!(result.success);
assert!(!file_exists(file_a));
assert!(file_exists(file_b));
}
#[test]
fn test_mv_force_replace_file() {
let file_a = "test_mv_force_replace_file_a";
let file_b = "test_mv_force_replace_file_b";
touch(file_a);
touch(file_b);
let result = run(Command::new(PROGNAME).arg("--force").arg(file_a).arg(file_b));
assert_empty_stderr!(result);
assert!(result.success);
assert!(!file_exists(file_a));
assert!(file_exists(file_b));
}
#[test]
fn test_mv_simple_backup() {
let file_a = "test_mv_simple_backup_file_a";
let file_b = "test_mv_simple_backup_file_b";
touch(file_a);
touch(file_b);
let result = run(Command::new(PROGNAME).arg("-b").arg(file_a).arg(file_b));
assert_empty_stderr!(result);
assert!(result.success);
assert!(!file_exists(file_a));
assert!(file_exists(file_b));
assert!(file_exists(&format!("{}~", file_b)));
}
#[test]
fn test_mv_custom_backup_suffix() {
let file_a = "test_mv_custom_backup_suffix_file_a";
let file_b = "test_mv_custom_backup_suffix_file_b";
let suffix = "super-suffix-of-the-century";
touch(file_a);
touch(file_b);
let result = run(Command::new(PROGNAME)
.arg("-b").arg(format!("--suffix={}", suffix))
.arg(file_a).arg(file_b));
assert_empty_stderr!(result);
assert!(result.success);
assert!(!file_exists(file_a));
assert!(file_exists(file_b));
assert!(file_exists(&format!("{}{}", file_b, suffix)));
}
#[test]
fn test_mv_backup_numbering() {
let file_a = "test_mv_backup_numbering_file_a";
let file_b = "test_mv_backup_numbering_file_b";
touch(file_a);
touch(file_b);
let result = run(Command::new(PROGNAME).arg("--backup=t").arg(file_a).arg(file_b));
assert_empty_stderr!(result);
assert!(result.success);
assert!(!file_exists(file_a));
assert!(file_exists(file_b));
assert!(file_exists(&format!("{}.~1~", file_b)));
}
#[test]
fn test_mv_existing_backup() {
let file_a = "test_mv_existing_backup_file_a";
let file_b = "test_mv_existing_backup_file_b";
let file_b_backup = "test_mv_existing_backup_file_b.~1~";
let resulting_backup = "test_mv_existing_backup_file_b.~2~";
touch(file_a);
touch(file_b);
touch(file_b_backup);
let result = run(Command::new(PROGNAME).arg("--backup=nil").arg(file_a).arg(file_b));
assert_empty_stderr!(result);
assert!(result.success);
assert!(!file_exists(file_a));
assert!(file_exists(file_b));
assert!(file_exists(file_b_backup));
assert!(file_exists(resulting_backup));
}
#[test]
fn test_mv_update_option() {
let file_a = "test_mv_update_option_file_a";
let file_b = "test_mv_update_option_file_b";
touch(file_a);
touch(file_b);
let ts = time::now().to_timespec();
let now = FileTime::from_seconds_since_1970(ts.sec as u64, ts.nsec as u32);
let later = FileTime::from_seconds_since_1970(ts.sec as u64 + 3600, ts.nsec as u32);
filetime::set_file_times(file_a, now, now).unwrap();
filetime::set_file_times(file_b, now, later).unwrap();
let result1 = run(Command::new(PROGNAME).arg("--update").arg(file_a).arg(file_b));
assert_empty_stderr!(result1);
assert!(result1.success);
assert!(file_exists(file_a));
assert!(file_exists(file_b));
let result2 = run(Command::new(PROGNAME).arg("--update").arg(file_b).arg(file_a));
assert_empty_stderr!(result2);
assert!(result2.success);
assert!(file_exists(file_a));
assert!(!file_exists(file_b));
}
#[test]
fn test_mv_target_dir() {
let dir = "test_mv_target_dir_dir";
let file_a = "test_mv_target_dir_file_a";
let file_b = "test_mv_target_dir_file_b";
touch(file_a);
touch(file_b);
mkdir(dir);
let result = run(Command::new(PROGNAME).arg("-t").arg(dir).arg(file_a).arg(file_b));
assert_empty_stderr!(result);
assert!(result.success);
assert!(!file_exists(file_a));
assert!(!file_exists(file_b));
assert!(file_exists(&format!("{}/{}", dir, file_a)));
assert!(file_exists(&format!("{}/{}", dir, file_b)));
}
#[test]
fn test_mv_overwrite_dir() {
let dir_a = "test_mv_overwrite_dir_a";
let dir_b = "test_mv_overwrite_dir_b";
mkdir(dir_a);
mkdir(dir_b);
let result = run(Command::new(PROGNAME).arg("-T").arg(dir_a).arg(dir_b));
assert_empty_stderr!(result);
assert!(result.success);
assert!(!dir_exists(dir_a));
assert!(dir_exists(dir_b));
}
#[test]
fn test_mv_overwrite_nonempty_dir() {
let dir_a = "test_mv_overwrite_nonempty_dir_a";
let dir_b = "test_mv_overwrite_nonempty_dir_b";
let dummy = "test_mv_overwrite_nonempty_dir_b/file";
mkdir(dir_a);
mkdir(dir_b);
touch(dummy);
let result = run(Command::new(PROGNAME).arg("-vT").arg(dir_a).arg(dir_b));
// Not same error as GNU; the error message is a rust builtin
// TODO: test (and implement) correct error message (or at least decide whether to do so)
// Current: "mv: error: couldn't rename path (Directory not empty; from=a; to=b)"
// GNU: "mv: cannot move a to b: Directory not empty"
assert!(result.stderr.len() > 0);
// Verbose output for the move should not be shown on failure
assert!(result.stdout.len() == 0);
assert!(!result.success);
assert!(dir_exists(dir_a));
assert!(dir_exists(dir_b));
}
#[test]
fn test_mv_backup_dir() {
let dir_a = "test_mv_backup_dir_dir_a";
let dir_b = "test_mv_backup_dir_dir_b";
mkdir(dir_a);
mkdir(dir_b);
let result = run(Command::new(PROGNAME).arg("-vbT").arg(dir_a).arg(dir_b));
assert_empty_stderr!(result);
assert_eq!(result.stdout,
format!("{} -> {} (backup: {}~)\n", dir_a, dir_b, dir_b));
assert!(result.success);
assert!(!dir_exists(dir_a));
assert!(dir_exists(dir_b));
assert!(dir_exists(&format!("{}~", dir_b)));
}
#[test]
fn test_mv_errors() {
let dir = "test_mv_errors_dir";
let file_a = "test_mv_errors_file_a";
let file_b = "test_mv_errors_file_b";
mkdir(dir);
touch(file_a);
touch(file_b);
// $ mv -T -t a b
// mv: cannot combine --target-directory (-t) and --no-target-directory (-T)
let result = run(Command::new(PROGNAME).arg("-T").arg("-t").arg(dir).arg(file_a).arg(file_b));
assert_eq!(result.stderr,
"mv: error: cannot combine --target-directory (-t) and --no-target-directory (-T)\n");
assert!(!result.success);
// $ touch file && mkdir dir
// $ mv -T file dir
// err == mv: cannot overwrite directory dir with non-directory
let result = run(Command::new(PROGNAME).arg("-T").arg(file_a).arg(dir));
assert_eq!(result.stderr,
format!("mv: error: cannot overwrite directory {} with non-directory\n", dir));
assert!(!result.success);
// $ mkdir dir && touch file
// $ mv dir file
// err == mv: cannot overwrite non-directory file with directory dir
let result = run(Command::new(PROGNAME).arg(dir).arg(file_a));
assert!(result.stderr.len() > 0);
assert!(!result.success);
}
#[test]
fn test_mv_verbose() {
let dir = "test_mv_verbose_dir";
let file_a = "test_mv_verbose_file_a";
let file_b = "test_mv_verbose_file_b";
mkdir(dir);
touch(file_a);
touch(file_b);
let result = run(Command::new(PROGNAME).arg("-v").arg(file_a).arg(file_b));
assert_empty_stderr!(result);
assert_eq!(result.stdout,
format!("{} -> {}\n", file_a, file_b));
assert!(result.success);
touch(file_a);
let result = run(Command::new(PROGNAME).arg("-vb").arg(file_a).arg(file_b));
assert_empty_stderr!(result);
assert_eq!(result.stdout,
format!("{} -> {} (backup: {}~)\n", file_a, file_b, file_b));
assert!(result.success);
}
// Todo:
// $ touch a b
// $ chmod -w b
// $ ll
// total 0
// -rw-rw-r-- 1 user user 0 okt 25 11:21 a
// -r--r--r-- 1 user user 0 okt 25 11:21 b
// $
// $ mv -v a b
// mv: try to overwrite b, overriding mode 0444 (r--r--r--)? y
// a -> b

Some files were not shown because too many files have changed in this diff Show More