From 6b8135119c4cd2eb545897ad1206e5f9ec162614 Mon Sep 17 00:00:00 2001 From: Nicolas Boichat Date: Tue, 25 Mar 2025 15:01:23 +0100 Subject: [PATCH] test_test: Simplify test_file_N I found the logic a little difficult to understand, and the comment probably doesn't match what `-N` is supposed to do? Intead, let's just manually set mtime and atime. Hopefully this helps clear up Android flakiness in #7570. Or at least understand better what is going on. --- tests/by-util/test_test.rs | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/tests/by-util/test_test.rs b/tests/by-util/test_test.rs index aab86d230..41d83c520 100644 --- a/tests/by-util/test_test.rs +++ b/tests/by-util/test_test.rs @@ -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(); }