tests: factor 350 fail=0 initializations into test-lib.sh
[platform/upstream/coreutils.git] / tests / ln / hard-to-sym
1 #!/bin/sh
2 # Tests for ln -L/-P.
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   ln --version
22 fi
23
24 . $srcdir/test-lib.sh
25
26
27 # ===================================================
28 # ensure -s silently overrides -L, -P
29 touch a || framework_failure
30 ln -L -s a symlink1 || fail=1
31 ln -P -s symlink1 symlink2 || fail=1
32 ln -s -L -P symlink2 symlink3 || fail=1
33
34 # ===================================================
35 # ensure that -L follows symlinks, and overrides -P
36 ln -P -L symlink3 hard-to-a || fail=1
37 ls=`ls -lG hard-to-a`x
38 case "$ls" in
39   *'hard-to-ax') ;;
40   *'hard-to-a -> '*x) fail=1 ;;
41   *) framework_failure ;;
42 esac
43
44 # ===================================================
45 # ensure that -P links (or at least duplicates) symlinks, and overrides -L
46 ln -L -P symlink3 hard-to-3 || fail=1
47 ls=`ls -lG hard-to-3`x
48 case "$ls" in
49   *'hard-to-3 -> symlink2x') ;;
50   *'hard-to-3x') fail=1 ;;
51   *'hard-to-3 -> '*x) fail=1 ;;
52   *) framework_failure ;;
53 esac
54
55 # ===================================================
56 # Create a hard link to a dangling symlink.
57 ln -s /no-such-dir || framework_failure
58 ln -L no-such-dir hard-to-dangle 2>err && fail=1
59 case `cat err` in
60   *' accessing `no-such-dir'\':*) ;;
61   *) fail=1 ;;
62 esac
63 ln -P no-such-dir hard-to-dangle || fail=1
64
65 # ===================================================
66 # Create a hard link to a symlink to a directory.
67 mkdir d || framework_failure
68 ln -s d link-to-dir || framework_failure
69 ln -L link-to-dir hard-to-dir-link 2>err && fail=1
70 case `cat err` in
71   *': `link-to-dir'\'': hard link not allowed for directory'*) ;;
72   *) fail=1 ;;
73 esac
74 ln -P link-to-dir/ hard-to-dir-link 2>err && fail=1
75 case `cat err` in
76   *': `link-to-dir/'\'': hard link not allowed for directory'*) ;;
77   *) fail=1 ;;
78 esac
79 ln -P link-to-dir hard-to-dir-link || fail=1
80
81 Exit $fail