Add regression tests for /bin/sh.
[dragonfly.git] / tools / regression / bin / sh / expansion / plus-minus4.0
1 # $FreeBSD: src/tools/regression/bin/sh/expansion/plus-minus4.0,v 1.1 2010/08/08 17:03:23 jilles Exp $
2
3 # These may be a bit unclear in the POSIX spec or the proposed revisions,
4 # and conflict with bash's interpretation, but I think ksh93's interpretation
5 # makes most sense. In particular, it makes no sense to me that single-quotes
6 # must match but are not removed.
7
8 e= q='?' a='*' t=texttext s='ast*que?non' p='/et[c]/' w='a b c' b='{{(#)}}'
9 h='##'
10 failures=''
11 ok=''
12
13 testcase() {
14         code="$1"
15         expected="$2"
16         oIFS="$IFS"
17         eval "$code"
18         IFS='|'
19         result="$#|$*"
20         IFS="$oIFS"
21         if [ "x$result" = "x$expected" ]; then
22                 ok=x$ok
23         else
24                 failures=x$failures
25                 echo "For $code, expected $expected actual $result"
26         fi
27 }
28
29 testcase 'set -- ${e:-'"'"'}'"'"'}'             '1|}'
30 testcase "set -- \${e:-\\'}"                    "1|'"
31 testcase "set -- \${e:-\\'\\'}"                 "1|''"
32 testcase "set -- \"\${e:-'}\""                  "1|'"
33 testcase "set -- \"\${e:-'}'}\""                "1|''}"
34 testcase "set -- \"\${e:-''}\""                 "1|''"
35 testcase 'set -- ${e:-\a}'                      '1|a'
36 testcase 'set -- "${e:-\a}"'                    '1|\a'
37
38 test "x$failures" = x