xref: /freebsd/bin/sh/tests/expansion/tilde1.0 (revision e9ac41698b2f322d55ccf9da50a3596edb2c1800)
1
2HOME=/tmp
3roothome=~root
4if [ "$roothome" = "~root" ]; then
5	echo "~root is not expanded!"
6	exit 2
7fi
8
9testcase() {
10	code="$1"
11	expected="$2"
12	oIFS="$IFS"
13	eval "$code"
14	IFS='|'
15	result="$#|$*"
16	IFS="$oIFS"
17	if [ "x$result" = "x$expected" ]; then
18		ok=x$ok
19	else
20		failures=x$failures
21		echo "For $code, expected $expected actual $result"
22	fi
23}
24
25testcase 'set -- ~'				'1|/tmp'
26testcase 'set -- ~/foo'				'1|/tmp/foo'
27testcase 'set -- x~'				'1|x~'
28testcase 'set -- ~root'				"1|$roothome"
29h=~
30testcase 'set -- "$h"'				'1|/tmp'
31ooIFS=$IFS
32IFS=m
33testcase 'set -- ~'				'1|/tmp'
34testcase 'set -- ~/foo'				'1|/tmp/foo'
35testcase 'set -- $h'				'2|/t|p'
36IFS=$ooIFS
37t=\~
38testcase 'set -- $t'				'1|~'
39r=$(cat <<EOF
40~
41EOF
42)
43testcase 'set -- $r'				'1|~'
44r=$(cat <<EOF
45${t+~}
46EOF
47)
48testcase 'set -- $r'				'1|~'
49r=$(cat <<EOF
50${t+~/.}
51EOF
52)
53testcase 'set -- $r'				'1|~/.'
54
55test "x$failures" = x
56