1#!/bin/sh
2# Test "ln --relative".
3
4# Copyright (C) 2012-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_ ln
21
22mkdir -p usr/bin || framework_failure_
23mkdir -p usr/lib/foo || framework_failure_
24touch usr/lib/foo/foo || framework_failure_
25
26ln -sr usr/lib/foo/foo usr/bin/foo
27test $(readlink usr/bin/foo) = '../lib/foo/foo' || fail=1
28
29ln -sr usr/bin/foo usr/lib/foo/link-to-foo
30test $(readlink usr/lib/foo/link-to-foo) = 'foo' || fail=1
31
32# Correctly update an existing link, which was broken in <= 8.21
33ln -s dir1/dir2/f existing_link
34ln -srf here existing_link
35test $(readlink existing_link) = 'here' || fail=1
36
37# Demonstrate resolved symlinks used to generate relative links
38# so here, 'web/latest' will not be linked to the intermediate 'latest' link.
39# You'd probably want to use realpath(1) in conjunction
40# with ln(1) without --relative to give greater control.
41ln -s release1 alpha
42ln -s release2 beta
43ln -s beta latest
44mkdir web
45ln -sr latest web/latest
46test $(readlink web/latest) = '../release2' || fail=1
47
48# Expect this to fail with exit status 1, or to succeed quietly (freebsd).
49# Prior to coreutils-8.23, it would segfault.
50ln -sr '' F
51case $? in [01]) ;; *) fail=1;; esac
52
53Exit $fail
54