*** empty log message ***
[coreutils.git] / tests / ln / misc
blob3a9d8d9bf92d553b54111450fa7cd9d1f743067c
1 #!/bin/sh
3 if test "$VERBOSE" = yes; then
4 set -x
5 ln --version
6 fi
8 pwd=`pwd`
9 tmp=t2-ln.$$
10 trap 'status=$?; cd $pwd; rm -rf $tmp && exit $status' 0
11 trap '(exit $?); exit' 1 2 13 15
13 framework_failure=0
14 mkdir $tmp || framework_failure=1
15 cd $tmp || framework_failure=1
17 t=tln-symlink
18 d=tln-subdir
19 ld=tln-symlink-to-subdir
20 f=tln-file
21 fail=0
23 # Create a simple symlink with both source and destination files
24 # in current directory.
25 touch $f || framework_failure=1
26 rm -f $t || framework_failure=1
27 ln -s $f $t || fail=1
28 test -f $t || fail=1
29 rm $t $f
31 # Create a symlink with source file and explicit destination directory/file.
32 touch $f || framework_failure=1
33 rm -rf $d || framework_failure=1
34 mkdir $d || framework_failure=1
35 ln -s ../$f $d/$t || fail=1
36 test -f $d/$t || fail=1
37 rm -rf $d $f
39 # Create a symlink with source file and destination directory.
40 touch $f || framework_failure=1
41 rm -rf $d || framework_failure=1
42 mkdir $d || framework_failure=1
43 ln -s ../$f $d || fail=1
44 test -f $d/$f || fail=1
45 rm -rf $d $f
47 # Make sure we get a failure with existing dest without -f option
48 touch $t || framework_failure=1
49 # FIXME: don't ignore the error message but rather test
50 # it to make sure it's the right one.
51 ln -s $t $t 2> /dev/null && fail=1
52 rm $t
54 # Make sure -sf fails when src and dest are the same
55 touch $t || framework_failure=1
56 ln -sf $t $t 2> /dev/null && fail=1
57 rm $t
59 # Create a symlink with source file and no explicit directory
60 rm -rf $d || framework_failure=1
61 mkdir $d || framework_failure=1
62 touch $d/$f || framework_failure=1
63 ln -s $d/$f || fail=1
64 test -f $f || fail=1
65 rm -rf $d $f
67 # Create a symlink with source file and destination symlink-to-directory.
68 rm -rf $d $f $ld || framework_failure=1
69 touch $f || framework_failure=1
70 mkdir $d || framework_failure=1
71 ln -s $d $ld
72 ln -s ../$f $ld || fail=1
73 test -f $d/$f || fail=1
74 rm -rf $d $f $ld
76 # Create a symlink with source file and destination symlink-to-directory.
77 # BUT use the new --no-dereference option.
78 rm -rf $d $f $ld || framework_failure=1
79 touch $f || framework_failure=1
80 mkdir $d || framework_failure=1
81 ln -s $d $ld
82 af=`pwd`/$f
83 ln --no-dereference -fs $af $ld || fail=1
84 test -f $ld || fail=1
85 rm -rf $d $f $ld
87 # Try to create a symlink with backup where the destination file exists
88 # and the backup file name is a hard link to the destination file.
89 touch a b || framework_failure=1
90 ln b b~ || framework_failure=1
91 ln -f --b=simple a b || fail=1
93 # ===================================================
94 # determine if link(2) follows symlinks on this system
95 touch a || framework_failure=1
96 ln -s a symlink || framework_failure=1
97 ln symlink hard-to-sym > /dev/null 2>&1 || framework_failure=1
98 ls=`ls -lG hard-to-sym`x
99 case "$ls" in
100 *'hard-to-symx') link_follows_symlink=yes ;;
101 *'hard-to-sym -> ax') link_follows_symlink=no ;;
102 *) framework_failure=1 ;;
103 esac
105 if test $link_follows_symlink = no; then
106 # Create a hard link to a dangling symlink.
107 # This is not portable. At least sunos4.1.4 and OpenBSD 2.3 fail this test.
108 # They get this:
109 # ln: cannot create hard link `hard-to-dangle' to `no-such-dir': \
110 # No such file or directory
112 ln -s /no-such-dir || fail=1
113 ln no-such-dir hard-to-dangle > /dev/null 2>&1 || fail=1
115 rm -rf a symlink hard-to-sym hard-to-dangle
116 # ===================================================
118 # Make sure ln can make simple backups.
119 # This was fixed in 4.0.34. Broken in 4.0r.
120 for cmd in ln cp mv ginstall; do
121 rm -rf a x a.orig
122 touch a x || framework_failure=1
123 $cmd --backup=simple --suffix=.orig x a || fail=1
124 test -f a.orig || fail=1
125 done
127 # ===================================================
129 if test $framework_failure = 1; then
130 echo 'failure in testing framework' 1>&2
131 exit 1
134 exit $fail