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