install: dereference source symlinks when comparing
[coreutils.git] / tests / test / test-N.sh
blob37db9c8067a11012315d196041ce00b20b162430
1 #!/bin/sh
2 # Test 'test -N file'.
4 # Copyright (C) 2018-2024 Free Software Foundation, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
20 print_ver_ test stat
22 stat_test_N() {
23 mtime=$(env stat -c '%.Y' "$1")
24 atime=$(env stat -c '%.X' "$1")
25 test "$mtime" = "$atime" && return 1
26 latest=$(printf '%s\n' "$mtime" "$atime" | sort -g | tail -n1)
27 test "$mtime" = "$latest"
30 # For a freshly touched file, atime should equal mtime: 'test -N' returns 1.
31 touch file || framework_failure_
32 if ! stat_test_N file; then
33 returns_ 1 env test -N file || fail=1
36 # Set access time to 2 days ago: 'test -N' returns 0.
37 touch -a -d '12:00 today -2 days' file || framework_failure_
38 if stat_test_N file; then
39 env test -N file || fail=1
42 # Set mtime to 2 days before atime: 'test -N' returns 1;
43 touch -m -d '12:00 today -4 days' file || framework_failure_
44 if ! stat_test_N file; then
45 returns_ 1 env test -N file || fail=1
48 # Now modify the file: 'test -N' returns 0.
49 echo 'data' > file || framework_failure_
50 if stat_test_N file; then
51 env test -N file || fail=1
54 Exit $fail