From b099b26fbc265bd8085acdd452476ade05dab804 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sun, 5 Jan 2025 17:47:03 -0600 Subject: [PATCH] Test -nt and -ot should only check nanoseconds when seconds match. --- tests/test.test | 5 ++++- toys/posix/test.c | 10 ++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/test.test b/tests/test.test index 185eab8b..a40902d3 100644 --- a/tests/test.test +++ b/tests/test.test @@ -114,14 +114,17 @@ testing "-lt" "arith_test -lt" "l" "" "" testing "-le" "arith_test -le" "le" "" "" touch oldfile -d 1970-01-01 -touch newfile -d 2031-01-01 +touch newfile -d 2031-01-01T00:00:00.5 +ln -s newfile samefile testcmd "-ef" "newfile -ef newfile && echo yes" "yes\n" "" "" +testcmd "-ef link" "newfile -ef samefile && echo yes" "yes\n" "" "" testcmd "-ef2" "newfile -ef oldfile || echo no" "no\n" "" "" testcmd "-ot" "oldfile -ot newfile && echo yes" "yes\n" "" "" testcmd "-ot2" "oldfile -ot oldfile || echo no" "no\n" "" "" testcmd "-nt" "newfile -nt oldfile && echo yes" "yes\n" "" "" testcmd "-nt2" "oldfile -nt newfile || echo no" "no\n" "" "" +testcmd "-nt2" "oldfile -nt newfile || echo no" "no\n" "" "" testing "positional" "test -a == -a && echo yes" "yes\n" "" "" testing "! stacks" 'test \! \! \! \! 2 -eq 2 && echo yes' "yes\n" "" "" diff --git a/toys/posix/test.c b/toys/posix/test.c index 8395b8d3..2fda1718 100644 --- a/toys/posix/test.c +++ b/toys/posix/test.c @@ -98,10 +98,12 @@ static int do_test(char **args, int *count) if (i==8) return a < b; if (i==10) return a<= b; if (i==12) return (st1.st_dev==st2.st_dev) && (st1.st_ino==st2.st_ino); - if (i==14) return (st1.st_atim.tv_sec < st2.st_atim.tv_sec) || - (st1.st_atim.tv_nsec < st2.st_atim.tv_nsec); - if (i==16) return (st1.st_atim.tv_sec > st2.st_atim.tv_sec) || - (st1.st_atim.tv_nsec > st2.st_atim.tv_nsec); + if (i==14) return (st1.st_mtim.tv_sec < st2.st_mtim.tv_sec) || + (st1.st_mtim.tv_sec == st2.st_mtim.tv_sec && + st1.st_mtim.tv_nsec < st2.st_mtim.tv_nsec); + if (i==16) return (st1.st_mtim.tv_sec > st2.st_mtim.tv_sec) || + (st1.st_mtim.tv_sec == st2.st_mtim.tv_sec && + st1.st_mtim.tv_nsec > st2.st_mtim.tv_nsec); } } s = *args; -- 2.39.5