]> git.saurik.com Git - apple/shell_cmds.git/blob - sh/tests/expansion/cmdsubst6.0
shell_cmds-207.11.1.tar.gz
[apple/shell_cmds.git] / sh / tests / expansion / cmdsubst6.0
1 # $FreeBSD: head/bin/sh/tests/expansion/cmdsubst6.0 216763 2010-12-28 14:58:08Z jilles $
2 # This tests if the cmdsubst optimization is still used if possible.
3
4 failures=''
5 ok=''
6
7 testcase() {
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
21 unset v
22 w=1
23 testcase '$w'
24 testcase '1${w+1}'
25 testcase '1${w-1}'
26 testcase '1${v+1}'
27 testcase '1${v-1}'
28 testcase '1${w:+1}'
29 testcase '1${w:-1}'
30 testcase '1${v:+1}'
31 testcase '1${v:-1}'
32 testcase '${w?}'
33 testcase '${w:?}'
34 testcase '${w#x}'
35 testcase '${w##x}'
36 testcase '${w%x}'
37 testcase '${w%%x}'
38
39 testcase '$((w))'
40 testcase '$(((w+4)*2/3))'
41 testcase '$((w==1))'
42 testcase '$((w>=0 && w<=5 && w!=2))'
43 testcase '$((${#w}))'
44 testcase '$((${#IFS}))'
45 testcase '$((${#w}>=1))'
46 testcase '$(($$))'
47 testcase '$(($#))'
48 testcase '$(($?))'
49
50 testcase '$(: $((w=4)))'
51 testcase '$(: ${v=2})'
52
53 test "x$failures" = x