mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
Merge pull request #4796 from shinhs0506/mv-cp-update
mv, cp: add support for --update=none,all,older
This commit is contained in:
commit
a97199f72a
9 changed files with 634 additions and 53 deletions
|
@ -244,6 +244,192 @@ fn test_cp_arg_update_interactive_error() {
|
|||
.no_stdout();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cp_arg_update_none() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
|
||||
ucmd.arg(TEST_HELLO_WORLD_SOURCE)
|
||||
.arg(TEST_HOW_ARE_YOU_SOURCE)
|
||||
.arg("--update=none")
|
||||
.succeeds()
|
||||
.no_stderr()
|
||||
.no_stdout();
|
||||
|
||||
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "How are you?\n")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cp_arg_update_all() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
|
||||
ucmd.arg(TEST_HELLO_WORLD_SOURCE)
|
||||
.arg(TEST_HOW_ARE_YOU_SOURCE)
|
||||
.arg("--update=all")
|
||||
.succeeds()
|
||||
.no_stderr()
|
||||
.no_stdout();
|
||||
|
||||
assert_eq!(
|
||||
at.read(TEST_HOW_ARE_YOU_SOURCE),
|
||||
at.read(TEST_HELLO_WORLD_SOURCE)
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cp_arg_update_older_dest_not_older_than_src() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
|
||||
let old = "test_cp_arg_update_dest_not_older_file1";
|
||||
let new = "test_cp_arg_update_dest_not_older_file2";
|
||||
let old_content = "old content\n";
|
||||
let new_content = "new content\n";
|
||||
|
||||
at.write(old, old_content);
|
||||
at.write(new, new_content);
|
||||
|
||||
ucmd.arg(old)
|
||||
.arg(new)
|
||||
.arg("--update=older")
|
||||
.succeeds()
|
||||
.no_stderr()
|
||||
.no_stdout();
|
||||
|
||||
assert_eq!(at.read(new), "new content\n")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cp_arg_update_older_dest_older_than_src() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
|
||||
let old = "test_cp_arg_update_dest_older_file1";
|
||||
let new = "test_cp_arg_update_dest_older_file2";
|
||||
let old_content = "old content\n";
|
||||
let new_content = "new content\n";
|
||||
|
||||
at.write(old, old_content);
|
||||
|
||||
sleep(Duration::from_secs(1));
|
||||
|
||||
at.write(new, new_content);
|
||||
|
||||
ucmd.arg(new)
|
||||
.arg(old)
|
||||
.arg("--update=older")
|
||||
.succeeds()
|
||||
.no_stderr()
|
||||
.no_stdout();
|
||||
|
||||
assert_eq!(at.read(old), "new content\n")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cp_arg_update_short_no_overwrite() {
|
||||
// same as --update=older
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
|
||||
let old = "test_cp_arg_update_short_no_overwrite_file1";
|
||||
let new = "test_cp_arg_update_short_no_overwrite_file2";
|
||||
let old_content = "old content\n";
|
||||
let new_content = "new content\n";
|
||||
|
||||
at.write(old, old_content);
|
||||
|
||||
sleep(Duration::from_secs(1));
|
||||
|
||||
at.write(new, new_content);
|
||||
|
||||
ucmd.arg(old)
|
||||
.arg(new)
|
||||
.arg("-u")
|
||||
.succeeds()
|
||||
.no_stderr()
|
||||
.no_stdout();
|
||||
|
||||
assert_eq!(at.read(new), "new content\n")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cp_arg_update_short_overwrite() {
|
||||
// same as --update=older
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
|
||||
let old = "test_cp_arg_update_short_overwrite_file1";
|
||||
let new = "test_cp_arg_update_short_overwrite_file2";
|
||||
let old_content = "old content\n";
|
||||
let new_content = "new content\n";
|
||||
|
||||
at.write(old, old_content);
|
||||
|
||||
sleep(Duration::from_secs(1));
|
||||
|
||||
at.write(new, new_content);
|
||||
|
||||
ucmd.arg(new)
|
||||
.arg(old)
|
||||
.arg("-u")
|
||||
.succeeds()
|
||||
.no_stderr()
|
||||
.no_stdout();
|
||||
|
||||
assert_eq!(at.read(old), "new content\n")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cp_arg_update_none_then_all() {
|
||||
// take last if multiple update args are supplied,
|
||||
// update=all wins in this case
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
|
||||
let old = "test_cp_arg_update_none_then_all_file1";
|
||||
let new = "test_cp_arg_update_none_then_all_file2";
|
||||
let old_content = "old content\n";
|
||||
let new_content = "new content\n";
|
||||
|
||||
at.write(old, old_content);
|
||||
|
||||
sleep(Duration::from_secs(1));
|
||||
|
||||
at.write(new, new_content);
|
||||
|
||||
ucmd.arg(old)
|
||||
.arg(new)
|
||||
.arg("--update=none")
|
||||
.arg("--update=all")
|
||||
.succeeds()
|
||||
.no_stderr()
|
||||
.no_stdout();
|
||||
|
||||
assert_eq!(at.read(new), "old content\n")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cp_arg_update_all_then_none() {
|
||||
// take last if multiple update args are supplied,
|
||||
// update=none wins in this case
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
|
||||
let old = "test_cp_arg_update_all_then_none_file1";
|
||||
let new = "test_cp_arg_update_all_then_none_file2";
|
||||
let old_content = "old content\n";
|
||||
let new_content = "new content\n";
|
||||
|
||||
at.write(old, old_content);
|
||||
|
||||
sleep(Duration::from_secs(1));
|
||||
|
||||
at.write(new, new_content);
|
||||
|
||||
ucmd.arg(old)
|
||||
.arg(new)
|
||||
.arg("--update=all")
|
||||
.arg("--update=none")
|
||||
.succeeds()
|
||||
.no_stderr()
|
||||
.no_stdout();
|
||||
|
||||
assert_eq!(at.read(new), "new content\n")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cp_arg_interactive() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue