xref: /openbsd/regress/bin/ln/test_ln.sh (revision f6aab3d8)
1#!/bin/sh
2#
3#	$OpenBSD: test_ln.sh,v 1.2 2020/12/18 18:05:29 bluhm Exp $
4
5set -f
6
7get_dev_ino()
8{
9	stat -f %d:%i "$@"
10}
11
12compare_dirents()
13{
14	opt=
15	if [ $# -eq 3 ]
16	then
17		opt=$1
18		shift
19	fi
20
21	echo Comparing $1 and $2
22	if [ `get_dev_ino $opt $1` != `get_dev_ino $opt $2` ]
23	then
24		echo comparison failed: $1 different than $2
25		exit 1
26	fi
27}
28
29test_ln()
30{
31	[ -e $2 ] || ln $1 $2
32	compare_dirents $1 $2
33}
34
35test_ln_s()
36{
37	[ -h $2 ] || ln -s $1 $2
38	compare_dirents -L $3 $2
39}
40
41test_ln_L()
42{
43	[ -e $2 ] || ln -L $1 $2
44
45	# Need 3rd argument because $2 follows symlink $1
46	compare_dirents $2 $3
47}
48
49test_ln_P()
50{
51	[ -e $2 ] || ln -P $1 $2
52	compare_dirents $1 $2
53}
54
55test_ln   ./links/source ./links/hardlink1
56test_ln_s source ./links/symlink1 ./links/source
57test_ln_L ./links/symlink1 ./links/hardlink2 ./links/source
58test_ln_P ./links/symlink1 ./links/symlink2
59test_ln_s symlink1 ./links/symlink3 ./links/symlink1
60test_ln_L ./links/symlink3 ./links/hardlink3 ./links/source
61err=`LC_ALL=C ln -P ./links/symlink1 ./links/symlink2 2>&1`
62if [ $? -eq 0 ]; then
63	exit 1
64fi
65case $err in
66 *"are identical"*"nothing done"*) ;;
67 *) exit 1;;
68esac
69