c9092b258930a2b6c618b01e6f94bbd37a74b4c4
[platform/upstream/coreutils.git] / tests / touch / empty-file
1 #!/bin/sh
2 # Make sure touch can set the mtime on an empty file.
3 # Volker Borchert reported that touch 3.16r (and presumably all before that)
4 # fails to work on SunOS 4.1.3 with `most of the recommended patches' when
5 # the empty file is on an NFS-mounted 4.2 volume.
6
7 if test "$VERBOSE" = yes; then
8   set -x
9   touch --version
10 fi
11
12 DEFAULT_SLEEP_SECONDS=2
13 SLEEP_SECONDS=${SLEEP_SECONDS=$DEFAULT_SLEEP_SECONDS}
14
15 fail=0
16
17 # FIXME: find writable directories on other partitions
18 # and run the test in those directories, too.
19
20 : ${TOUCH_DIR_LIST=.}
21
22 framework_failure=0
23
24 for d in $TOUCH_DIR_LIST; do
25   rm -rf $d/a $d/b $d/c
26   > $d/a || framework_failure=1
27   test -f $d/a || framework_failure=1
28   > $d/b || framework_failure=1
29   test -f $d/b || framework_failure=1
30   > $d/c || framework_failure=1
31   test -f $d/c || framework_failure=1
32 done
33
34 if test $framework_failure = 1; then
35   echo 'failure in testing framework'
36   exit 1
37 fi
38
39 echo sleeping for $SLEEP_SECONDS seconds...
40 sleep $SLEEP_SECONDS
41 for d in $TOUCH_DIR_LIST; do
42   touch $d/a || fail=1
43   set x `ls -t $d/a $d/b`
44   test "$*" = "x $d/a $d/b" || fail=1
45 done
46
47 echo sleeping for $SLEEP_SECONDS seconds...
48 sleep $SLEEP_SECONDS
49 for d in $TOUCH_DIR_LIST; do
50   touch $d/b
51   set x `ls -t $d/a $d/b`
52   test "$*" = "x $d/b $d/a" || fail=1
53
54   if touch - 1< $d/c 2> /dev/null; then
55     set x `ls -t $d/a $d/c`
56     test "$*" = "x $d/c $d/a" || fail=1
57   fi
58
59   rm -rf $d/a $d/b $d/c
60 done
61
62 if test $fail != 0; then
63   cat 1>&2 <<EOF
64 *** This test has just failed.  That can happen when the test is run in an
65 *** NFS-mounted directory on a system whose clock is not well synchronized
66 *** with that of the NFS server.  If you think that is the reason, set the
67 *** environment variable SLEEP_SECONDS to some number of seconds larger than
68 *** the default of $DEFAULT_SLEEP_SECONDS and rerun the test.
69 EOF
70 fi
71
72 exit $fail