From dbfd700502cdd0beac32e7ab3cb9397c9f4d6b99 Mon Sep 17 00:00:00 2001 From: Nathan Houghton Date: Sun, 22 Oct 2023 10:51:15 -0700 Subject: [PATCH] test: use mtime for -ot and fix direction of comparison - Use the file modification time instead of the creation time (matches GNU coreutils documentation) - Fix direction of comparison (a < b instead of a > b) - Extend test case to cover both the 0 and 1 exit code cases --- src/uu/test/src/test.rs | 2 +- tests/by-util/test_test.rs | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/uu/test/src/test.rs b/src/uu/test/src/test.rs index 7e778f9b5e..4f230a590d 100644 --- a/src/uu/test/src/test.rs +++ b/src/uu/test/src/test.rs @@ -218,7 +218,7 @@ fn files(a: &OsStr, b: &OsStr, op: &OsStr) -> ParseResult { #[cfg(not(unix))] Some("-ef") => unimplemented!(), Some("-nt") => f_a.modified().unwrap() > f_b.modified().unwrap(), - Some("-ot") => f_a.created().unwrap() > f_b.created().unwrap(), + Some("-ot") => f_a.modified().unwrap() < f_b.modified().unwrap(), _ => return Err(ParseError::UnknownOperator(op.quote().to_string())), }) } diff --git a/tests/by-util/test_test.rs b/tests/by-util/test_test.rs index 2f36a805c3..922d854c64 100644 --- a/tests/by-util/test_test.rs +++ b/tests/by-util/test_test.rs @@ -317,7 +317,7 @@ fn test_file_is_itself() { } #[test] -#[cfg(not(any(target_env = "musl", target_os = "android")))] +#[cfg(not(target_os = "android"))] fn test_file_is_newer_than_and_older_than_itself() { // odd but matches GNU new_ucmd!() @@ -364,8 +364,7 @@ fn test_same_device_inode() { } #[test] -#[cfg(not(any(target_env = "musl", target_os = "android")))] -// musl: creation time is not available on this platform currently +#[cfg(not(target_os = "android"))] fn test_newer_file() { let scenario = TestScenario::new(util_name!()); @@ -377,10 +376,21 @@ fn test_newer_file() { .ucmd() .args(&["newer_file", "-nt", "regular_file"]) .succeeds(); + scenario .ucmd() - .args(&["newer_file", "-ot", "regular_file"]) + .args(&["regular_file", "-nt", "newer_file"]) + .fails(); + + scenario + .ucmd() + .args(&["regular_file", "-ot", "newer_file"]) .succeeds(); + + scenario + .ucmd() + .args(&["newer_file", "-ot", "regular_file"]) + .fails(); } #[test]