1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-30 20:47:46 +00:00

Merge pull request #432 from awestroke/more_mv_test_cases

More mv tests and use cases
This commit is contained in:
Alex Lyon 2014-10-31 01:30:54 -07:00
commit 03f26845d7
2 changed files with 48 additions and 2 deletions

View file

@ -274,7 +274,7 @@ fn move_files_into_dir(files: &[Path], target_dir: &Path, b: &Behaviour) -> int
fn rename(from: &Path, to: &Path, b: &Behaviour) -> IoResult<()> {
let mut backup_path = None;
if to.is_file() {
if to.exists() {
match b.overwrite {
NoClobber => return Ok(()),
Interactive => {
@ -303,6 +303,8 @@ fn rename(from: &Path, to: &Path, b: &Behaviour) -> IoResult<()> {
}
}
try!(fs::rename(from, to));
if b.verbose {
print!("{} -> {}", from.display(), to.display());
match backup_path {
@ -310,7 +312,7 @@ fn rename(from: &Path, to: &Path, b: &Behaviour) -> IoResult<()> {
None => println!("")
}
}
fs::rename(from, to)
Ok(())
}
fn read_yes() -> bool {

View file

@ -352,6 +352,50 @@ fn test_mv_overwrite_dir() {
assert!(Path::new(dir_b).is_dir());
}
#[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(EXE).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!(Path::new(dir_a).is_dir());
assert!(Path::new(dir_b).is_dir());
}
#[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(EXE).arg("-vbT").arg(dir_a).arg(dir_b));
assert_empty_stderr!(result);
assert_eq!(result.stdout.as_slice(),
format!("{} -> {} (backup: {}~)\n", dir_a, dir_b, dir_b).as_slice())
assert!(result.success);
assert!(!Path::new(dir_a).is_dir());
assert!(Path::new(dir_b).is_dir());
assert!(Path::new(format!("{}~", dir_b)).is_dir());
}
#[test]
fn test_mv_errors() {
let dir = "test_mv_errors_dir";