valid.sh 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #!/bin/sh
  2. echo "Not running Shell-valid as it has a high failure rate on target #7336"
  3. echo PASS
  4. exit 0
  5. source $(dirname "$0")/test-commons.inc
  6. # Are comments ignored?
  7. # Sanity check: can we do && and || ?
  8. true || exit 2
  9. false
  10. # Can we chain &&'s?
  11. false && exit 2 && fail "can't chain &&'s"
  12. # Proper precedence between &&'s and ||'s
  13. false && exit 2 || true && false && fail Invalid precedence between '&&' and '||'
  14. # Sanity check: can we pass arguments to 'test'?
  15. if not test yes = yes { exit 2 }
  16. # Sanity check: can we use $(command)?
  17. if not test "$(echo yes)" = yes { exit 2 }
  18. # Redirections.
  19. if not test -z "$(echo foo > /dev/null)" { fail direct path redirection }
  20. if not test -z "$(echo foo 2> /dev/null 1>&2)" { fail indirect redirection }
  21. if not test -n "$(echo foo 2> /dev/null)" { fail fds interfere with each other }
  22. # Argument unpack
  23. if not test "$(echo (yes))" = yes { fail arguments inside bare lists }
  24. if not test "$(echo (no)() yes)" = yes { fail arguments inside juxtaposition: empty }
  25. if not test "$(echo (y)(es))" = yes { fail arguments inside juxtaposition: list }
  26. if not test "$(echo "y"es)" = yes { fail arguments inside juxtaposition: string }
  27. # String substitution
  28. foo=yes
  29. if not test "$(echo $foo)" = yes { fail simple string var lookup }
  30. if not test "$(echo "$foo")" = yes { fail stringified string var lookup }
  31. # List substitution
  32. foo=(yes)
  33. # Static lookup, as list
  34. if not test "$(echo $foo)" = yes { fail simple list var lookup }
  35. # Static lookup, stringified
  36. if not test "$(echo "$foo")" = yes { fail stringified list var lookup }
  37. # Dynamic lookup through static expression
  38. if not test "$(echo $'foo')" = yes { fail dynamic lookup through static exp }
  39. # Dynamic lookup through dynamic expression
  40. ref_to_foo=foo
  41. if not test "$(echo $"$ref_to_foo")" = yes { fail dynamic lookup through dynamic exp }
  42. # More redirections
  43. echo test > /tmp/sh-test
  44. if not test "$(cat /tmp/sh-test)" = test { fail simple path redirect }
  45. rm /tmp/sh-test
  46. # 'brace' expansions
  47. if not test "$(echo x(yes no))" = "xyes xno" { fail simple juxtaposition expansion }
  48. if not test "$(echo (y n)(es o))" = "yes yo nes no" { fail list-list juxtaposition expansion }
  49. if not test "$(echo ()(foo bar baz))" = "" { fail empty expansion }
  50. # Variables inside commands
  51. to_devnull=(>/dev/null)
  52. if not test "$(echo hewwo $to_devnull)" = "" { fail variable containing simple command }
  53. word_count=(() | wc -w)
  54. if not test "$(echo well hello friends $word_count)" -eq 3 { fail variable containing pipeline }
  55. # Globs
  56. rm -fr /tmp/sh-test 2> /dev/null
  57. mkdir -p /tmp/sh-test
  58. pushd /tmp/sh-test
  59. touch (a b c)(d e f)
  60. if not test "$(echo a*)" = "ad ae af" { fail '*' glob expansion }
  61. if not test "$(echo a?)" = "ad ae af" { fail '?' glob expansion }
  62. glob_in_var='*'
  63. if not test "$(echo $glob_in_var)" = '*' { fail substituted string acts as glob }
  64. if not test "$(echo (a*))" = "ad ae af" { fail globs in lists resolve wrong }
  65. if not test "$(echo x(a*))" = "xad xae xaf" { fail globs in lists do not resolve to lists }
  66. if not test "$(echo "foo"a*)" = "fooad fooae fooaf" { fail globs join to dquoted strings }
  67. popd
  68. rm -fr /tmp/sh-test
  69. # Setopt
  70. setopt --inline_exec_keep_empty_segments
  71. if not test "$(echo -n "a\n\nb")" = "a b" { fail inline_exec_keep_empty_segments has no effect }
  72. setopt --no_inline_exec_keep_empty_segments
  73. if not test "$(echo -n "a\n\nb")" = "a b" { fail cannot unset inline_exec_keep_empty_segments }
  74. echo PASS