xref: /freebsd/bin/sh/tests/expansion/assign1.0 (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
1
2e= q='?' a='*' t=texttext s='ast*que?non' p='/et[c]/' w='a b c' b='{{(#)}}'
3h='##'
4failures=''
5ok=''
6
7testcase() {
8	code="$1"
9	expected="$2"
10	oIFS="$IFS"
11	eval "$code"
12	IFS='|'
13	result="$#|$*"
14	IFS="$oIFS"
15	if [ "x$result" = "x$expected" ]; then
16		ok=x$ok
17	else
18		failures=x$failures
19		echo "For $code, expected $expected actual $result"
20	fi
21}
22
23testcase 'v=; set -- ${v=a b} $v'		'0|'
24testcase 'unset v; set -- ${v=a b} $v'		'4|a|b|a|b'
25testcase 'v=; set -- ${v:=a b} $v'		'4|a|b|a|b'
26testcase 'v=; set -- "${v:=a b}" "$v"'		'2|a b|a b'
27# expect sensible behaviour, although it disagrees with POSIX
28testcase 'v=; set -- ${v:=a\ b} $v'		'4|a|b|a|b'
29testcase 'v=; set -- ${v:=$p} $v'		'2|/etc/|/etc/'
30testcase 'v=; set -- "${v:=$p}" "$v"'		'2|/et[c]/|/et[c]/'
31testcase 'v=; set -- "${v:=a\ b}" "$v"'		'2|a\ b|a\ b'
32testcase 'v=; set -- ${v:="$p"} $v'		'2|/etc/|/etc/'
33# whether $p is quoted or not shouldn't really matter
34testcase 'v=; set -- "${v:="$p"}" "$v"'		'2|/et[c]/|/et[c]/'
35
36test "x$failures" = x
37