tests: factor 350 fail=0 initializations into test-lib.sh
[platform/upstream/coreutils.git] / tests / ln / misc
1 #!/bin/sh
2 # Miscellaneous tests for "ln".
3
4 # Copyright (C) 1998-2000, 2004, 2006-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 t=tln-symlink
27 d=tln-subdir
28 ld=tln-symlink-to-subdir
29 f=tln-file
30
31 # Create a simple symlink with both source and destination files
32 # in current directory.
33 touch $f || framework_failure
34 rm -f $t || framework_failure
35 ln -s $f $t || fail=1
36 test -f $t || fail=1
37 rm $t $f
38
39 # Create a symlink with source file and explicit destination directory/file.
40 touch $f || framework_failure
41 rm -rf $d || framework_failure
42 mkdir $d || framework_failure
43 ln -s ../$f $d/$t || fail=1
44 test -f $d/$t || fail=1
45 rm -rf $d $f
46
47 # Create a symlink with source file and destination directory.
48 touch $f || framework_failure
49 rm -rf $d || framework_failure
50 mkdir $d || framework_failure
51 ln -s ../$f $d || fail=1
52 test -f $d/$f || fail=1
53 rm -rf $d $f
54
55 # See whether a trailing slash is followed too far.
56 touch $f || framework_failure
57 rm -rf $d || framework_failure
58 mkdir $d $d/$f || framework_failure
59 ln $f $d/ 2> /dev/null && fail=1
60 ln -s $f $d/ 2> /dev/null && fail=1
61 rm -rf $d $f
62
63 # Make sure we get a failure with existing dest without -f option
64 touch $t || framework_failure
65 # FIXME: don't ignore the error message but rather test
66 # it to make sure it's the right one.
67 ln -s $t $t 2> /dev/null && fail=1
68 rm $t
69
70 # Make sure -sf fails when src and dest are the same
71 touch $t || framework_failure
72 ln -sf $t $t 2> /dev/null && fail=1
73 rm $t
74
75 # Create a symlink with source file and no explicit directory
76 rm -rf $d || framework_failure
77 mkdir $d || framework_failure
78 touch $d/$f || framework_failure
79 ln -s $d/$f || fail=1
80 test -f $f || fail=1
81 rm -rf $d $f
82
83 # Create a symlink with source file and destination symlink-to-directory.
84 rm -rf $d $f $ld || framework_failure
85 touch $f || framework_failure
86 mkdir $d || framework_failure
87 ln -s $d $ld
88 ln -s ../$f $ld || fail=1
89 test -f $d/$f || fail=1
90 rm -rf $d $f $ld
91
92 # Create a symlink with source file and destination symlink-to-directory.
93 # BUT use the new --no-dereference option.
94 rm -rf $d $f $ld || framework_failure
95 touch $f || framework_failure
96 mkdir $d || framework_failure
97 ln -s $d $ld
98 af=`pwd`/$f
99 ln --no-dereference -fs "$af" $ld || fail=1
100 test -f $ld || fail=1
101 rm -rf $d $f $ld
102
103 # Try to create a symlink with backup where the destination file exists
104 # and the backup file name is a hard link to the destination file.
105 touch a b || framework_failure
106 ln b b~ || framework_failure
107 ln -f --b=simple a b || fail=1
108
109 # ===================================================
110
111 # Make sure ln can make simple backups.
112 # This was fixed in 4.0.34.  Broken in 4.0r.
113 for cmd in ln cp mv ginstall; do
114   rm -rf a x a.orig
115   touch a x || framework_failure
116   $cmd --backup=simple --suffix=.orig x a || fail=1
117   test -f a.orig || fail=1
118 done
119
120 # ===================================================
121 # With coreutils-5.2.1, this would mistakenly access argv[1][-1].
122 # I'm including it here, in case some day programs like valgrind detect that.
123 # Purify probably would have done so.
124 ln foo '' 2> /dev/null
125
126 # ===================================================
127
128 Exit $fail