tests: factor 350 fail=0 initializations into test-lib.sh
[platform/upstream/coreutils.git] / tests / touch / trailing-slash
1 #!/bin/sh
2 # Ensure that touch honors trailing slash.
3
4 # Copyright (C) 2009 Free Software Foundation, Inc.
5
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.
10
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.
15
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/>.
18
19 if test "$VERBOSE" = yes; then
20   set -x
21   touch --version
22 fi
23
24 . $srcdir/test-lib.sh
25
26 ln -s nowhere dangling || framework_failure
27 ln -s loop loop || framework_failure
28 touch file || framework_failure
29 ln -s file link1 || framework_failure
30 mkdir dir || framework_failure
31 ln -s dir link2 || framework_failure
32
33
34 # Trailing slash can only appear on directory or symlink-to-directory.
35 # Up through coreutils 8.0, Solaris 9 failed these tests.
36 touch no-file/ && fail=1
37 touch file/ && fail=1
38 touch dangling/ && fail=1
39 touch loop/ && fail=1
40 touch link1/ && fail=1
41 touch dir/ || fail=1
42
43 # -c silences ENOENT, but not ENOTDIR or ELOOP
44 touch -c no-file/ || fail=1
45 touch -c file/ && fail=1
46 touch -c dangling/ || fail=1
47 touch -c loop/ && fail=1
48 touch -c link1/ && fail=1
49 touch -c dir/ || fail=1
50 test -f no-file && fail=1
51 test -f nowhere && fail=1
52
53 # Trailing slash dereferences a symlink, even with -h.
54 # mtime is sufficient to show pass (besides, lstat changes atime of
55 # symlinks and directories under Cygwin 1.5).
56 touch -d 2009-10-10 -h link2/ || fail=1
57 touch -h -r link2/ file || fail=1
58 case `stat --format=%y dir` in
59   2009-10-10*) ;;
60   *) fail=1 ;;
61 esac
62 case `stat --format=%y link2` in
63   2009-10-10*) fail=1 ;;
64 esac
65 case `stat --format=%y file` in
66   2009-10-10*) ;;
67   *) fail=1 ;;
68 esac
69
70 Exit $fail