diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 16:11:47 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 16:11:47 +0000 |
commit | 758f820bcc0f68aeebac1717e537ca13a320b909 (patch) | |
tree | 48111ece75cf4f98316848b37a7e26356e00669e /tests/touch | |
parent | Initial commit. (diff) | |
download | coreutils-758f820bcc0f68aeebac1717e537ca13a320b909.tar.xz coreutils-758f820bcc0f68aeebac1717e537ca13a320b909.zip |
Adding upstream version 9.1.upstream/9.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/touch')
-rwxr-xr-x | tests/touch/60-seconds.sh | 33 | ||||
-rwxr-xr-x | tests/touch/dangling-symlink.sh | 49 | ||||
-rwxr-xr-x | tests/touch/dir-1.sh | 9 | ||||
-rwxr-xr-x | tests/touch/empty-file.sh | 80 | ||||
-rwxr-xr-x | tests/touch/fail-diag.sh | 32 | ||||
-rwxr-xr-x | tests/touch/fifo.sh | 27 | ||||
-rwxr-xr-x | tests/touch/no-create-missing.sh | 37 | ||||
-rwxr-xr-x | tests/touch/no-dereference.sh | 82 | ||||
-rwxr-xr-x | tests/touch/no-rights.sh | 40 | ||||
-rwxr-xr-x | tests/touch/not-owner.sh | 55 | ||||
-rwxr-xr-x | tests/touch/now-owned-by-other.sh | 34 | ||||
-rwxr-xr-x | tests/touch/obsolescent.sh | 41 | ||||
-rwxr-xr-x | tests/touch/read-only.sh | 31 | ||||
-rwxr-xr-x | tests/touch/relative.sh | 38 | ||||
-rwxr-xr-x | tests/touch/trailing-slash.sh | 70 |
15 files changed, 658 insertions, 0 deletions
diff --git a/tests/touch/60-seconds.sh b/tests/touch/60-seconds.sh new file mode 100755 index 0000000..8b30a8e --- /dev/null +++ b/tests/touch/60-seconds.sh @@ -0,0 +1,33 @@ +#!/bin/sh +# touch -t would mistakenly reject a time specifying "60" seconds + +# Copyright (C) 2009-2022 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ touch + +echo 60.000000000 > exp || framework_failure_ + + +# Before coreutils-7.7, this would fail, complaining of +# an 'invalid date format'. Specifying 60 seconds *is* valid. +TZ=UTC0 touch -t 197001010000.60 f || fail=1 + +stat --p='%.9Y\n' f > out || fail=1 + +compare exp out || fail=1 + +Exit $fail diff --git a/tests/touch/dangling-symlink.sh b/tests/touch/dangling-symlink.sh new file mode 100755 index 0000000..2b34dd4 --- /dev/null +++ b/tests/touch/dangling-symlink.sh @@ -0,0 +1,49 @@ +#!/bin/sh +# Make sure touch can create a file through a dangling symlink. +# This was broken in the 4.0[e-i] test releases. + +# Copyright (C) 1999-2022 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ touch + +rm -f touch-target t-symlink +ln -s touch-target t-symlink + +# This used to infloop. +touch t-symlink || fail=1 + +test -f touch-target || fail=1 +rm -f touch-target t-symlink + +if test $fail = 1; then + case $host_triplet in + *linux-gnu*) + case "$(uname -r)" in + 2.3.9[0-9]*) + skip_ \ +'**************************************************** +WARNING!!! +This version of the Linux kernel causes touch to fail +when operating on dangling symlinks. +****************************************************' + ;; + esac + ;; + esac +fi + +Exit $fail diff --git a/tests/touch/dir-1.sh b/tests/touch/dir-1.sh new file mode 100755 index 0000000..cb0e172 --- /dev/null +++ b/tests/touch/dir-1.sh @@ -0,0 +1,9 @@ +#!/bin/sh +# Make sure touch can operate on a directory. +# This was broken in the 4.0[efg] test releases. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ touch + +touch . || fail=1 +Exit $fail diff --git a/tests/touch/empty-file.sh b/tests/touch/empty-file.sh new file mode 100755 index 0000000..908f268 --- /dev/null +++ b/tests/touch/empty-file.sh @@ -0,0 +1,80 @@ +#!/bin/sh +# Make sure touch can set the mtime on an empty file. + +# Copyright (C) 1998-2022 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + + +# Volker Borchert reported that touch 3.16r (and presumably all before that) +# fails to work on SunOS 4.1.3 with 'most of the recommended patches' when +# the empty file is on an NFS-mounted 4.2 volume. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ touch + +DEFAULT_SLEEP_SECONDS=2 +SLEEP_SECONDS=${SLEEP_SECONDS=$DEFAULT_SLEEP_SECONDS} + + +# FIXME: find writable directories on other partitions +# and run the test in those directories, too. + +: ${TOUCH_DIR_LIST=.} + + +for d in $TOUCH_DIR_LIST; do + rm -rf $d/a $d/b $d/c + > $d/a || framework_failure_ + test -f $d/a || framework_failure_ + > $d/b || framework_failure_ + test -f $d/b || framework_failure_ + > $d/c || framework_failure_ + test -f $d/c || framework_failure_ +done + +echo sleeping for $SLEEP_SECONDS seconds... +sleep $SLEEP_SECONDS +for d in $TOUCH_DIR_LIST; do + touch $d/a || fail=1 + set x $(ls -t $d/a $d/b) + test "$*" = "x $d/a $d/b" || fail=1 +done + +echo sleeping for $SLEEP_SECONDS seconds... +sleep $SLEEP_SECONDS +for d in $TOUCH_DIR_LIST; do + touch $d/b + set x $(ls -t $d/a $d/b) + test "$*" = "x $d/b $d/a" || fail=1 + + if touch - 1< $d/c 2> /dev/null; then + set x $(ls -t $d/a $d/c) + test "$*" = "x $d/c $d/a" || fail=1 + fi + + rm -rf $d/a $d/b $d/c +done + +if test $fail != 0; then + cat 1>&2 <<EOF +*** This test has just failed. That can happen when the test is run in an +*** NFS-mounted directory on a system whose clock is not well synchronized +*** with that of the NFS server. If you think that is the reason, set the +*** environment variable SLEEP_SECONDS to some number of seconds larger than +*** the default of $DEFAULT_SLEEP_SECONDS and rerun the test. +EOF +fi + +Exit $fail diff --git a/tests/touch/fail-diag.sh b/tests/touch/fail-diag.sh new file mode 100755 index 0000000..7678440 --- /dev/null +++ b/tests/touch/fail-diag.sh @@ -0,0 +1,32 @@ +#!/bin/sh +# make sure touch gives reasonable diagnostics + +# Copyright (C) 2001-2022 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ touch +skip_if_root_ + +file=/no-such-dir/file + +touch $file > out 2>&1 && fail=1 +cat <<EOF > exp +touch: cannot touch '$file': No such file or directory +EOF + +compare exp out || fail=1 + +Exit $fail diff --git a/tests/touch/fifo.sh b/tests/touch/fifo.sh new file mode 100755 index 0000000..0129c3e --- /dev/null +++ b/tests/touch/fifo.sh @@ -0,0 +1,27 @@ +#!/bin/sh +# Make sure touch works on fifos without hanging. + +# Copyright (C) 2000-2022 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ touch + +mkfifo_or_skip_ fifo + + +touch fifo || fail=1 + +Exit $fail diff --git a/tests/touch/no-create-missing.sh b/tests/touch/no-create-missing.sh new file mode 100755 index 0000000..bc4bddf --- /dev/null +++ b/tests/touch/no-create-missing.sh @@ -0,0 +1,37 @@ +#!/bin/sh +# Ensure that touch -c no-such-file no longer fails (it did in 4.1.8). + +# Copyright (C) 2002-2022 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ touch test + + +touch -c no-file > /dev/null 2>&1 || fail=1 +touch -cm no-file > /dev/null 2>&1 || fail=1 +touch -ca no-file > /dev/null 2>&1 || fail=1 + +# If >&- works, test "touch -c -" etc. +# >&- apparently does not work in HP-UX 11.23. +# This test is ineffective unless /dev/stdout also works. +if env test -w /dev/stdout >/dev/null && + env test ! -w /dev/stdout >&-; then + touch -c - >&- 2> /dev/null || fail=1 + touch -cm - >&- 2> /dev/null || fail=1 + touch -ca - >&- 2> /dev/null || fail=1 +fi + +Exit $fail diff --git a/tests/touch/no-dereference.sh b/tests/touch/no-dereference.sh new file mode 100755 index 0000000..5249d62 --- /dev/null +++ b/tests/touch/no-dereference.sh @@ -0,0 +1,82 @@ +#!/bin/sh +# Ensure that touch -h works. + +# Copyright (C) 2009-2022 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ touch test + +ln -s nowhere dangling || framework_failure_ +touch file || framework_failure_ +ln -s file link || framework_failure_ + + +# These first tests should work on every platform. +# -h does not create files, but it warns. Use -c to silence warning. +returns_ 1 touch -h no-file 2> err || fail=1 +compare /dev/null err && fail=1 +touch -h -c no-file 2> err || fail=1 +compare /dev/null err || fail=1 + +# -h works on regular files +touch -h file || fail=1 + +# -h coupled with -r uses timestamp of the symlink, not the referent. +touch -h -r dangling file || fail=1 +test -f nowhere && fail=1 + +# The remaining tests of -h require kernel support for changing symlink times. +grep '^#define HAVE_UTIMENSAT 1' "$CONFIG_HEADER" > /dev/null || +grep '^#define HAVE_LUTIMES 1' "$CONFIG_HEADER" > /dev/null || + skip_ 'this system lacks the utimensat function' + +# Changing time of dangling symlink is okay. +# Skip the test if this fails, but the error text corresponds to +# ENOSYS (possible with old kernel but new glibc). +touch -h dangling 2> err +case $? in + 0) test -f nowhere && fail=1 + compare /dev/null err || fail=1;; + 1) grep 'Function not implemented' err \ + && skip_ 'this system lacks the utimensat function' + fail=1;; + *) fail=1;; +esac + +# Change the mtime of a symlink. +touch -m -h -d 2009-10-10 link || fail=1 +case $(stat --format=%y link) in + 2009-10-10*) ;; + *) fail=1 ;; +esac +case $(stat --format=%y file) in + 2009-10-10*) fail=1;; +esac + +# Test interactions with -. +touch -h - > file || fail=1 + +# If >&- works, test "touch -ch -" etc. +# >&- apparently does not work in HP-UX 11.23. +# This test is ineffective unless /dev/stdout also works. +# If stdout is open, it is not a symlink. +if env test -w /dev/stdout >/dev/null && + env test ! -w /dev/stdout >&-; then + returns_ 1 touch -h - >&- || fail=1 + touch -h -c - >&- || fail=1 +fi + +Exit $fail diff --git a/tests/touch/no-rights.sh b/tests/touch/no-rights.sh new file mode 100755 index 0000000..3cf387d --- /dev/null +++ b/tests/touch/no-rights.sh @@ -0,0 +1,40 @@ +#!/bin/sh +# Make sure touch can update the times on a file that is neither +# readable nor writable. + +# Copyright (C) 1999-2022 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ touch + +# Make sure t2 is newer than t1. +touch -d '2000-01-01 00:00' t1 || framework_failure_ +touch -d '2000-01-02 00:00' t2 || framework_failure_ + +set x $(ls -t t1 t2) +test "$*" = "x t2 t1" || framework_failure_ + + +chmod 0 t1 +touch -d '2000-01-03 00:00' -c t1 || fail=1 + +set x $(ls -t t1 t2) +test "$*" = "x t1 t2" || fail=1 + +# Also test the combination of --no-create and -a. +touch -a --no-create t1 || fail=1 + +Exit $fail diff --git a/tests/touch/not-owner.sh b/tests/touch/not-owner.sh new file mode 100755 index 0000000..fddf4fc --- /dev/null +++ b/tests/touch/not-owner.sh @@ -0,0 +1,55 @@ +#!/bin/sh +# Make sure that touch gives reasonable diagnostics when applied +# to an unwritable directory owned by some other user. + +# Copyright (C) 2003-2022 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ touch + +if env -- test -w /; then + skip_ you have write access to /. +fi + +if env -- test -O / || env -- test -G /; then + skip_ "you own /." +fi + +skip_if_root_ + + +# Before fileutils-4.1, we'd get the following misleading +# diagnostic instead of '...: Permission denied'. +# touch: creating '/': Is a directory +touch / > out 2>&1 && fail=1 + +# On SunOS4, EPERM is 'Not owner'. +# On some *BSD systems it's 'Operation not permitted'. +# On a system where root file system is mounted read-only +# it's 'Read-only file system'. +for msg in 'Not owner' 'Operation not permitted' 'Permission denied' \ + 'Read-only file system'; do + cat > exp <<EOF +touch: setting times of '/': $msg +EOF + + cmp out exp > /dev/null 2>&1 && { match=1; break; } +done +test "$match" = 1 || fail=1 + +test $fail = 1 && compare exp out + +Exit $fail diff --git a/tests/touch/now-owned-by-other.sh b/tests/touch/now-owned-by-other.sh new file mode 100755 index 0000000..6d307a2 --- /dev/null +++ b/tests/touch/now-owned-by-other.sh @@ -0,0 +1,34 @@ +#!/bin/sh +# Demonstrate that "touch -d now writable-but-owned-by-other" works. + +# Copyright (C) 2008-2022 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ touch +require_root_ + +# Create a file owned by root, and writable by $NON_ROOT_USERNAME. +echo > root-owned || framework_failure_ +chgrp +$NON_ROOT_GID . root-owned || framework_failure_ +chmod g+w root-owned + +# Ensure that the current directory is searchable by $NON_ROOT_USERNAME. +chmod g+x . + +chroot --skip-chdir --user=$NON_ROOT_USERNAME / env PATH="$PATH" \ + touch -d now root-owned || fail=1 + +Exit $fail diff --git a/tests/touch/obsolescent.sh b/tests/touch/obsolescent.sh new file mode 100755 index 0000000..86de203 --- /dev/null +++ b/tests/touch/obsolescent.sh @@ -0,0 +1,41 @@ +#!/bin/sh +# Test touch with obsolescent 8- or 10-digit timestamps. + +# Copyright (C) 2000-2022 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ touch + +_POSIX2_VERSION=199209; export _POSIX2_VERSION +POSIXLY_CORRECT=1; export POSIXLY_CORRECT + + +yearstart=01010000 + +for ones in 11111111 1111111111; do + for args in $ones "-- $ones" "$yearstart $ones" "-- $yearstart $ones"; do + touch $args || fail=1 + test -f $ones || fail=1 + test -f $yearstart && fail=1 + rm -f $ones || fail=1 + done +done + +y2000=0101000000 +rm -f $y2000 file || fail=1 +touch $y2000 file && test -f $y2000 && test -f file || fail=1 + +Exit $fail diff --git a/tests/touch/read-only.sh b/tests/touch/read-only.sh new file mode 100755 index 0000000..88b23ff --- /dev/null +++ b/tests/touch/read-only.sh @@ -0,0 +1,31 @@ +#!/bin/sh +# ensure that touch can operate on read-only files + +# Copyright (C) 2005-2022 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ touch +skip_if_root_ + +> read-only || framework_failure_ +chmod 444 read-only || framework_failure_ + + +touch read-only || fail=1 + +touch - 1< read-only 2> /dev/null && { test ! -f - || fail=1; } + +Exit $fail diff --git a/tests/touch/relative.sh b/tests/touch/relative.sh new file mode 100755 index 0000000..6643a1a --- /dev/null +++ b/tests/touch/relative.sh @@ -0,0 +1,38 @@ +#!/bin/sh +# Demonstrate using a combination of --reference and --date to +# set the time of a file back by an arbitrary amount. + +# Copyright (C) 2004-2022 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ touch + +TZ=UTC0 touch --date='2004-01-16 12:00 +0000' f || framework_failure_ + + +# Set times back by 5 days. +touch --ref f --date='-5 days' f || fail=1 + +TZ=UTC0 ls -og --time-style=+%Y-%m-%d f > out.1 || fail=1 +sed 's/ f$//;s/.* //' out.1 > out + +cat <<\EOF > exp || framework_failure_ +2004-01-11 +EOF + +compare exp out || fail=1 + +Exit $fail diff --git a/tests/touch/trailing-slash.sh b/tests/touch/trailing-slash.sh new file mode 100755 index 0000000..9f4b29e --- /dev/null +++ b/tests/touch/trailing-slash.sh @@ -0,0 +1,70 @@ +#!/bin/sh +# Ensure that touch honors trailing slash. + +# Copyright (C) 2009-2022 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ touch + +ln -s nowhere dangling || framework_failure_ +ln -s loop loop || framework_failure_ +touch file || framework_failure_ +ln -s file link1 || framework_failure_ +mkdir dir || framework_failure_ +ln -s dir link2 || framework_failure_ + + +# Trailing slash can only appear on directory or symlink-to-directory. +# Up through coreutils 8.0, Solaris 9 failed these tests. +returns_ 1 touch no-file/ || fail=1 +returns_ 1 touch file/ || fail=1 +returns_ 1 touch dangling/ || fail=1 +returns_ 1 touch loop/ || fail=1 +if returns_ 2 ls link1/; then # darwin allows trailing slash to files + returns_ 1 touch link1/ || fail=1 +fi +touch dir/ || fail=1 + +# -c silences ENOENT, but not ENOTDIR or ELOOP +touch -c no-file/ || fail=1 +returns_ 1 touch -c file/ || fail=1 +touch -c dangling/ || fail=1 +returns_ 1 touch -c loop/ || fail=1 +if returns_ 2 ls link1/; then + returns_ 1 touch -c link1/ || fail=1 +fi +touch -c dir/ || fail=1 +returns_ 1 test -f no-file || fail=1 +returns_ 1 test -f nowhere || fail=1 + +# Trailing slash dereferences a symlink, even with -h. +# mtime is sufficient to show pass (besides, lstat changes atime of +# symlinks and directories under Cygwin 1.5). +touch -d 2009-10-10 -h link2/ || fail=1 +touch -h -r link2/ file || fail=1 +case $(stat --format=%y dir) in + 2009-10-10*) ;; + *) fail=1 ;; +esac +case $(stat --format=%y link2) in + 2009-10-10*) fail=1 ;; +esac +case $(stat --format=%y file) in + 2009-10-10*) ;; + *) fail=1 ;; +esac + +Exit $fail |