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

120 lines, 35 significant
1
2#### crash dump
3
4rm -f $TMP/*.json
5
6OILS_CRASH_DUMP_DIR=$TMP $SH -c '
7g() {
8 local glocal="glocal"
9 echo $(( 1 / 0 ))
10}
11f() {
12 local flocal="flocal"
13 shift
14 FOO=bar g
15}
16readonly array=(A B C)
17f "${array[@]}"
18' dummy a b c
19
20echo status=$?
21
22# Just check that we can parse it. TODO: Test properties.
23python3 -c '
24import json, sys
25from pprint import pprint
26
27for path in sys.argv[1:]:
28 #print(path)
29 with open(path) as f:
30 dump = json.load(f)
31
32 if 0:
33 print("DUMP")
34 print("status = %d" % dump["status"])
35 print("pid = %d" % dump["pid"])
36
37 if 0:
38 # This has msg, source, line
39 print("error %s" % dump["error"])
40 print()
41
42 if 0:
43 # It would be nice if this has the proc name, I guess debug_stack has it
44 print("argv_stack")
45 pprint(dump["argv_stack"])
46 print()
47
48 if 0:
49 print("debug_stack")
50 pprint(dump["debug_stack"])
51 print()
52
53 if 0:
54 print("var_stack")
55 pprint(dump["var_stack"])
56
57' $TMP/*.json
58echo status=$?
59
60## STDOUT:
61status=1
62status=0
63## END
64
65#### crash dump with source
66# TODO: The failure is not propagated through 'source'. Failure only happens
67# on 'errexit'.
68#rm -f $TMP/*.json
69OILS_CRASH_DUMP_DIR=$TMP $SH -c "
70set -o errexit
71source $REPO_ROOT/spec/testdata/crash.sh
72"
73echo crash status=$?
74
75# Now try to parse crash dumps
76set -o xtrace
77set -o errexit
78
79# Enumerate crash dumps
80ok=0
81for dump in $TMP/*.json; do
82 # Workaround for test issue: release binaries leave empty files because they
83 # don't have the json module.
84 if test -s $dump; then # non-empty
85 python2 -m json.tool $dump > /dev/null
86 echo "OK $dump" >&2
87 (( ++ok ))
88 fi
89done
90
91if test $ok -ge 1; then # make sure we parsed at least once crash dump
92 echo 'found crash dump'
93fi
94
95## STDOUT:
96crash status=1
97found crash dump
98## END
99
100# NOTE: strict_arith has one case in arith.test.sh), strict_word-eval has a case in var-op-other.
101
102
103#### --tool cat-em
104
105$SH --tool cat-em zzZZ
106echo status=$?
107
108$SH --tool cat-em stdlib/math.ysh > /dev/null
109echo status=$?
110
111$SH --tool cat-em zzZZ stdlib/math.ysh > /dev/null
112echo status=$?
113
114## STDOUT:
115status=1
116status=0
117status=1
118## END
119
120