Tizen 2.0 Release
[external/tizen-coreutils.git] / tests / readlink / can-m
1 #!/bin/sh
2 # tests for canonicalize-missing mode (readlink -m).
3
4 # Copyright (C) 2004, 2006, 2007 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 -m .` && 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 -m "${p}regfile"` || break
80   test "$v" = "$my_pwd/$tmp/regfile" || break
81
82   v=`readlink -m "${p}./regfile/"` || break
83   test "$v" = "$my_pwd/$tmp/regfile" || break
84
85   v=`readlink -m "${p}regfile/more"` || break
86   test "$v" = "$my_pwd/$tmp/regfile/more" || break
87
88   v=`readlink -m "${p}./regfile/more/"` || break
89   test "$v" = "$my_pwd/$tmp/regfile/more" || break
90
91   v=`readlink -m "${p}subdir"` || break
92   test "$v" = "$my_pwd/$tmp/subdir" || break
93
94   v=`readlink -m "${p}./subdir/"` || break
95   test "$v" = "$my_pwd/$tmp/subdir" || break
96
97   v=`readlink -m "${p}subdir/more"` || break
98   test "$v" = "$my_pwd/$tmp/subdir/more" || break
99
100   v=`readlink -m "${p}./subdir/more/"` || break
101   test "$v" = "$my_pwd/$tmp/subdir/more" || break
102
103   v=`readlink -m "${p}missing"` || break
104   test "$v" = "$my_pwd/$tmp/missing" || break
105
106   v=`readlink -m "${p}./missing/"` || break
107   test "$v" = "$my_pwd/$tmp/missing" || break
108
109   v=`readlink -m "${p}missing/more"` || break
110   test "$v" = "$my_pwd/$tmp/missing/more" || break
111
112   v=`readlink -m "${p}./missing/more/"` || break
113   test "$v" = "$my_pwd/$tmp/missing/more" || break
114
115   v=`readlink -m "${p}link1"` || break
116   test "$v" = "$my_pwd/$tmp/regfile" || break
117
118   v=`readlink -m "${p}./link1/"` || break
119   test "$v" = "$my_pwd/$tmp/regfile" || break
120
121   v=`readlink -m "${p}link1/more"` || break
122   test "$v" = "$my_pwd/$tmp/regfile/more" || break
123
124   v=`readlink -m "${p}./link1/more/"` || break
125   test "$v" = "$my_pwd/$tmp/regfile/more" || break
126
127   v=`readlink -m "${p}link2"` || break
128   test "$v" = "$my_pwd/$tmp/subdir" || break
129
130   v=`readlink -m "${p}./link2/"` || break
131   test "$v" = "$my_pwd/$tmp/subdir" || break
132
133   v=`readlink -m "${p}link2/more"` || break
134   test "$v" = "$my_pwd/$tmp/subdir/more" || break
135
136   v=`readlink -m "${p}./link2/more/"` || break
137   test "$v" = "$my_pwd/$tmp/subdir/more" || break
138
139   v=`readlink -m "${p}link2/more/more2"` || break
140   test "$v" = "$my_pwd/$tmp/subdir/more/more2" || break
141
142   v=`readlink -m "${p}./link2/more/more2/"` || break
143   test "$v" = "$my_pwd/$tmp/subdir/more/more2" || break
144
145   v=`readlink -m "${p}link3"` || break
146   test "$v" = "$my_pwd/$tmp/missing" || break
147
148   v=`readlink -m "${p}./link3/"` || break
149   test "$v" = "$my_pwd/$tmp/missing" || break
150
151   v=`readlink -m "${p}link3/more"` || break
152   test "$v" = "$my_pwd/$tmp/missing/more" || break
153
154   v=`readlink -m "${p}./link3/more/"` || break
155   test "$v" = "$my_pwd/$tmp/missing/more" || break
156
157   v=`readlink -m "${p}link4"` || break
158   test "$v" = "$my_pwd/$tmp/subdir/missing" || break
159
160   v=`readlink -m "${p}./link4/"` || break
161   test "$v" = "$my_pwd/$tmp/subdir/missing" || break
162
163   v=`readlink -m "${p}link4/more"` || break
164   test "$v" = "$my_pwd/$tmp/subdir/missing/more" || break
165
166   v=`readlink -m "${p}./link4/more/"` || break
167   test "$v" = "$my_pwd/$tmp/subdir/missing/more" || break
168
169   fail=0
170 done
171
172 (exit $fail); exit $fail