From fee851dc1c99588a21eb44b7999b7d717c52e85d Mon Sep 17 00:00:00 2001 From: Niyaz Nigmatullin Date: Mon, 8 Aug 2022 12:11:17 +0300 Subject: [PATCH] test/cp: fix test_copy_through_dangling_symlink_no_dereference_permissions (#3789) * test/cp: -p changes ctime and added sleep for better timestamp testing * test/cp: add nanoseconds checking for copied timestamps * test/cp: made compilable on other OSes * test/cp: added error messages to assert_eq calls --- tests/by-util/test_cp.rs | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/tests/by-util/test_cp.rs b/tests/by-util/test_cp.rs index 037a63890..fa53969d1 100644 --- a/tests/by-util/test_cp.rs +++ b/tests/by-util/test_cp.rs @@ -22,9 +22,7 @@ use filetime::FileTime; use rlimit::Resource; #[cfg(any(target_os = "linux", target_os = "android"))] use std::fs as std_fs; -#[cfg(any(target_os = "linux", target_os = "android"))] use std::thread::sleep; -#[cfg(any(target_os = "linux", target_os = "android"))] use std::time::Duration; use uucore::display::Quotable; @@ -1732,6 +1730,8 @@ fn test_copy_through_dangling_symlink_no_dereference_permissions() { let (at, mut ucmd) = at_and_ucmd!(); // target name link name at.symlink_file("no-such-file", "dangle"); + // to check if access time and modification time didn't change + sleep(Duration::from_millis(5000)); // don't dereference the link // | copy permissions, too // | | from the link @@ -1742,18 +1742,27 @@ fn test_copy_through_dangling_symlink_no_dereference_permissions() { .succeeds() .no_stderr() .no_stdout(); - assert!(at.symlink_exists("d2")); + assert!(at.symlink_exists("d2"), "symlink wasn't created"); // `-p` means `--preserve=mode,ownership,timestamps` #[cfg(unix)] { let metadata1 = at.symlink_metadata("dangle"); let metadata2 = at.symlink_metadata("d2"); - assert_eq!(metadata1.mode(), metadata2.mode()); - assert_eq!(metadata1.uid(), metadata2.uid()); - assert_eq!(metadata1.atime(), metadata2.atime()); - assert_eq!(metadata1.mtime(), metadata2.mtime()); - assert_eq!(metadata1.ctime(), metadata2.ctime()); + assert_eq!(metadata1.mode(), metadata2.mode(), "mode is different"); + assert_eq!(metadata1.uid(), metadata2.uid(), "uid is different"); + assert_eq!(metadata1.atime(), metadata2.atime(), "atime is different"); + assert_eq!( + metadata1.atime_nsec(), + metadata2.atime_nsec(), + "atime_nsec is different" + ); + assert_eq!(metadata1.mtime(), metadata2.mtime(), "mtime is different"); + assert_eq!( + metadata1.mtime_nsec(), + metadata2.mtime_nsec(), + "mtime_nsec is different" + ); } }