mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-31 21:17:46 +00:00
More mv tests and use cases
This commit is contained in:
parent
3ee7627c6c
commit
019abb993e
2 changed files with 48 additions and 2 deletions
|
@ -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<()> {
|
fn rename(from: &Path, to: &Path, b: &Behaviour) -> IoResult<()> {
|
||||||
let mut backup_path = None;
|
let mut backup_path = None;
|
||||||
|
|
||||||
if to.is_file() {
|
if to.exists() {
|
||||||
match b.overwrite {
|
match b.overwrite {
|
||||||
NoClobber => return Ok(()),
|
NoClobber => return Ok(()),
|
||||||
Interactive => {
|
Interactive => {
|
||||||
|
@ -303,6 +303,8 @@ fn rename(from: &Path, to: &Path, b: &Behaviour) -> IoResult<()> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try!(fs::rename(from, to));
|
||||||
|
|
||||||
if b.verbose {
|
if b.verbose {
|
||||||
print!("‘{}’ -> ‘{}’", from.display(), to.display());
|
print!("‘{}’ -> ‘{}’", from.display(), to.display());
|
||||||
match backup_path {
|
match backup_path {
|
||||||
|
@ -310,7 +312,7 @@ fn rename(from: &Path, to: &Path, b: &Behaviour) -> IoResult<()> {
|
||||||
None => println!("")
|
None => println!("")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fs::rename(from, to)
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_yes() -> bool {
|
fn read_yes() -> bool {
|
||||||
|
|
44
test/mv.rs
44
test/mv.rs
|
@ -352,6 +352,50 @@ fn test_mv_overwrite_dir() {
|
||||||
assert!(Path::new(dir_b).is_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]
|
#[test]
|
||||||
fn test_mv_errors() {
|
fn test_mv_errors() {
|
||||||
let dir = "test_mv_errors_dir";
|
let dir = "test_mv_errors_dir";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue