1 #!/usr/bin/env bash
2
3 #### --debug-file
4 $SH --debug-file $TMP/debug.txt -c 'true'
5 grep 'OSH started with' $TMP/debug.txt >/dev/null && echo yes
6 ## stdout: yes
7
8 #### strict-arith option
9 set -o strict-arith
10 ## status: 0
11
12 #### strict-arith from command line
13 $SH -o strict-arith
14 ## status: 0
15
16 #### repr
17 x=42
18 repr x
19 echo status=$?
20 repr nonexistent
21 echo status=$?
22 ## STDOUT:
23 x = (value.Str s:42)
24 status=0
25 'nonexistent' is not defined
26 status=1
27 ## END
28
29
30 #### crash dump
31 rm -f $TMP/*.json
32 OSH_CRASH_DUMP_DIR=$TMP $SH -c '
33 g() {
34 local glocal="glocal"
35 echo $(( 1 / 0 ))
36 }
37 f() {
38 local flocal="flocal"
39 shift
40 FOO=bar g
41 }
42 readonly array=(A B C)
43 f "${array[@]}"
44 ' dummy a b c
45 echo status=$?
46 # Just check that we can parse it. TODO: Test properties.
47 python -m json.tool $TMP/*.json > /dev/null
48 echo status=$?
49 ## STDOUT:
50 status=1
51 status=0
52 ## END
53
54 #### crash dump with source
55 # TODO: The failure is not propagated through 'source'. Failure only happens
56 # on 'errexit'.
57 #rm -f $TMP/*.json
58 OSH_CRASH_DUMP_DIR=$TMP $SH -c '
59 set -o errexit
60 source spec/testdata/crash.sh
61 '
62 echo status=$?
63
64 # Now try to parse crash dumps
65 set -o xtrace
66 set -o errexit
67 ok=0
68 for dump in $TMP/*.json; do
69 # Workaround for test issue: release binaries leave empty files because they
70 # don't have the json module.
71 if test -s $dump; then # non-empty
72 python -m json.tool $dump > /dev/null
73 echo "OK $dump" >&2
74 (( ++ok ))
75 fi
76 done
77 if test $ok -ge 1; then # make sure we parsed at least once crash dump
78 echo OK
79 fi
80 ## STDOUT:
81 status=1
82 OK
83 ## END
84
85 # NOTE: strict-arith has one case in arith.test.sh), strict-word-eval has a case in var-op-other.
86