OILS / test / nohup.sh View on Github | oilshell.org

89 lines, 52 significant
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
12set -o nounset
13set -o pipefail
14set -o errexit
15
16source devtools/task-five.sh
17source test/common.sh # run-test-funcs
18
19run-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
41compare-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
52test-echo() {
53 compare-shells -c 'echo hi; echo status=$?'
54}
55
56# TODO: osh needs location info for this one
57test-read() {
58 compare-shells -c 'read x; echo status=$? x=$x'
59}
60
61test-json-read() {
62 rm -v nohup.out || true
63
64 run-shell bin/osh -c 'json read'
65}
66
67soil-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
89task-five "$@"