1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

cp: handle update prompt with and without interactive mode enabled

This commit is contained in:
Vikrant2691 2024-03-13 23:31:11 +00:00 committed by Ben Wiederhake
parent aeafabd23f
commit 9b9c0cc237
2 changed files with 19 additions and 26 deletions

View file

@ -274,20 +274,6 @@ fn test_cp_target_directory_is_file() {
.stderr_contains(format!("'{TEST_HOW_ARE_YOU_SOURCE}' is not a directory"));
}
#[test]
// FixMe: for FreeBSD, flaky test; track repair progress at GH:uutils/coreutils/issue/4725
#[cfg(not(target_os = "freebsd"))]
fn test_cp_arg_update_interactive() {
new_ucmd!()
.arg(TEST_HELLO_WORLD_SOURCE)
.arg(TEST_HOW_ARE_YOU_SOURCE)
.arg("-i")
.arg("--update")
.succeeds()
.no_stdout()
.no_stderr();
}
#[test]
fn test_cp_arg_update_interactive_error() {
new_ucmd!()
@ -498,7 +484,7 @@ fn test_cp_arg_interactive() {
#[test]
#[cfg(not(any(target_os = "android", target_os = "freebsd")))]
fn test_cp_arg_interactive_update() {
fn test_cp_arg_interactive_update_overwrite_newer() {
// -u -i won't show the prompt to validate the override or not
// Therefore, the error code will be 0
let (at, mut ucmd) = at_and_ucmd!();
@ -517,12 +503,13 @@ fn test_cp_arg_interactive_update() {
#[test]
#[cfg(not(any(target_os = "android", target_os = "freebsd")))]
#[ignore = "known issue #6019"]
fn test_cp_arg_interactive_update_newer() {
fn test_cp_arg_interactive_update_overwrite_older() {
// -u -i *WILL* show the prompt to validate the override.
// Therefore, the error code depends on the prompt response.
// Option N
let (at, mut ucmd) = at_and_ucmd!();
at.touch("b");
std::thread::sleep(Duration::from_secs(1));
at.touch("a");
ucmd.args(&["-i", "-u", "a", "b"])
.pipe_in("N\n")
@ -530,6 +517,16 @@ fn test_cp_arg_interactive_update_newer() {
.code_is(1)
.no_stdout()
.stderr_is("cp: overwrite 'b'? ");
// Option Y
let (at, mut ucmd) = at_and_ucmd!();
at.touch("b");
std::thread::sleep(Duration::from_secs(1));
at.touch("a");
ucmd.args(&["-i", "-u", "a", "b"])
.pipe_in("Y\n")
.succeeds()
.no_stdout();
}
#[test]