Skip to content

Commit

Permalink
Merge pull request uutils#5441 from n1000/test_ot_fix
Browse files Browse the repository at this point in the history
test: use mtime for -ot and fix direction of comparison
  • Loading branch information
sylvestre committed Oct 23, 2023
2 parents 9389c44 + dbfd700 commit 209ffe8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/uu/test/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ fn files(a: &OsStr, b: &OsStr, op: &OsStr) -> ParseResult<bool> {
#[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())),
})
}
Expand Down
18 changes: 14 additions & 4 deletions tests/by-util/test_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!()
Expand Down Expand Up @@ -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!());

Expand All @@ -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]
Expand Down

0 comments on commit 209ffe8

Please sign in to comment.