tests: factor 350 fail=0 initializations into test-lib.sh
[platform/upstream/coreutils.git] / tests / readlink / can-e
1 #!/bin/sh
2 # tests for canonicalize-existing mode (readlink -e).
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
41 cd "$pwd/$tmp/removed" || framework_failure
42
43 # Skip this test if the system doesn't let you remove the working directory.
44 if rmdir ../removed 2>/dev/null; then
45   v=`readlink -e .` && fail=1
46   test -z "$v" || fail=1
47 fi
48
49 cd "$pwd/$tmp" || fail=1
50
51 for p in "" "$pwd/$tmp/"; do
52
53   v=`readlink -e "${p}regfile"` || fail=1
54   test "$v" = "$my_pwd/$tmp/regfile" || fail=1
55
56   v=`readlink -e "${p}./regfile/"` && fail=1
57   test -z "$v" || fail=1
58
59   v=`readlink -e "${p}subdir"` || fail=1
60   test "$v" = "$my_pwd/$tmp/subdir" || fail=1
61
62   v=`readlink -e "${p}./subdir/"` || fail=1
63   test "$v" = "$my_pwd/$tmp/subdir" || fail=1
64
65   v=`readlink -e "${p}missing"` && fail=1
66   test -z "$v" || fail=1
67
68   v=`readlink -e "${p}./missing/"` && fail=1
69   test -z "$v" || fail=1
70
71   v=`readlink -e "${p}link1"` || fail=1
72   test "$v" = "$my_pwd/$tmp/regfile" || fail=1
73
74   v=`readlink -e "${p}./link1/"` && fail=1
75   test -z "$v" || fail=1
76
77   v=`readlink -e "${p}link1/more"` && fail=1
78   test -z "$v" || fail=1
79
80   v=`readlink -e "${p}link2"` || fail=1
81   test "$v" = "$my_pwd/$tmp/subdir" || fail=1
82
83   v=`readlink -e "${p}./link2/"` || fail=1
84   test "$v" = "$my_pwd/$tmp/subdir" || fail=1
85
86   v=`readlink -e "${p}link2/more"` && fail=1
87   test -z "$v" || fail=1
88
89   v=`readlink -e "${p}link3"` && fail=1
90   test -z "$v" || fail=1
91
92   v=`readlink -e "${p}./link3/"` && fail=1
93   test -z "$v" || fail=1
94
95   v=`readlink -e "${p}link3/more"` && fail=1
96   test -z "$v" || fail=1
97
98   v=`readlink -e "${p}link4"` && fail=1
99   test -z "$v" || fail=1
100
101   v=`readlink -e "${p}./link4/"` && fail=1
102   test -z "$v" || fail=1
103
104   v=`readlink -e "${p}link4/more"` && fail=1
105   test -z "$v" || fail=1
106 done
107
108 Exit $fail