maint: avoid a syntax check failure
[coreutils.git] / tests / touch / empty-file.sh
blobd977493d801a92782a8df25d9e0896f6315514fc
1 #!/bin/sh
2 # Make sure touch can set the mtime on an empty file.
4 # Copyright (C) 1998-2017 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 <http://www.gnu.org/licenses/>.
20 # Volker Borchert reported that touch 3.16r (and presumably all before that)
21 # fails to work on SunOS 4.1.3 with 'most of the recommended patches' when
22 # the empty file is on an NFS-mounted 4.2 volume.
24 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
25 print_ver_ touch
27 DEFAULT_SLEEP_SECONDS=2
28 SLEEP_SECONDS=${SLEEP_SECONDS=$DEFAULT_SLEEP_SECONDS}
31 # FIXME: find writable directories on other partitions
32 # and run the test in those directories, too.
34 : ${TOUCH_DIR_LIST=.}
37 for d in $TOUCH_DIR_LIST; do
38 rm -rf $d/a $d/b $d/c
39 > $d/a || framework_failure_
40 test -f $d/a || framework_failure_
41 > $d/b || framework_failure_
42 test -f $d/b || framework_failure_
43 > $d/c || framework_failure_
44 test -f $d/c || framework_failure_
45 done
47 echo sleeping for $SLEEP_SECONDS seconds...
48 sleep $SLEEP_SECONDS
49 for d in $TOUCH_DIR_LIST; do
50 touch $d/a || fail=1
51 set x $(ls -t $d/a $d/b)
52 test "$*" = "x $d/a $d/b" || fail=1
53 done
55 echo sleeping for $SLEEP_SECONDS seconds...
56 sleep $SLEEP_SECONDS
57 for d in $TOUCH_DIR_LIST; do
58 touch $d/b
59 set x $(ls -t $d/a $d/b)
60 test "$*" = "x $d/b $d/a" || fail=1
62 if touch - 1< $d/c 2> /dev/null; then
63 set x $(ls -t $d/a $d/c)
64 test "$*" = "x $d/c $d/a" || fail=1
67 rm -rf $d/a $d/b $d/c
68 done
70 if test $fail != 0; then
71 cat 1>&2 <<EOF
72 *** This test has just failed. That can happen when the test is run in an
73 *** NFS-mounted directory on a system whose clock is not well synchronized
74 *** with that of the NFS server. If you think that is the reason, set the
75 *** environment variable SLEEP_SECONDS to some number of seconds larger than
76 *** the default of $DEFAULT_SLEEP_SECONDS and rerun the test.
77 EOF
80 Exit $fail