1# $FreeBSD: src/tools/regression/bin/sh/expansion/tilde2.0,v 1.1 2010/04/03 22:04:44 jilles Exp $ 2 3HOME=/tmp 4roothome=~root 5if [ "$roothome" = "~root" ]; then 6 echo "~root is not expanded!" 7 exit 2 8fi 9 10testcase() { 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 26testcase 'set -- ${$+~}' '1|/tmp' 27testcase 'set -- ${$+~/}' '1|/tmp/' 28testcase 'set -- ${$+~/foo}' '1|/tmp/foo' 29testcase 'set -- ${$+x~}' '1|x~' 30testcase 'set -- ${$+~root}' "1|$roothome" 31testcase 'set -- ${$+"~"}' '1|~' 32testcase 'set -- ${$+"~/"}' '1|~/' 33testcase 'set -- ${$+"~/foo"}' '1|~/foo' 34testcase 'set -- ${$+"x~"}' '1|x~' 35testcase 'set -- ${$+"~root"}' "1|~root" 36testcase 'set -- "${$+~}"' '1|~' 37testcase 'set -- "${$+~/}"' '1|~/' 38testcase 'set -- "${$+~/foo}"' '1|~/foo' 39testcase 'set -- "${$+x~}"' '1|x~' 40testcase 'set -- "${$+~root}"' "1|~root" 41testcase 'set -- ${HOME#~}' '0|' 42h=~ 43testcase 'set -- "$h"' '1|/tmp' 44f=~/foo 45testcase 'set -- "$f"' '1|/tmp/foo' 46testcase 'set -- ${f#~}' '1|/foo' 47testcase 'set -- ${f#~/}' '1|foo' 48 49ooIFS=$IFS 50IFS=m 51testcase 'set -- ${$+~}' '1|/tmp' 52testcase 'set -- ${$+~/foo}' '1|/tmp/foo' 53testcase 'set -- ${$+$h}' '2|/t|p' 54testcase 'set -- ${HOME#~}' '0|' 55IFS=$ooIFS 56 57t=\~ 58testcase 'set -- ${$+$t}' '1|~' 59r=$(cat <<EOF 60${HOME#~} 61EOF 62) 63testcase 'set -- $r' '0|' 64r=$(cat <<EOF 65${HOME#'~'} 66EOF 67) 68testcase 'set -- $r' '1|/tmp' 69r=$(cat <<EOF 70${t#'~'} 71EOF 72) 73testcase 'set -- $r' '0|' 74r=$(cat <<EOF 75${roothome#~root} 76EOF 77) 78testcase 'set -- $r' '0|' 79r=$(cat <<EOF 80${f#~} 81EOF 82) 83testcase 'set -- $r' '1|/foo' 84r=$(cat <<EOF 85${f#~/} 86EOF 87) 88testcase 'set -- $r' '1|foo' 89 90test "x$failures" = x 91