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