]> git.saurik.com Git - apple/shell_cmds.git/blob - sh/tests/expansion/tilde2.0
4f8ed9b491c7c030964a52092ee5ff4bd0bdd88f
[apple/shell_cmds.git] / sh / tests / expansion / tilde2.0
1 # $FreeBSD$
2
3 HOME=/tmp
4 roothome=~root
5 if [ "$roothome" = "~root" ]; then
6 echo "~root is not expanded!"
7 exit 2
8 fi
9
10 testcase() {
11 code="$1"
12 expected="$2"
13 oIFS="$IFS"
14 eval "$code"
15 IFS='|'
16 result="$#|$*"
17 IFS="$oIFS"
18 if [ "x$result" = "x$expected" ]; then
19 ok=x$ok
20 else
21 failures=x$failures
22 echo "For $code, expected $expected actual $result"
23 fi
24 }
25
26 testcase 'set -- ${$+~}' '1|/tmp'
27 testcase 'set -- ${$+~/}' '1|/tmp/'
28 testcase 'set -- ${$+~/foo}' '1|/tmp/foo'
29 testcase 'set -- ${$+x~}' '1|x~'
30 testcase 'set -- ${$+~root}' "1|$roothome"
31 testcase 'set -- ${$+"~"}' '1|~'
32 testcase 'set -- ${$+"~/"}' '1|~/'
33 testcase 'set -- ${$+"~/foo"}' '1|~/foo'
34 testcase 'set -- ${$+"x~"}' '1|x~'
35 testcase 'set -- ${$+"~root"}' "1|~root"
36 testcase 'set -- "${$+~}"' '1|~'
37 testcase 'set -- "${$+~/}"' '1|~/'
38 testcase 'set -- "${$+~/foo}"' '1|~/foo'
39 testcase 'set -- "${$+x~}"' '1|x~'
40 testcase 'set -- "${$+~root}"' "1|~root"
41 testcase 'set -- ${HOME#~}' '0|'
42 h=~
43 testcase 'set -- "$h"' '1|/tmp'
44 f=~/foo
45 testcase 'set -- "$f"' '1|/tmp/foo'
46 testcase 'set -- ${f#~}' '1|/foo'
47 testcase 'set -- ${f#~/}' '1|foo'
48
49 ooIFS=$IFS
50 IFS=m
51 testcase 'set -- ${$+~}' '1|/tmp'
52 testcase 'set -- ${$+~/foo}' '1|/tmp/foo'
53 testcase 'set -- ${$+$h}' '2|/t|p'
54 testcase 'set -- ${HOME#~}' '0|'
55 IFS=$ooIFS
56
57 t=\~
58 testcase 'set -- ${$+$t}' '1|~'
59 r=$(cat <<EOF
60 ${HOME#~}
61 EOF
62 )
63 testcase 'set -- $r' '0|'
64 r=$(cat <<EOF
65 ${HOME#'~'}
66 EOF
67 )
68 testcase 'set -- $r' '1|/tmp'
69 r=$(cat <<EOF
70 ${t#'~'}
71 EOF
72 )
73 testcase 'set -- $r' '0|'
74 r=$(cat <<EOF
75 ${roothome#~root}
76 EOF
77 )
78 testcase 'set -- $r' '0|'
79 r=$(cat <<EOF
80 ${f#~}
81 EOF
82 )
83 testcase 'set -- $r' '1|/foo'
84 r=$(cat <<EOF
85 ${f#~/}
86 EOF
87 )
88 testcase 'set -- $r' '1|foo'
89
90 test "x$failures" = x