Add/fix copyright notices and adjust to latest GNU FDL.
[platform/upstream/coreutils.git] / tests / readlink / can-f
1 #!/bin/sh
2 # tests for canonicalize mode (readlink -f).
3
4 # Copyright (C) 2004 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 2 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, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 # 02110-1301, USA.
20
21 if test "$VERBOSE" = yes; then
22   set -x
23   readlink --version
24 fi
25
26 pwd=`pwd`
27 t0=`echo "$0" |sed 's,.*/,,'`.tmp; tmp=$t0/$$
28 trap 'status=$?; cd $pwd; chmod -R u+rwx $t0; rm -rf $t0 && exit $status' 0
29 trap 'status=$?; (exit $status); exit $status' 1 2 13 15
30
31 fail=1
32 while :; do
33   bindir=`cd ../../src; pwd`|| break
34   my_pwd=`$bindir/pwd` || break
35
36   mkdir -p $tmp || break
37   cd $tmp || break
38
39   mkdir subdir removed || break
40   touch regfile || break
41
42   ln -s regfile link1 || break
43   ln -s subdir link2 || break
44   ln -s missing link3 || break
45   ln -s subdir/missing link4 || break
46
47   fail=0
48   break
49 done
50
51 if test $fail = 1; then
52   echo "$0: failure in testing framework" 1>&2
53   (exit 1); exit 1
54 fi
55
56 fail=1
57 while :; do
58   cd "$pwd/$tmp/removed" || break
59
60   # Skip this test if the system doesn't let you remove the working directory.
61   if rmdir ../removed 2>/dev/null; then
62     v=`readlink -f .` && break
63     test -z "$v" || break
64   fi
65
66   cd "$pwd/$tmp" || break
67
68   fail=0
69   break
70 done
71
72 if test $fail = 1; then
73   (exit $fail); exit $fail
74 fi
75
76 for p in "" "$pwd/$tmp/"; do
77   fail=1
78
79   v=`readlink -f ${p}regfile` || break
80   test "$v" = "$my_pwd/$tmp/regfile" || break
81
82   v=`readlink -f ${p}./regfile/` && break
83   test -z "$v" || break
84
85   v=`readlink -f ${p}regfile/more` && break
86   test -z "$v" || break
87
88   v=`readlink -f ${p}./regfile/more/` && break
89   test -z "$v" || break
90
91   v=`readlink -f ${p}subdir` || break
92   test "$v" = "$my_pwd/$tmp/subdir" || break
93
94   v=`readlink -f ${p}./subdir/` || break
95   test "$v" = "$my_pwd/$tmp/subdir" || break
96
97   v=`readlink -f ${p}subdir/more` || break
98   test "$v" = "$my_pwd/$tmp/subdir/more" || break
99
100   v=`readlink -f ${p}./subdir/more/` && break
101   test -z "$v" || break
102
103   v=`readlink -f ${p}missing` || break
104   test "$v" = "$my_pwd/$tmp/missing" || break
105
106   v=`readlink -f ${p}./missing/` && break
107   test -z "$v" || break
108
109   v=`readlink -f ${p}missing/more` && break
110   test -z "$v" || break
111
112   v=`readlink -f ${p}./missing/more/` && break
113   test -z "$v" || break
114
115   v=`readlink -f ${p}link1` || break
116   test "$v" = "$my_pwd/$tmp/regfile" || break
117
118   v=`readlink -f ${p}./link1/` && break
119   test -z "$v" || break
120
121   v=`readlink -f ${p}link1/more` && break
122   test -z "$v" || break
123
124   v=`readlink -f ${p}./link1/more/` && break
125   test -z "$v" || break
126
127   v=`readlink -f ${p}link2` || break
128   test "$v" = "$my_pwd/$tmp/subdir" || break
129
130   v=`readlink -f ${p}./link2/` || break
131   test "$v" = "$my_pwd/$tmp/subdir" || break
132
133   v=`readlink -f ${p}link2/more` || break
134   test "$v" = "$my_pwd/$tmp/subdir/more" || break
135
136   v=`readlink -f ${p}./link2/more/` && break
137   test -z "$v" || break
138
139   v=`readlink -f ${p}link2/more/more2` && break
140   test -z "$v" || break
141
142   v=`readlink -f ${p}./link2/more/more2/` && break
143   test -z "$v" || break
144
145   v=`readlink -f ${p}link3` || break
146   test "$v" = "$my_pwd/$tmp/missing" || break
147
148   v=`readlink -f ${p}./link3/` && break
149   test -z "$v" || break
150
151   v=`readlink -f ${p}link3/more` && break
152   test -z "$v" || break
153
154   v=`readlink -f ${p}./link3/more/` && break
155   test -z "$v" || break
156
157   v=`readlink -f ${p}link4` || break
158   test "$v" = "$my_pwd/$tmp/subdir/missing" || break
159
160   v=`readlink -f ${p}./link4/` && break
161   test -z "$v" || break
162
163   v=`readlink -f ${p}link4/more` && break
164   test -z "$v" || break
165
166   fail=0
167 done
168
169 (exit $fail); exit $fail