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

Merge pull request #7579 from drinkcat/test_file_N

test_test: Simplify test_file_N
This commit is contained in:
Sylvestre Ledru 2025-03-26 08:47:18 +01:00 committed by GitHub
commit 68515b5d3b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -918,16 +918,31 @@ fn test_bracket_syntax_version() {
#[allow(non_snake_case)]
#[cfg(unix)]
fn test_file_N() {
use std::{fs::FileTimes, time::Duration};
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
let f = at.make_file("file");
f.set_modified(std::time::UNIX_EPOCH).unwrap();
// Set the times so that the file is accessed _after_ being modified
// => test -N return false.
let times = FileTimes::new()
.set_accessed(std::time::UNIX_EPOCH + Duration::from_secs(123))
.set_modified(std::time::UNIX_EPOCH);
f.set_times(times).unwrap();
// TODO: stat call for debugging #7570, remove?
println!("{}", scene.cmd_shell("stat file").succeeds().stdout_str());
scene.ucmd().args(&["-N", "file"]).fails();
// The file will have different create/modified data
// so, test -N will return 0
at.touch("file");
// Set the times so that the file is modified _after_ being accessed
// => test -N return true.
let times = FileTimes::new()
.set_accessed(std::time::UNIX_EPOCH)
.set_modified(std::time::UNIX_EPOCH + Duration::from_secs(123));
f.set_times(times).unwrap();
// TODO: stat call for debugging #7570, remove?
println!("{}", scene.cmd_shell("stat file").succeeds().stdout_str());
scene.ucmd().args(&["-N", "file"]).succeeds();
}