1#!/bin/sh
2# tests for canonicalize-existing mode (readlink -e).
3
4# Copyright (C) 2004-2023 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 <https://www.gnu.org/licenses/>.
18
19. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
20print_ver_ readlink pwd
21
22pwd=$(pwd)
23my_pwd=$(env pwd -P)
24tmp=d
25
26mkdir $tmp || framework_failure_
27cd $tmp || framework_failure_
28
29mkdir subdir removed || framework_failure_
30touch regfile || framework_failure_
31
32ln -s regfile link1 || framework_failure_
33ln -s subdir link2 || framework_failure_
34ln -s missing link3 || framework_failure_
35ln -s subdir/missing link4 || framework_failure_
36
37cd "$pwd/$tmp/removed" || framework_failure_
38
39# Skip this test if the system doesn't let you remove the working directory.
40if rmdir ../removed 2>/dev/null; then
41  v=$(returns_ 1 readlink -e .) || fail=1
42  test -z "$v" || fail=1
43fi
44
45cd "$pwd/$tmp" || fail=1
46
47for p in "" "$pwd/$tmp/"; do
48
49  v=$(readlink -e "${p}regfile") || fail=1
50  test "$v" = "$my_pwd/$tmp/regfile" || fail=1
51
52  v=$(returns_ 1 readlink -e "${p}./regfile/") || fail=1
53  test -z "$v" || fail=1
54
55  v=$(readlink -e "${p}subdir") || fail=1
56  test "$v" = "$my_pwd/$tmp/subdir" || fail=1
57
58  v=$(readlink -e "${p}./subdir/") || fail=1
59  test "$v" = "$my_pwd/$tmp/subdir" || fail=1
60
61  v=$(returns_ 1 readlink -e "${p}missing") || fail=1
62  test -z "$v" || fail=1
63
64  v=$(returns_ 1 readlink -e "${p}./missing/") || fail=1
65  test -z "$v" || fail=1
66
67  v=$(readlink -e "${p}link1") || fail=1
68  test "$v" = "$my_pwd/$tmp/regfile" || fail=1
69
70  v=$(returns_ 1 readlink -e "${p}./link1/") || fail=1
71  test -z "$v" || fail=1
72
73  v=$(returns_ 1 readlink -e "${p}link1/more") || fail=1
74  test -z "$v" || fail=1
75
76  v=$(readlink -e "${p}link2") || fail=1
77  test "$v" = "$my_pwd/$tmp/subdir" || fail=1
78
79  v=$(readlink -e "${p}./link2/") || fail=1
80  test "$v" = "$my_pwd/$tmp/subdir" || fail=1
81
82  v=$(returns_ 1 readlink -e "${p}link2/more") || fail=1
83  test -z "$v" || fail=1
84
85  v=$(returns_ 1 readlink -e "${p}link3") || fail=1
86  test -z "$v" || fail=1
87
88  v=$(returns_ 1 readlink -e "${p}./link3/") || fail=1
89  test -z "$v" || fail=1
90
91  v=$(returns_ 1 readlink -e "${p}link3/more") || fail=1
92  test -z "$v" || fail=1
93
94  v=$(returns_ 1 readlink -e "${p}link4") || fail=1
95  test -z "$v" || fail=1
96
97  v=$(returns_ 1 readlink -e "${p}./link4/") || fail=1
98  test -z "$v" || fail=1
99
100  v=$(returns_ 1 readlink -e "${p}link4/more") || fail=1
101  test -z "$v" || fail=1
102done
103
104Exit $fail
105