tests: factor 350 fail=0 initializations into test-lib.sh
[platform/upstream/coreutils.git] / tests / readlink / can-f
1 #!/bin/sh
2 # tests for canonicalize mode (readlink -f).
3
4 # Copyright (C) 2004, 2006-2009 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 3 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, see <http://www.gnu.org/licenses/>.
18
19 if test "$VERBOSE" = yes; then
20   set -x
21   readlink --version
22 fi
23
24 . $srcdir/test-lib.sh
25
26 pwd=`pwd`
27 my_pwd=$("$abs_top_builddir/src/pwd")
28 tmp=d
29
30 mkdir $tmp || framework_failure
31 cd $tmp || framework_failure
32
33 mkdir subdir removed || framework_failure
34 touch regfile || framework_failure
35
36 ln -s regfile link1 || framework_failure
37 ln -s subdir link2 || framework_failure
38 ln -s missing link3 || framework_failure
39 ln -s subdir/missing link4 || framework_failure
40 ln -s link5 link5 || framework_failure
41
42 cd "$pwd/$tmp/removed" || framework_failure
43
44 # Skip this test if the system doesn't let you remove the working directory.
45 if rmdir ../removed 2>/dev/null; then
46   v=`readlink -e .` && fail=1
47   test -z "$v" || fail=1
48 fi
49
50 cd "$pwd/$tmp" || fail=1
51
52 for p in "" "$pwd/$tmp/"; do
53
54   v=`readlink -f "${p}regfile"` || fail=1
55   test "$v" = "$my_pwd/$tmp/regfile" || fail=1
56
57   v=`readlink -f "${p}./regfile/"` && fail=1
58   test -z "$v" || fail=1
59
60   v=`readlink -f "${p}regfile/more"` && fail=1
61   test -z "$v" || fail=1
62
63   v=`readlink -f "${p}./regfile/more/"` && fail=1
64   test -z "$v" || fail=1
65
66   v=`readlink -f "${p}subdir"` || fail=1
67   test "$v" = "$my_pwd/$tmp/subdir" || fail=1
68
69   v=`readlink -f "${p}./subdir/"` || fail=1
70   test "$v" = "$my_pwd/$tmp/subdir" || fail=1
71
72   v=`readlink -f "${p}subdir/more"` || fail=1
73   test "$v" = "$my_pwd/$tmp/subdir/more" || fail=1
74
75   v=`readlink -f "${p}./subdir/more/"` || fail=1
76   test "$v" = "$my_pwd/$tmp/subdir/more" || fail=1
77
78   v=`readlink -f "${p}missing"` || fail=1
79   test "$v" = "$my_pwd/$tmp/missing" || fail=1
80
81   v=`readlink -f "${p}./missing/"` || fail=1
82   test "$v" = "$my_pwd/$tmp/missing" || fail=1
83
84   v=`readlink -f "${p}missing/more"` && fail=1
85   test -z "$v" || fail=1
86
87   v=`readlink -f "${p}./missing/more/"` && fail=1
88   test -z "$v" || fail=1
89
90   v=`readlink -f "${p}link1"` || fail=1
91   test "$v" = "$my_pwd/$tmp/regfile" || fail=1
92
93   v=`readlink -f "${p}./link1/"` && fail=1
94   test -z "$v" || fail=1
95
96   v=`readlink -f "${p}link1/more"` && fail=1
97   test -z "$v" || fail=1
98
99   v=`readlink -f "${p}./link1/more/"` && fail=1
100   test -z "$v" || fail=1
101
102   v=`readlink -f "${p}link2"` || fail=1
103   test "$v" = "$my_pwd/$tmp/subdir" || fail=1
104
105   v=`readlink -f "${p}./link2/"` || fail=1
106   test "$v" = "$my_pwd/$tmp/subdir" || fail=1
107
108   v=`readlink -f "${p}link2/more"` || fail=1
109   test "$v" = "$my_pwd/$tmp/subdir/more" || fail=1
110
111   v=`readlink -f "${p}./link2/more/"` || fail=1
112   test "$v" = "$my_pwd/$tmp/subdir/more" || fail=1
113
114   v=`readlink -f "${p}link2/more/more2"` && fail=1
115   test -z "$v" || fail=1
116
117   v=`readlink -f "${p}./link2/more/more2/"` && fail=1
118   test -z "$v" || fail=1
119
120   v=`readlink -f "${p}link3"` || fail=1
121   test "$v" = "$my_pwd/$tmp/missing" || fail=1
122
123   v=`readlink -f "${p}./link3/"` || fail=1
124   test "$v" = "$my_pwd/$tmp/missing" || fail=1
125
126   v=`readlink -f "${p}link3/more"` && fail=1
127   test -z "$v" || fail=1
128
129   v=`readlink -f "${p}./link3/more/"` && fail=1
130   test -z "$v" || fail=1
131
132   v=`readlink -f "${p}link4"` || fail=1
133   test "$v" = "$my_pwd/$tmp/subdir/missing" || fail=1
134
135   v=`readlink -f "${p}./link4/"` || fail=1
136   test "$v" = "$my_pwd/$tmp/subdir/missing" || fail=1
137
138   v=`readlink -f "${p}link4/more"` && fail=1
139   test -z "$v" || fail=1
140
141   v=`readlink -f "${p}./link4/more"` && fail=1
142   test -z "$v" || fail=1
143
144   v=`readlink -f "${p}link5"` && fail=1
145   test -z "$v" || fail=1
146
147   v=`readlink -f "${p}./link5/"` && fail=1
148   test -z "$v" || fail=1
149
150   v=`readlink -f "${p}link5/more"` && fail=1
151   test -z "$v" || fail=1
152
153   v=`readlink -f "${p}./link5/more"` && fail=1
154   test -z "$v" || fail=1
155 done
156
157 Exit $fail