| 1 | #!/usr/bin/env bash
|
| 2 | #
|
| 3 | # This should be a spec test, but the framework runs like
|
| 4 | #
|
| 5 | # echo $code | $SH
|
| 6 | #
|
| 7 | # which seems to interfere with nohup.
|
| 8 | #
|
| 9 | # Usage:
|
| 10 | # test/nohup.sh <function name>
|
| 11 |
|
| 12 | set -o nounset
|
| 13 | set -o pipefail
|
| 14 | set -o errexit
|
| 15 |
|
| 16 | source devtools/run-task.sh
|
| 17 | source test/common.sh # run-test-funcs
|
| 18 |
|
| 19 | run-shell() {
|
| 20 | local sh=$1
|
| 21 | shift
|
| 22 |
|
| 23 | rm -v nohup.out || true
|
| 24 |
|
| 25 | set +o errexit
|
| 26 | nohup $sh "$@"
|
| 27 | echo " => $sh returned $?"
|
| 28 | set -o errexit
|
| 29 |
|
| 30 | if test -f nohup.out; then
|
| 31 | cat nohup.out
|
| 32 | else
|
| 33 | # happens in CI ? I thought we run with docker -t.
|
| 34 | echo "nohup.out doesn't exist"
|
| 35 | fi
|
| 36 |
|
| 37 | echo
|
| 38 |
|
| 39 | }
|
| 40 |
|
| 41 | compare-shells() {
|
| 42 | for sh in dash bash mksh bin/osh; do
|
| 43 | echo " ----- "
|
| 44 | echo " $sh"
|
| 45 | echo
|
| 46 |
|
| 47 | run-shell $sh "$@"
|
| 48 |
|
| 49 | done
|
| 50 | }
|
| 51 |
|
| 52 | test-echo() {
|
| 53 | compare-shells -c 'echo hi; echo status=$?'
|
| 54 | }
|
| 55 |
|
| 56 | # TODO: osh needs location info for this one
|
| 57 | test-read() {
|
| 58 | compare-shells -c 'read x; echo status=$? x=$x'
|
| 59 | }
|
| 60 |
|
| 61 | test-json-read() {
|
| 62 | rm -v nohup.out || true
|
| 63 |
|
| 64 | run-shell bin/osh -c 'json read'
|
| 65 | }
|
| 66 |
|
| 67 | soil-run() {
|
| 68 | # Make sure there's a TTY
|
| 69 | echo TTY
|
| 70 | tty
|
| 71 | echo
|
| 72 |
|
| 73 | # Somehow it behaves differently in CI
|
| 74 | nohup --version
|
| 75 | echo
|
| 76 |
|
| 77 | # Can't use run-test-funcs because it "steals" input from stdin
|
| 78 | # run-test-funcs
|
| 79 | for t in test-echo test-read test-json-read; do
|
| 80 | echo
|
| 81 | echo "*** Running $t"
|
| 82 | echo
|
| 83 |
|
| 84 | $0 $t < $(tty)
|
| 85 |
|
| 86 | done
|
| 87 | }
|
| 88 |
|
| 89 | run-task "$@"
|