OILS / spec / ysh-dev.test.sh View on Github | oilshell.org

164 lines, 46 significant
1
2#### argv0 trace
3
4OILS_TRACE_DIR=$TMP $SH -c '
5
6# No argv does not crash
7$(true)
8
9echo 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
24a=$(echo "\$("; /bin/true; /bin/true; echo ")")
25echo "$a"
26
27/bin/echo x3
28'
29
30# For now just check that it parses
31for j in $TMP/*.json; do
32 #echo "$j" >&2
33 python3 -m json.tool $j >/dev/null
34done
35
36## STDOUT:
37internal
38x1
39x2
40(
41$(
42)
43x3
44## END
45
46#### crash dump
47
48rm -f $TMP/*.json
49
50OILS_CRASH_DUMP_DIR=$TMP $SH -c '
51g() {
52 local glocal="glocal"
53 echo $(( 1 / 0 ))
54}
55f() {
56 local flocal="flocal"
57 shift
58 FOO=bar g
59}
60readonly array=(A B C)
61f "${array[@]}"
62' dummy a b c
63
64echo status=$?
65
66# Just check that we can parse it. TODO: Test properties.
67python3 -c '
68import json, sys
69from pprint import pprint
70
71for 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
102echo status=$?
103
104## STDOUT:
105status=1
106status=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
113OILS_CRASH_DUMP_DIR=$TMP $SH -c "
114set -o errexit
115source $REPO_ROOT/spec/testdata/crash.sh
116"
117echo crash status=$?
118
119# Now try to parse crash dumps
120set -o xtrace
121set -o errexit
122
123# Enumerate crash dumps
124ok=0
125for 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
133done
134
135if test $ok -ge 1; then # make sure we parsed at least once crash dump
136 echo 'found crash dump'
137fi
138
139## STDOUT:
140crash status=1
141found 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
150echo status=$?
151
152$SH --tool cat-em stdlib/math.ysh > /dev/null
153echo status=$?
154
155$SH --tool cat-em zzZZ stdlib/math.ysh > /dev/null
156echo status=$?
157
158## STDOUT:
159status=1
160status=0
161status=1
162## END
163
164