1 | #!/usr/bin/env bash
|
2 | #
|
3 | # Usage:
|
4 | # ./osh-crash.sh <function name>
|
5 |
|
6 | set -o nounset
|
7 | set -o pipefail
|
8 | set -o errexit
|
9 |
|
10 | g() {
|
11 | readonly g=1
|
12 | local -a bash_array=(a b)
|
13 | bash_array[5]=z
|
14 | readonly bash_array
|
15 |
|
16 | readonly -A bash_assoc=([x]=y [foo]=bar)
|
17 |
|
18 | echo foo > $bar
|
19 | }
|
20 |
|
21 | f() {
|
22 | shift
|
23 | local flocal=flocal
|
24 | FOO=bar g A B
|
25 | }
|
26 |
|
27 | main() {
|
28 | f a b c
|
29 | }
|
30 |
|
31 | run-with-osh() {
|
32 | OILS_CRASH_DUMP_DIR=_tmp bin/osh $0 main "$@"
|
33 | }
|
34 |
|
35 | _do-subshell() {
|
36 | echo PID=$$
|
37 | ( f a b c )
|
38 | }
|
39 |
|
40 | # Note: we get two difference crash dumps, with two different stacks.
|
41 | #
|
42 | # That's because we call through $0.
|
43 |
|
44 | do-subshell() {
|
45 | # clear environment so it's smaller
|
46 | env -i OILS_CRASH_DUMP_DIR=_tmp \
|
47 | bin/osh $0 _do-subshell "$@"
|
48 | }
|
49 |
|
50 | _pipeline() {
|
51 | # All of these show multiple errors
|
52 |
|
53 | false | wc -l
|
54 |
|
55 | #{ echo 1; false; echo 2; } | wc -l
|
56 |
|
57 | #f() { echo 1; false; echo 2; }
|
58 | #f | tac
|
59 | }
|
60 |
|
61 | do-pipeline() {
|
62 | env -i PATH=$PATH OILS_CRASH_DUMP_DIR=_tmp \
|
63 | bin/osh $0 _pipeline
|
64 | }
|
65 |
|
66 | "$@"
|