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