1 | #!/usr/bin/env bash
|
2 | #
|
3 | # Usage:
|
4 | # test/oshc-deps.sh <function name>
|
5 |
|
6 | set -o nounset
|
7 | set -o pipefail
|
8 | set -o errexit
|
9 |
|
10 | source test/common.sh
|
11 |
|
12 | # TODO: We need a common test framework for command-line syntax of bin/*. The
|
13 | # spec tests are doing that now with $SH.
|
14 | # osh2oil should be oshc translate.
|
15 |
|
16 | # Compare osh code on stdin (fd 0) and expected oil code on fd 3.
|
17 | assert-deps() {
|
18 | bin/osh --tool deps | diff -u /dev/fd/3 - || fail
|
19 | }
|
20 |
|
21 | test-ourselves() {
|
22 | ### This shows an error but doesn't exit 0
|
23 | bin/osh --tool deps $0
|
24 | test $? -eq 0 || fail
|
25 | }
|
26 |
|
27 | test-deps() {
|
28 | # Have to go inside a condition
|
29 | assert-deps <<EOF 3<<DEPS
|
30 | if { grep foo bar; } then
|
31 | cat hi
|
32 | fi
|
33 | EOF
|
34 | grep
|
35 | cat
|
36 | DEPS
|
37 |
|
38 | # g is used textually before defined, but that's OK
|
39 | assert-deps <<EOF 3<<DEPS
|
40 | f() {
|
41 | g
|
42 | }
|
43 | g() {
|
44 | echo G
|
45 | }
|
46 | f
|
47 | grep foo bar
|
48 | EOF
|
49 | grep
|
50 | DEPS
|
51 | }
|
52 |
|
53 | DISABLED-test-deps-2() {
|
54 | # g is used before defined, NOT OK
|
55 | assert-deps <<EOF 3<<DEPS
|
56 | g
|
57 | g() {
|
58 | echo G
|
59 | }
|
60 | grep foo bar
|
61 | EOF
|
62 | g
|
63 | grep
|
64 | DEPS
|
65 |
|
66 | }
|
67 |
|
68 | run-for-release() {
|
69 | run-other-suite-for-release tools-deps run-test-funcs
|
70 | }
|
71 |
|
72 | soil-run() {
|
73 | run-test-funcs
|
74 | }
|
75 |
|
76 | "$@"
|