* src/dircolors.hin: Add .flv. Move .svgz to "image formats".
[coreutils.git] / tests / ln / misc
blobbe7efb036f6313e3b7dc4d1528356a52c2cd3894
1 #!/bin/sh
2 # Miscellaneous tests for "ln".
4 # Copyright (C) 1998-2000, 2004, 2006-2007 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/>.
19 if test "$VERBOSE" = yes; then
20 set -x
21 ln --version
24 . $srcdir/../test-lib.sh
26 t=tln-symlink
27 d=tln-subdir
28 ld=tln-symlink-to-subdir
29 f=tln-file
30 fail=0
32 # Create a simple symlink with both source and destination files
33 # in current directory.
34 touch $f || framework_failure
35 rm -f $t || framework_failure
36 ln -s $f $t || fail=1
37 test -f $t || fail=1
38 rm $t $f
40 # Create a symlink with source file and explicit destination directory/file.
41 touch $f || framework_failure
42 rm -rf $d || framework_failure
43 mkdir $d || framework_failure
44 ln -s ../$f $d/$t || fail=1
45 test -f $d/$t || fail=1
46 rm -rf $d $f
48 # Create a symlink with source file and destination directory.
49 touch $f || framework_failure
50 rm -rf $d || framework_failure
51 mkdir $d || framework_failure
52 ln -s ../$f $d || fail=1
53 test -f $d/$f || fail=1
54 rm -rf $d $f
56 # See whether a trailing slash is followed too far.
57 touch $f || framework_failure
58 rm -rf $d || framework_failure
59 mkdir $d $d/$f || framework_failure
60 ln $f $d/ 2> /dev/null && fail=1
61 ln -s $f $d/ 2> /dev/null && fail=1
62 rm -rf $d $f
64 # Make sure we get a failure with existing dest without -f option
65 touch $t || framework_failure
66 # FIXME: don't ignore the error message but rather test
67 # it to make sure it's the right one.
68 ln -s $t $t 2> /dev/null && fail=1
69 rm $t
71 # Make sure -sf fails when src and dest are the same
72 touch $t || framework_failure
73 ln -sf $t $t 2> /dev/null && fail=1
74 rm $t
76 # Create a symlink with source file and no explicit directory
77 rm -rf $d || framework_failure
78 mkdir $d || framework_failure
79 touch $d/$f || framework_failure
80 ln -s $d/$f || fail=1
81 test -f $f || fail=1
82 rm -rf $d $f
84 # Create a symlink with source file and destination symlink-to-directory.
85 rm -rf $d $f $ld || framework_failure
86 touch $f || framework_failure
87 mkdir $d || framework_failure
88 ln -s $d $ld
89 ln -s ../$f $ld || fail=1
90 test -f $d/$f || fail=1
91 rm -rf $d $f $ld
93 # Create a symlink with source file and destination symlink-to-directory.
94 # BUT use the new --no-dereference option.
95 rm -rf $d $f $ld || framework_failure
96 touch $f || framework_failure
97 mkdir $d || framework_failure
98 ln -s $d $ld
99 af=`pwd`/$f
100 ln --no-dereference -fs "$af" $ld || fail=1
101 test -f $ld || fail=1
102 rm -rf $d $f $ld
104 # Try to create a symlink with backup where the destination file exists
105 # and the backup file name is a hard link to the destination file.
106 touch a b || framework_failure
107 ln b b~ || framework_failure
108 ln -f --b=simple a b || fail=1
110 # ===================================================
111 # determine if link(2) follows symlinks on this system
112 touch a || framework_failure
113 ln -s a symlink || framework_failure
114 ln symlink hard-to-sym > /dev/null 2>&1 || framework_failure
115 ls=`ls -lG hard-to-sym`x
116 case "$ls" in
117 *'hard-to-symx') link_follows_symlink=yes ;;
118 *'hard-to-sym -> ax') link_follows_symlink=no ;;
119 *) framework_failure ;;
120 esac
122 if test $link_follows_symlink = no; then
123 # Create a hard link to a dangling symlink.
124 # This is not portable. At least sunos4.1.4 and OpenBSD 2.3 fail this test.
125 # They get this:
126 # ln: cannot create hard link `hard-to-dangle' to `no-such-dir': \
127 # No such file or directory
129 ln -s /no-such-dir || fail=1
130 ln no-such-dir hard-to-dangle > /dev/null 2>&1 || fail=1
132 rm -rf a symlink hard-to-sym hard-to-dangle
133 # ===================================================
135 # Make sure ln can make simple backups.
136 # This was fixed in 4.0.34. Broken in 4.0r.
137 for cmd in ln cp mv ginstall; do
138 rm -rf a x a.orig
139 touch a x || framework_failure
140 $cmd --backup=simple --suffix=.orig x a || fail=1
141 test -f a.orig || fail=1
142 done
144 # ===================================================
145 # With coreutils-5.2.1, this would mistakenly access argv[1][-1].
146 # I'm including it here, in case some day programs like valgrind detect that.
147 # Purify probably would have done so.
148 ln foo '' 2> /dev/null
150 # ===================================================
152 (exit $fail); exit $fail