| 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 | : ${LIB_OSH=stdlib/osh}
|
| 13 | source $LIB_OSH/bash-strict.sh
|
| 14 | source $LIB_OSH/task-five.sh
|
| 15 |
|
| 16 | source test/common.sh # run-test-funcs
|
| 17 |
|
| 18 | run-shell() {
|
| 19 | local sh=$1
|
| 20 | shift
|
| 21 |
|
| 22 | rm -v nohup.out || true
|
| 23 |
|
| 24 | set +o errexit
|
| 25 | nohup $sh "$@"
|
| 26 | echo " => $sh returned $?"
|
| 27 | set -o errexit
|
| 28 |
|
| 29 | if test -f nohup.out; then
|
| 30 | cat nohup.out
|
| 31 | else
|
| 32 | # happens in CI ? I thought we run with docker -t.
|
| 33 | echo "nohup.out doesn't exist"
|
| 34 | fi
|
| 35 |
|
| 36 | echo
|
| 37 |
|
| 38 | }
|
| 39 |
|
| 40 | compare-shells() {
|
| 41 | for sh in dash bash mksh bin/osh; do
|
| 42 | echo " ----- "
|
| 43 | echo " $sh"
|
| 44 | echo
|
| 45 |
|
| 46 | run-shell $sh "$@"
|
| 47 |
|
| 48 | done
|
| 49 | }
|
| 50 |
|
| 51 | test-echo() {
|
| 52 | compare-shells -c 'echo hi; echo status=$?'
|
| 53 | }
|
| 54 |
|
| 55 | # TODO: osh needs location info for this one
|
| 56 | test-read() {
|
| 57 | compare-shells -c 'read x; echo status=$? x=$x'
|
| 58 | }
|
| 59 |
|
| 60 | test-json-read() {
|
| 61 | rm -v nohup.out || true
|
| 62 |
|
| 63 | run-shell bin/osh -c 'json read'
|
| 64 | }
|
| 65 |
|
| 66 | # TODO: Use byo-server
|
| 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 | task-five "$@"
|