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