From 29015bd1f2d872d8be052e942b472b6d665c182d Mon Sep 17 00:00:00 2001 From: Vikrant2691 <37099198+Vikrant2691@users.noreply.github.com> Date: Wed, 13 Mar 2024 23:31:11 +0000 Subject: [PATCH 01/10] updated prompt logic to handle update with and without interactive mode enabled --- src/uu/cp/src/cp.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index 778ddf843b6..0dab63653d9 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -1540,7 +1540,9 @@ fn handle_existing_dest( return Err(format!("{} and {} are the same file", source.quote(), dest.quote()).into()); } - options.overwrite.verify(dest)?; + if options.update != UpdateMode::ReplaceIfOlder { + options.overwrite.verify(dest)?; + } let backup_path = backup_control::get_backup_path(options.backup, dest, &options.backup_suffix); if let Some(backup_path) = backup_path { @@ -1767,6 +1769,8 @@ fn handle_copy_mode( if src_time <= dest_time { return Ok(()); } else { + options.overwrite.verify(dest)?; + copy_helper( source, dest, @@ -1863,14 +1867,6 @@ fn copy_file( copied_files: &mut HashMap, source_in_command_line: bool, ) -> CopyResult<()> { - if (options.update == UpdateMode::ReplaceIfOlder || options.update == UpdateMode::ReplaceNone) - && options.overwrite == OverwriteMode::Interactive(ClobberMode::Standard) - { - // `cp -i --update old new` when `new` exists doesn't copy anything - // and exit with 0 - return Ok(()); - } - // Fail if dest is a dangling symlink or a symlink this program created previously if dest.is_symlink() { if FileInformation::from_path(dest, false) From 792885308cbabc706ab85c3ff4fb04f2b4e7b890 Mon Sep 17 00:00:00 2001 From: Vikrant2691 <37099198+Vikrant2691@users.noreply.github.com> Date: Thu, 14 Mar 2024 18:59:16 +0000 Subject: [PATCH 02/10] updated codebase --- tests/by-util/test_cp.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/by-util/test_cp.rs b/tests/by-util/test_cp.rs index fc955db4c92..ac1d817052b 100644 --- a/tests/by-util/test_cp.rs +++ b/tests/by-util/test_cp.rs @@ -517,7 +517,6 @@ 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() { // -u -i *WILL* show the prompt to validate the override. // Therefore, the error code depends on the prompt response. From 0b4993deb776aeecf5029d63598cae8128a237a4 Mon Sep 17 00:00:00 2001 From: Vikrant2691 <37099198+Vikrant2691@users.noreply.github.com> Date: Fri, 22 Mar 2024 01:09:48 +0000 Subject: [PATCH 03/10] added explicit file creation timestamps for test cases to fix the tests --- tests/by-util/test_cp.rs | 21 +++++++++++++++++---- tests/common/util.rs | 26 ++++++++++++++++++++++++-- 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/tests/by-util/test_cp.rs b/tests/by-util/test_cp.rs index ac1d817052b..355bec60a8c 100644 --- a/tests/by-util/test_cp.rs +++ b/tests/by-util/test_cp.rs @@ -498,7 +498,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 +517,12 @@ fn test_cp_arg_interactive_update() { #[test] #[cfg(not(any(target_os = "android", target_os = "freebsd")))] -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. let (at, mut ucmd) = at_and_ucmd!(); - at.touch("b"); - at.touch("a"); + at.touch_with_file_date("b","202403211030"); + at.touch_with_file_date("a","202403211031"); ucmd.args(&["-i", "-u", "a", "b"]) .pipe_in("N\n") .fails() @@ -531,6 +531,19 @@ fn test_cp_arg_interactive_update_newer() { .stderr_is("cp: overwrite 'b'? "); } +#[test] +#[cfg(not(any(target_os = "android", target_os = "freebsd")))] +fn test_cp_arg_interactive_update_with_create_dates_equal() { + // -u -i *WILL NOT* show the prompt to validate the override. + let (at, mut ucmd) = at_and_ucmd!(); + // Create files with the same creation date + at.touch_with_file_date("b","202403211030"); + at.touch_with_file_date("a","202403211030"); + ucmd.args(&["-i", "-u", "a", "b"]) + .pipe_in("N\n") + .succeeds().no_stdout(); +} + #[test] #[cfg(not(target_os = "android"))] fn test_cp_arg_interactive_verbose() { diff --git a/tests/common/util.rs b/tests/common/util.rs index 44f364b916a..5339e2b66af 100644 --- a/tests/common/util.rs +++ b/tests/common/util.rs @@ -8,6 +8,7 @@ #![allow(dead_code)] +use chrono::{NaiveDateTime, Utc, DateTime}; #[cfg(unix)] use nix::pty::OpenptyResult; use pretty_assertions::assert_eq; @@ -21,7 +22,7 @@ use std::collections::VecDeque; #[cfg(not(windows))] use std::ffi::CString; use std::ffi::{OsStr, OsString}; -use std::fs::{self, hard_link, remove_file, File, OpenOptions}; +use std::fs::{self, hard_link, remove_file, File, OpenOptions, FileTimes}; use std::io::{self, BufWriter, Read, Result, Write}; #[cfg(unix)] use std::os::fd::OwnedFd; @@ -40,7 +41,7 @@ use std::process::{Child, Command, ExitStatus, Output, Stdio}; use std::rc::Rc; use std::sync::mpsc::{self, RecvTimeoutError}; use std::thread::{sleep, JoinHandle}; -use std::time::{Duration, Instant}; +use std::time::{Duration, Instant, SystemTime}; use std::{env, hint, mem, thread}; use tempfile::{Builder, TempDir}; @@ -957,6 +958,27 @@ impl AtPath { File::create(self.plus(file)).unwrap(); } + pub fn touch_with_file_date>(&self, file: P, time: &str) { + let file = file.as_ref(); + log_info("touch", self.plus_as_string(file)); + let file_time = Self::parse_str_time_to_system_time(time); + let times = FileTimes::new() + .set_accessed(file_time) + .set_modified(file_time); + File::create(self.plus(file)) + .unwrap() + .set_times(times) + .unwrap(); + } + + fn parse_str_time_to_system_time(time: &str) -> SystemTime { + // Parse the time string (YYYYMMDDhhmm) to a DateTime + let naive_date_time = NaiveDateTime::parse_from_str(time, "%Y%m%d%H%M").unwrap(); + let date_time: DateTime = DateTime::::from_naive_utc_and_offset(naive_date_time,Utc); + // Convert the DateTime to a SystemTime + date_time.into() + } + #[cfg(not(windows))] pub fn mkfifo(&self, fifo: &str) { let full_path = self.plus_as_string(fifo); From 9f0caf4ea1a9750a66cb10b635dfeff094e59ff9 Mon Sep 17 00:00:00 2001 From: Vikrant2691 <37099198+Vikrant2691@users.noreply.github.com> Date: Fri, 22 Mar 2024 19:49:39 +0000 Subject: [PATCH 04/10] removed test cases with unstable libs --- tests/by-util/test_cp.rs | 18 +++--------------- tests/common/util.rs | 26 ++------------------------ 2 files changed, 5 insertions(+), 39 deletions(-) diff --git a/tests/by-util/test_cp.rs b/tests/by-util/test_cp.rs index 355bec60a8c..1511ed6dedc 100644 --- a/tests/by-util/test_cp.rs +++ b/tests/by-util/test_cp.rs @@ -521,8 +521,9 @@ 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. let (at, mut ucmd) = at_and_ucmd!(); - at.touch_with_file_date("b","202403211030"); - at.touch_with_file_date("a","202403211031"); + at.touch("b"); + std::thread::sleep(Duration::from_secs(1)); + at.touch("a"); ucmd.args(&["-i", "-u", "a", "b"]) .pipe_in("N\n") .fails() @@ -531,19 +532,6 @@ fn test_cp_arg_interactive_update_overwrite_older() { .stderr_is("cp: overwrite 'b'? "); } -#[test] -#[cfg(not(any(target_os = "android", target_os = "freebsd")))] -fn test_cp_arg_interactive_update_with_create_dates_equal() { - // -u -i *WILL NOT* show the prompt to validate the override. - let (at, mut ucmd) = at_and_ucmd!(); - // Create files with the same creation date - at.touch_with_file_date("b","202403211030"); - at.touch_with_file_date("a","202403211030"); - ucmd.args(&["-i", "-u", "a", "b"]) - .pipe_in("N\n") - .succeeds().no_stdout(); -} - #[test] #[cfg(not(target_os = "android"))] fn test_cp_arg_interactive_verbose() { diff --git a/tests/common/util.rs b/tests/common/util.rs index 5339e2b66af..44f364b916a 100644 --- a/tests/common/util.rs +++ b/tests/common/util.rs @@ -8,7 +8,6 @@ #![allow(dead_code)] -use chrono::{NaiveDateTime, Utc, DateTime}; #[cfg(unix)] use nix::pty::OpenptyResult; use pretty_assertions::assert_eq; @@ -22,7 +21,7 @@ use std::collections::VecDeque; #[cfg(not(windows))] use std::ffi::CString; use std::ffi::{OsStr, OsString}; -use std::fs::{self, hard_link, remove_file, File, OpenOptions, FileTimes}; +use std::fs::{self, hard_link, remove_file, File, OpenOptions}; use std::io::{self, BufWriter, Read, Result, Write}; #[cfg(unix)] use std::os::fd::OwnedFd; @@ -41,7 +40,7 @@ use std::process::{Child, Command, ExitStatus, Output, Stdio}; use std::rc::Rc; use std::sync::mpsc::{self, RecvTimeoutError}; use std::thread::{sleep, JoinHandle}; -use std::time::{Duration, Instant, SystemTime}; +use std::time::{Duration, Instant}; use std::{env, hint, mem, thread}; use tempfile::{Builder, TempDir}; @@ -958,27 +957,6 @@ impl AtPath { File::create(self.plus(file)).unwrap(); } - pub fn touch_with_file_date>(&self, file: P, time: &str) { - let file = file.as_ref(); - log_info("touch", self.plus_as_string(file)); - let file_time = Self::parse_str_time_to_system_time(time); - let times = FileTimes::new() - .set_accessed(file_time) - .set_modified(file_time); - File::create(self.plus(file)) - .unwrap() - .set_times(times) - .unwrap(); - } - - fn parse_str_time_to_system_time(time: &str) -> SystemTime { - // Parse the time string (YYYYMMDDhhmm) to a DateTime - let naive_date_time = NaiveDateTime::parse_from_str(time, "%Y%m%d%H%M").unwrap(); - let date_time: DateTime = DateTime::::from_naive_utc_and_offset(naive_date_time,Utc); - // Convert the DateTime to a SystemTime - date_time.into() - } - #[cfg(not(windows))] pub fn mkfifo(&self, fifo: &str) { let full_path = self.plus_as_string(fifo); From 68e6ab9e4b1bb89d1ad6a0c7e84f04bdd3c35409 Mon Sep 17 00:00:00 2001 From: Vikrant2691 <37099198+Vikrant2691@users.noreply.github.com> Date: Wed, 13 Mar 2024 23:31:11 +0000 Subject: [PATCH 05/10] updated prompt logic to handle update with and without interactive mode enabled --- src/uu/cp/src/cp.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index 778ddf843b6..0dab63653d9 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -1540,7 +1540,9 @@ fn handle_existing_dest( return Err(format!("{} and {} are the same file", source.quote(), dest.quote()).into()); } - options.overwrite.verify(dest)?; + if options.update != UpdateMode::ReplaceIfOlder { + options.overwrite.verify(dest)?; + } let backup_path = backup_control::get_backup_path(options.backup, dest, &options.backup_suffix); if let Some(backup_path) = backup_path { @@ -1767,6 +1769,8 @@ fn handle_copy_mode( if src_time <= dest_time { return Ok(()); } else { + options.overwrite.verify(dest)?; + copy_helper( source, dest, @@ -1863,14 +1867,6 @@ fn copy_file( copied_files: &mut HashMap, source_in_command_line: bool, ) -> CopyResult<()> { - if (options.update == UpdateMode::ReplaceIfOlder || options.update == UpdateMode::ReplaceNone) - && options.overwrite == OverwriteMode::Interactive(ClobberMode::Standard) - { - // `cp -i --update old new` when `new` exists doesn't copy anything - // and exit with 0 - return Ok(()); - } - // Fail if dest is a dangling symlink or a symlink this program created previously if dest.is_symlink() { if FileInformation::from_path(dest, false) From 96c776c27ccb85791ce6cbf6645dafe62537dd9d Mon Sep 17 00:00:00 2001 From: Vikrant2691 <37099198+Vikrant2691@users.noreply.github.com> Date: Thu, 14 Mar 2024 18:59:16 +0000 Subject: [PATCH 06/10] updated codebase --- tests/by-util/test_cp.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/by-util/test_cp.rs b/tests/by-util/test_cp.rs index e3b373da19d..884dc885539 100644 --- a/tests/by-util/test_cp.rs +++ b/tests/by-util/test_cp.rs @@ -517,7 +517,6 @@ 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() { // -u -i *WILL* show the prompt to validate the override. // Therefore, the error code depends on the prompt response. From 36b868964cb62f66939a5c8b1a96ec16e1dd36fe Mon Sep 17 00:00:00 2001 From: Vikrant2691 <37099198+Vikrant2691@users.noreply.github.com> Date: Fri, 22 Mar 2024 01:09:48 +0000 Subject: [PATCH 07/10] added explicit file creation timestamps for test cases to fix the tests --- tests/by-util/test_cp.rs | 21 +++++++++++++++++---- tests/common/util.rs | 26 ++++++++++++++++++++++++-- 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/tests/by-util/test_cp.rs b/tests/by-util/test_cp.rs index 884dc885539..fa47e7093e0 100644 --- a/tests/by-util/test_cp.rs +++ b/tests/by-util/test_cp.rs @@ -498,7 +498,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 +517,12 @@ fn test_cp_arg_interactive_update() { #[test] #[cfg(not(any(target_os = "android", target_os = "freebsd")))] -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. let (at, mut ucmd) = at_and_ucmd!(); - at.touch("b"); - at.touch("a"); + at.touch_with_file_date("b","202403211030"); + at.touch_with_file_date("a","202403211031"); ucmd.args(&["-i", "-u", "a", "b"]) .pipe_in("N\n") .fails() @@ -531,6 +531,19 @@ fn test_cp_arg_interactive_update_newer() { .stderr_is("cp: overwrite 'b'? "); } +#[test] +#[cfg(not(any(target_os = "android", target_os = "freebsd")))] +fn test_cp_arg_interactive_update_with_create_dates_equal() { + // -u -i *WILL NOT* show the prompt to validate the override. + let (at, mut ucmd) = at_and_ucmd!(); + // Create files with the same creation date + at.touch_with_file_date("b","202403211030"); + at.touch_with_file_date("a","202403211030"); + ucmd.args(&["-i", "-u", "a", "b"]) + .pipe_in("N\n") + .succeeds().no_stdout(); +} + #[test] #[cfg(not(target_os = "android"))] fn test_cp_arg_interactive_verbose() { diff --git a/tests/common/util.rs b/tests/common/util.rs index 19ef8317af2..3c587920688 100644 --- a/tests/common/util.rs +++ b/tests/common/util.rs @@ -8,6 +8,7 @@ #![allow(dead_code)] +use chrono::{NaiveDateTime, Utc, DateTime}; #[cfg(unix)] use nix::pty::OpenptyResult; use pretty_assertions::assert_eq; @@ -20,7 +21,7 @@ use std::collections::VecDeque; #[cfg(not(windows))] use std::ffi::CString; use std::ffi::{OsStr, OsString}; -use std::fs::{self, hard_link, remove_file, File, OpenOptions}; +use std::fs::{self, hard_link, remove_file, File, OpenOptions, FileTimes}; use std::io::{self, BufWriter, Read, Result, Write}; #[cfg(unix)] use std::os::fd::OwnedFd; @@ -39,7 +40,7 @@ use std::process::{Child, Command, ExitStatus, Output, Stdio}; use std::rc::Rc; use std::sync::mpsc::{self, RecvTimeoutError}; use std::thread::{sleep, JoinHandle}; -use std::time::{Duration, Instant}; +use std::time::{Duration, Instant, SystemTime}; use std::{env, hint, mem, thread}; use tempfile::{Builder, TempDir}; @@ -967,6 +968,27 @@ impl AtPath { File::create(self.plus(file)).unwrap(); } + pub fn touch_with_file_date>(&self, file: P, time: &str) { + let file = file.as_ref(); + log_info("touch", self.plus_as_string(file)); + let file_time = Self::parse_str_time_to_system_time(time); + let times = FileTimes::new() + .set_accessed(file_time) + .set_modified(file_time); + File::create(self.plus(file)) + .unwrap() + .set_times(times) + .unwrap(); + } + + fn parse_str_time_to_system_time(time: &str) -> SystemTime { + // Parse the time string (YYYYMMDDhhmm) to a DateTime + let naive_date_time = NaiveDateTime::parse_from_str(time, "%Y%m%d%H%M").unwrap(); + let date_time: DateTime = DateTime::::from_naive_utc_and_offset(naive_date_time,Utc); + // Convert the DateTime to a SystemTime + date_time.into() + } + #[cfg(not(windows))] pub fn mkfifo(&self, fifo: &str) { let full_path = self.plus_as_string(fifo); From 1a7877bcc455dfd3e018e7e9af9d75eb6c1fc48f Mon Sep 17 00:00:00 2001 From: Vikrant2691 <37099198+Vikrant2691@users.noreply.github.com> Date: Fri, 22 Mar 2024 19:49:39 +0000 Subject: [PATCH 08/10] removed test cases with unstable libs --- tests/by-util/test_cp.rs | 18 +++--------------- tests/common/util.rs | 26 ++------------------------ 2 files changed, 5 insertions(+), 39 deletions(-) diff --git a/tests/by-util/test_cp.rs b/tests/by-util/test_cp.rs index fa47e7093e0..8c47089859c 100644 --- a/tests/by-util/test_cp.rs +++ b/tests/by-util/test_cp.rs @@ -521,8 +521,9 @@ 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. let (at, mut ucmd) = at_and_ucmd!(); - at.touch_with_file_date("b","202403211030"); - at.touch_with_file_date("a","202403211031"); + at.touch("b"); + std::thread::sleep(Duration::from_secs(1)); + at.touch("a"); ucmd.args(&["-i", "-u", "a", "b"]) .pipe_in("N\n") .fails() @@ -531,19 +532,6 @@ fn test_cp_arg_interactive_update_overwrite_older() { .stderr_is("cp: overwrite 'b'? "); } -#[test] -#[cfg(not(any(target_os = "android", target_os = "freebsd")))] -fn test_cp_arg_interactive_update_with_create_dates_equal() { - // -u -i *WILL NOT* show the prompt to validate the override. - let (at, mut ucmd) = at_and_ucmd!(); - // Create files with the same creation date - at.touch_with_file_date("b","202403211030"); - at.touch_with_file_date("a","202403211030"); - ucmd.args(&["-i", "-u", "a", "b"]) - .pipe_in("N\n") - .succeeds().no_stdout(); -} - #[test] #[cfg(not(target_os = "android"))] fn test_cp_arg_interactive_verbose() { diff --git a/tests/common/util.rs b/tests/common/util.rs index 3c587920688..19ef8317af2 100644 --- a/tests/common/util.rs +++ b/tests/common/util.rs @@ -8,7 +8,6 @@ #![allow(dead_code)] -use chrono::{NaiveDateTime, Utc, DateTime}; #[cfg(unix)] use nix::pty::OpenptyResult; use pretty_assertions::assert_eq; @@ -21,7 +20,7 @@ use std::collections::VecDeque; #[cfg(not(windows))] use std::ffi::CString; use std::ffi::{OsStr, OsString}; -use std::fs::{self, hard_link, remove_file, File, OpenOptions, FileTimes}; +use std::fs::{self, hard_link, remove_file, File, OpenOptions}; use std::io::{self, BufWriter, Read, Result, Write}; #[cfg(unix)] use std::os::fd::OwnedFd; @@ -40,7 +39,7 @@ use std::process::{Child, Command, ExitStatus, Output, Stdio}; use std::rc::Rc; use std::sync::mpsc::{self, RecvTimeoutError}; use std::thread::{sleep, JoinHandle}; -use std::time::{Duration, Instant, SystemTime}; +use std::time::{Duration, Instant}; use std::{env, hint, mem, thread}; use tempfile::{Builder, TempDir}; @@ -968,27 +967,6 @@ impl AtPath { File::create(self.plus(file)).unwrap(); } - pub fn touch_with_file_date>(&self, file: P, time: &str) { - let file = file.as_ref(); - log_info("touch", self.plus_as_string(file)); - let file_time = Self::parse_str_time_to_system_time(time); - let times = FileTimes::new() - .set_accessed(file_time) - .set_modified(file_time); - File::create(self.plus(file)) - .unwrap() - .set_times(times) - .unwrap(); - } - - fn parse_str_time_to_system_time(time: &str) -> SystemTime { - // Parse the time string (YYYYMMDDhhmm) to a DateTime - let naive_date_time = NaiveDateTime::parse_from_str(time, "%Y%m%d%H%M").unwrap(); - let date_time: DateTime = DateTime::::from_naive_utc_and_offset(naive_date_time,Utc); - // Convert the DateTime to a SystemTime - date_time.into() - } - #[cfg(not(windows))] pub fn mkfifo(&self, fifo: &str) { let full_path = self.plus_as_string(fifo); From e0f89604e3bd6a538c2254a13577b046acaea1a1 Mon Sep 17 00:00:00 2001 From: Vikrant2691 <37099198+Vikrant2691@users.noreply.github.com> Date: Mon, 25 Mar 2024 19:33:20 +0000 Subject: [PATCH 09/10] Removed flaky test Added a test for the 'Y' option. --- tests/by-util/test_cp.rs | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/tests/by-util/test_cp.rs b/tests/by-util/test_cp.rs index 8c47089859c..3781a6ec7e6 100644 --- a/tests/by-util/test_cp.rs +++ b/tests/by-util/test_cp.rs @@ -274,19 +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() { @@ -520,6 +507,7 @@ fn test_cp_arg_interactive_update_overwrite_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)); @@ -530,6 +518,16 @@ fn test_cp_arg_interactive_update_overwrite_older() { .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] From d9a25919fabc5b3319fd7ad6890dc6056f8ed708 Mon Sep 17 00:00:00 2001 From: Vikrant2691 <37099198+Vikrant2691@users.noreply.github.com> Date: Tue, 26 Mar 2024 18:26:48 +0000 Subject: [PATCH 10/10] fix formatting issues --- tests/by-util/test_cp.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/by-util/test_cp.rs b/tests/by-util/test_cp.rs index 3781a6ec7e6..bdfc9c8e8a4 100644 --- a/tests/by-util/test_cp.rs +++ b/tests/by-util/test_cp.rs @@ -274,7 +274,6 @@ fn test_cp_target_directory_is_file() { .stderr_contains(format!("'{TEST_HOW_ARE_YOU_SOURCE}' is not a directory")); } - #[test] fn test_cp_arg_update_interactive_error() { new_ucmd!() @@ -518,7 +517,7 @@ fn test_cp_arg_interactive_update_overwrite_older() { .code_is(1) .no_stdout() .stderr_is("cp: overwrite 'b'? "); - + // Option Y let (at, mut ucmd) = at_and_ucmd!(); at.touch("b");