1 2failures='' 3ok='' 4 5testcase() { 6 code="$1" 7 expected="$2" 8 oIFS="$IFS" 9 eval "$code" 10 IFS='|' 11 result="$#|$*" 12 IFS="$oIFS" 13 if [ "x$result" = "x$expected" ]; then 14 ok=x$ok 15 else 16 failures=x$failures 17 echo "For $code, expected $expected actual $result" 18 fi 19} 20 21testcase 'shift $#; set -- ""$*' '1|' 22testcase 'shift $#; set -- $*""' '1|' 23testcase 'shift $#; set -- ""$@' '1|' 24testcase 'shift $#; set -- $@""' '1|' 25testcase 'shift $#; set -- """$*"' '1|' 26testcase 'shift $#; set -- "$*"""' '1|' 27testcase 'shift $#; set -- """$@"' '1|' 28testcase 'shift $#; set -- "$@"""' '1|' 29 30test "x$failures" = x 31