param_expand_indicate_error.tests 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # do all of these in subshells since it's supposed to error out
  2. # first try some invalid patterns
  3. #"$THIS_SH" -c 'echo ${?}' -- this is valid as it's the same as $?
  4. "$THIS_SH" -c 'echo ${:?}'
  5. # then some funky ones
  6. # note: bash prints 1 - treats it as "length of $#"
  7. "$THIS_SH" -c 'echo ${#?}'
  8. # bash prints 0
  9. "$THIS_SH" -c 'echo ${#:?}'
  10. # now some valid ones
  11. export msg_unset="unset!"
  12. export msg_null_or_unset="null or unset!"
  13. echo ====
  14. "$THIS_SH" -c 'set --; echo _$1'
  15. "$THIS_SH" -c 'set --; echo _${1?}'
  16. "$THIS_SH" -c 'set --; echo _${1:?}'
  17. "$THIS_SH" -c 'set --; echo _${1?message1}'
  18. "$THIS_SH" -c 'set --; echo _${1:?message1}'
  19. "$THIS_SH" -c 'set --; echo _${1?$msg_unset}'
  20. "$THIS_SH" -c 'set --; echo _${1:?$msg_null_or_unset}'
  21. echo ====
  22. "$THIS_SH" -c 'set -- aaaa; echo _$1'
  23. "$THIS_SH" -c 'set -- aaaa; echo _${1?}'
  24. "$THIS_SH" -c 'set -- aaaa; echo _${1:?}'
  25. "$THIS_SH" -c 'set -- aaaa; echo _${1?word}'
  26. "$THIS_SH" -c 'set -- aaaa; echo _${1:?word}'
  27. "$THIS_SH" -c 'set -- aaaa; echo _${1?$msg_unset}'
  28. "$THIS_SH" -c 'set -- aaaa; echo _${1:?$msg_null_or_unset}'
  29. echo ====
  30. "$THIS_SH" -c 'unset f; echo _$f'
  31. "$THIS_SH" -c 'unset f; echo _${f?}'
  32. "$THIS_SH" -c 'unset f; echo _${f:?}'
  33. "$THIS_SH" -c 'unset f; echo _${f?message3}'
  34. "$THIS_SH" -c 'unset f; echo _${f:?message3}'
  35. "$THIS_SH" -c 'unset f; echo _${f?$msg_unset}'
  36. "$THIS_SH" -c 'unset f; echo _${f:?$msg_null_or_unset}'
  37. echo ====
  38. "$THIS_SH" -c 'f=; echo _$f'
  39. "$THIS_SH" -c 'f=; echo _${f?}'
  40. "$THIS_SH" -c 'f=; echo _${f:?}'
  41. "$THIS_SH" -c 'f=; echo _${f?word}'
  42. "$THIS_SH" -c 'f=; echo _${f:?message4}'
  43. "$THIS_SH" -c 'f=; echo _${f?$msg_unset}'
  44. "$THIS_SH" -c 'f=; echo _${f:?$msg_null_or_unset}'
  45. echo ====
  46. "$THIS_SH" -c 'f=fff; echo _$f'
  47. "$THIS_SH" -c 'f=fff; echo _${f?}'
  48. "$THIS_SH" -c 'f=fff; echo _${f:?}'
  49. "$THIS_SH" -c 'f=fff; echo _${f?word}'
  50. "$THIS_SH" -c 'f=fff; echo _${f:?word}'
  51. "$THIS_SH" -c 'f=fff; echo _${f?$msg_unset}'
  52. "$THIS_SH" -c 'f=fff; echo _${f:?$msg_null_or_unset}'