]>
Commit | Line | Data |
---|---|---|
deb63bfb | 1 | # $FreeBSD: head/bin/sh/tests/expansion/plus-minus1.0 216738 2010-12-27 15:57:41Z emaste $ |
71aad674 A |
2 | |
3 | e= q='?' a='*' t=texttext s='ast*que?non' p='/et[c]/' w='a b c' b='{{(#)}}' | |
4 | h='##' | |
5 | failures='' | |
6 | ok='' | |
7 | ||
8 | testcase() { | |
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 | ||
24 | testcase 'set -- a b' '2|a|b' | |
25 | testcase 'set --' '0|' | |
26 | testcase 'set -- ${e}' '0|' | |
27 | testcase 'set -- "${e}"' '1|' | |
28 | ||
29 | testcase 'set -- $p' '1|/etc/' | |
30 | testcase 'set -- "$p"' '1|/et[c]/' | |
31 | testcase 'set -- ${s+$p}' '1|/etc/' | |
32 | testcase 'set -- "${s+$p}"' '1|/et[c]/' | |
33 | testcase 'set -- ${s+"$p"}' '1|/et[c]/' | |
34 | # Dquotes in dquotes is undefined for Bourne shell operators | |
35 | #testcase 'set -- "${s+"$p"}"' '1|/et[c]/' | |
36 | testcase 'set -- ${e:-$p}' '1|/etc/' | |
37 | testcase 'set -- "${e:-$p}"' '1|/et[c]/' | |
38 | testcase 'set -- ${e:-"$p"}' '1|/et[c]/' | |
39 | # Dquotes in dquotes is undefined for Bourne shell operators | |
40 | #testcase 'set -- "${e:-"$p"}"' '1|/et[c]/' | |
41 | testcase 'set -- ${e:+"$e"}' '0|' | |
42 | testcase 'set -- ${e:+$w"$e"}' '0|' | |
43 | testcase 'set -- ${w:+"$w"}' '1|a b c' | |
44 | testcase 'set -- ${w:+$w"$w"}' '3|a|b|ca b c' | |
45 | ||
46 | testcase 'set -- "${s+a b}"' '1|a b' | |
47 | testcase 'set -- "${e:-a b}"' '1|a b' | |
48 | testcase 'set -- ${e:-\}}' '1|}' | |
49 | testcase 'set -- ${e:+{}}' '1|}' | |
50 | testcase 'set -- "${e:+{}}"' '1|}' | |
51 | ||
52 | testcase 'set -- ${e+x}${e+x}' '1|xx' | |
53 | testcase 'set -- "${e+x}"${e+x}' '1|xx' | |
54 | testcase 'set -- ${e+x}"${e+x}"' '1|xx' | |
55 | testcase 'set -- "${e+x}${e+x}"' '1|xx' | |
56 | testcase 'set -- "${e+x}""${e+x}"' '1|xx' | |
57 | ||
58 | testcase 'set -- ${e:-${e:-$p}}' '1|/etc/' | |
59 | testcase 'set -- "${e:-${e:-$p}}"' '1|/et[c]/' | |
60 | testcase 'set -- ${e:-"${e:-$p}"}' '1|/et[c]/' | |
61 | testcase 'set -- ${e:-${e:-"$p"}}' '1|/et[c]/' | |
62 | testcase 'set -- ${e:-${e:-${e:-$w}}}' '3|a|b|c' | |
63 | testcase 'set -- ${e:-${e:-${e:-"$w"}}}' '1|a b c' | |
64 | testcase 'set -- ${e:-${e:-"${e:-$w}"}}' '1|a b c' | |
65 | testcase 'set -- ${e:-"${e:-${e:-$w}}"}' '1|a b c' | |
66 | testcase 'set -- "${e:-${e:-${e:-$w}}}"' '1|a b c' | |
67 | ||
68 | testcase 'shift $#; set -- ${1+"$@"}' '0|' | |
69 | testcase 'set -- ""; set -- ${1+"$@"}' '1|' | |
70 | testcase 'set -- "" a; set -- ${1+"$@"}' '2||a' | |
71 | testcase 'set -- a ""; set -- ${1+"$@"}' '2|a|' | |
72 | testcase 'set -- a b; set -- ${1+"$@"}' '2|a|b' | |
73 | testcase 'set -- a\ b; set -- ${1+"$@"}' '1|a b' | |
74 | testcase 'set -- " " ""; set -- ${1+"$@"}' '2| |' | |
75 | ||
76 | test "x$failures" = x |