xref: /freebsd/bin/sh/tests/expansion/cmdsubst6.0 (revision 0b3105a37d7adcadcb720112fed4dc4e8040be99)
1# $FreeBSD$
2# This tests if the cmdsubst optimization is still used if possible.
3
4failures=''
5ok=''
6
7testcase() {
8	code="$1"
9
10	unset v
11	eval "pid=\$(dummy=$code echo \$(\$SH -c echo\ \\\$PPID))"
12
13	if [ "$pid" = "$$" ]; then
14		ok=x$ok
15	else
16		failures=x$failures
17		echo "Failure for $code"
18	fi
19}
20
21unset v
22w=1
23testcase '$w'
24testcase '1${w+1}'
25testcase '1${w-1}'
26testcase '1${v+1}'
27testcase '1${v-1}'
28testcase '1${w:+1}'
29testcase '1${w:-1}'
30testcase '1${v:+1}'
31testcase '1${v:-1}'
32testcase '${w?}'
33testcase '${w:?}'
34testcase '${w#x}'
35testcase '${w##x}'
36testcase '${w%x}'
37testcase '${w%%x}'
38
39testcase '$((w))'
40testcase '$(((w+4)*2/3))'
41testcase '$((w==1))'
42testcase '$((w>=0 && w<=5 && w!=2))'
43testcase '$((${#w}))'
44testcase '$((${#IFS}))'
45testcase '$((${#w}>=1))'
46testcase '$(($$))'
47testcase '$(($#))'
48testcase '$(($?))'
49
50testcase '$(: $((w=4)))'
51testcase '$(: ${v=2})'
52
53test "x$failures" = x
54