subshell.sh 882 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/bin/sh
  2. source $(dirname "$0")/test-commons.inc
  3. setopt --verbose
  4. rm -rf /tmp/shell-test 2> /dev/null
  5. mkdir -p /tmp/shell-test
  6. pushd /tmp/shell-test
  7. # Simple sequence (grouping)
  8. { echo test > testfile }
  9. if not test "$(cat testfile)" = "test" {
  10. fail cannot write to file in subshell
  11. }
  12. # Simple sequence - many commands
  13. { echo test1 > testfile; echo test2 > testfile }
  14. if not test "$(cat testfile)" = "test2" {
  15. fail cannot write to file in subshell 2
  16. }
  17. # Does it exit with the last exit code?
  18. { test -z "a" }
  19. exitcode=$?
  20. if not test "$exitcode" -eq 1 {
  21. fail exits with $exitcode when it should exit with 1
  22. }
  23. { test -z "a" || echo test }
  24. exitcode=$?
  25. if not test "$exitcode" -eq 0 {
  26. fail exits with $exitcode when it should exit with 0
  27. }
  28. popd
  29. rm -rf /tmp/shell-test
  30. echo PASS