1
2 #### argv0 trace
3
4 OILS_TRACE_DIR=$TMP $SH -c '
5
6 # No argv does not crash
7 $(true)
8
9 echo internal
10
11 /bin/echo x1
12
13 /bin/true
14
15 /bin/echo x2
16
17 # Not getting anything here?
18 # NOFORKLAST optimization messes things up if the last command is external
19 # Though turning this off means that measuring performance changes performance
20
21 #( echo "("; /bin/false; /bin/false; echo ")" )
22 ( echo "("; /bin/false; /bin/false )
23
24 a=$(echo "\$("; /bin/true; /bin/true; echo ")")
25 echo "$a"
26
27 /bin/echo x3
28 '
29
30 # For now just check that it parses
31 for j in $TMP/*.json; do
32 #echo "$j" >&2
33 python3 -m json.tool $j >/dev/null
34 done
35
36 ## STDOUT:
37 internal
38 x1
39 x2
40 (
41 $(
42 )
43 x3
44 ## END
45
46 #### crash dump
47
48 rm -f $TMP/*.json
49
50 OILS_CRASH_DUMP_DIR=$TMP $SH -c '
51 g() {
52 local glocal="glocal"
53 echo $(( 1 / 0 ))
54 }
55 f() {
56 local flocal="flocal"
57 shift
58 FOO=bar g
59 }
60 readonly array=(A B C)
61 f "${array[@]}"
62 ' dummy a b c
63
64 echo status=$?
65
66 # Just check that we can parse it. TODO: Test properties.
67 python3 -c '
68 import json, sys
69 from pprint import pprint
70
71 for path in sys.argv[1:]:
72 #print(path)
73 with open(path) as f:
74 dump = json.load(f)
75
76 if 0:
77 print("DUMP")
78 print("status = %d" % dump["status"])
79 print("pid = %d" % dump["pid"])
80
81 if 0:
82 # This has msg, source, line
83 print("error %s" % dump["error"])
84 print()
85
86 if 0:
87 # It would be nice if this has the proc name, I guess debug_stack has it
88 print("argv_stack")
89 pprint(dump["argv_stack"])
90 print()
91
92 if 0:
93 print("debug_stack")
94 pprint(dump["debug_stack"])
95 print()
96
97 if 0:
98 print("var_stack")
99 pprint(dump["var_stack"])
100
101 ' $TMP/*.json
102 echo status=$?
103
104 ## STDOUT:
105 status=1
106 status=0
107 ## END
108
109 #### crash dump with source
110 # TODO: The failure is not propagated through 'source'. Failure only happens
111 # on 'errexit'.
112 #rm -f $TMP/*.json
113 OILS_CRASH_DUMP_DIR=$TMP $SH -c "
114 set -o errexit
115 source $REPO_ROOT/spec/testdata/crash.sh
116 "
117 echo crash status=$?
118
119 # Now try to parse crash dumps
120 set -o xtrace
121 set -o errexit
122
123 # Enumerate crash dumps
124 ok=0
125 for dump in $TMP/*.json; do
126 # Workaround for test issue: release binaries leave empty files because they
127 # don't have the json module.
128 if test -s $dump; then # non-empty
129 python2 -m json.tool $dump > /dev/null
130 echo "OK $dump" >&2
131 (( ++ok ))
132 fi
133 done
134
135 if test $ok -ge 1; then # make sure we parsed at least once crash dump
136 echo 'found crash dump'
137 fi
138
139 ## STDOUT:
140 crash status=1
141 found crash dump
142 ## END
143
144 # NOTE: strict_arith has one case in arith.test.sh), strict_word-eval has a case in var-op-other.
145
146
147 #### --tool cat-em
148
149 $SH --tool cat-em zzZZ
150 echo status=$?
151
152 $SH --tool cat-em stdlib/ysh/math.ysh > /dev/null
153 echo status=$?
154
155 $SH --tool cat-em zzZZ stdlib/ysh/math.ysh > /dev/null
156 echo status=$?
157
158 ## STDOUT:
159 status=1
160 status=0
161 status=1
162 ## END
163
164