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 = (cell val:(value.Str s:42) exported:F readonly:F)
16 status=0
17 'nonexistent' is not defined
18 status=1
19 ## END
20
21 #### repr on indexed array with hole
22 declare -a array
23 array[3]=42
24 repr array
25 ## STDOUT:
26 array = (cell val:(value.MaybeStrArray strs:[_ _ _ 42]) exported:F readonly:F)
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