OILS / test / tools-deps.sh View on Github | oilshell.org

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