-
-
Notifications
You must be signed in to change notification settings - Fork 146
/
osh-usage.sh
executable file
·193 lines (150 loc) · 3.27 KB
/
osh-usage.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#!/usr/bin/env bash
#
# Test osh usage "from the outside".
#
# Usage:
# ./osh-usage.sh <function name>
set -o nounset
set -o pipefail
set -o errexit
source test/common.sh
# Doesn't work in release automation!
FAIL-test-manual-oheap() {
# Not dumping to terminal
if bin/osh -n --ast-format oheap -c 'echo hi'; then
die "Should have failed"
fi
echo OK
}
test-ast-formats() {
bin/osh -n -c 'echo hi'
bin/osh -n --ast-format text -c 'echo hi'
bin/osh -n --ast-format abbrev-html -c 'echo hi'
bin/osh -n --ast-format html -c 'echo hi'
# Removed with oheap
return
local ast_bin=_tmp/smoke-ast.bin
bin/osh -n --ast-format oheap -c 'echo hi' > $ast_bin
ls -l $ast_bin
hexdump -C $ast_bin
}
# Read from a file.
test-osh-file() {
echo ===== Hello
cat >_tmp/smoke-prog.sh <<EOF
echo hi
myfunc() {
echo "inside func"
}
myfunc 1 2 3
# TODO: Test vars don't persist.
(echo "in subshell"; echo "another")
echo \$(echo ComSub)
EOF
$OSH _tmp/smoke-prog.sh
echo ===== EMPTY
touch _tmp/empty.sh
$OSH _tmp/empty.sh
echo ===== NO TRAILING NEWLINE
echo -n 'echo hi' >_tmp/no-newline.sh
$OSH _tmp/no-newline.sh
}
# Read from stdin.
test-osh-stdin() {
$OSH < _tmp/smoke-prog.sh
echo ===== EMPTY
$OSH < _tmp/empty.sh
echo ===== NO TRAILING NEWLINE
$OSH < _tmp/no-newline.sh
# Line continuation tests
$OSH <<EOF
echo "
hi
"
echo \\
line continuation; echo two
cat <<EOF_INNER
here doc
EOF_INNER
echo \$(
echo command sub
)
myfunc() {
echo hi
}
EOF
}
test-osh-interactive() {
set +o errexit
echo 'echo hi' | $OSH -i
assert $? -eq 0
echo 'exit' | $OSH -i
assert $? -eq 0
# Parse failure
echo ';' | $OSH -i
assert $? -eq 2
# Bug fix: this shouldn't try execute 'echo OIL OIL'
# The line lexer wasn't getting reset on parse failures.
echo ';echo OIL OIL' | $OSH -i
assert $? -eq 2
# Bug fix: c_parser.Peek() in main_loop.InteractiveLoop can raise execptions
echo 'v=`echo \"`' | $OSH -i
assert $? -eq 2
}
test-help() {
set +o errexit
# TODO: Test the oil.ovm binary as well as bin/oil.py.
export PYTHONPATH='.:vendor/' # TODO: Put this in one place.
# Bundle usage.
bin/oil.py --help
assert $? -eq 0
# Pass applet as first name.
bin/oil.py osh --help
assert $? -eq 0
bin/oil.py oil --help
assert $? -eq 0
# Symlinks.
bin/osh --help
assert $? -eq 0
bin/oil --help
assert $? -eq 0
}
test-exit-builtin-interactive() {
set +o errexit
echo 'echo one; exit 42; echo two' | bin/osh -i
assert $? -eq 42
}
test-rc-file() {
set +o errexit
local rc=_tmp/testrc
echo 'PS1="TESTRC$ "' > $rc
bin/osh -i --rcfile $rc < /dev/null
assert $? -eq 0
bin/osh -i --rcfile /dev/null < /dev/null
assert $? -eq 0
# oshrc is optional
# TODO: Could warn about nonexistent explicit --rcfile?
bin/osh -i --rcfile nonexistent__ < /dev/null
assert $? -eq 0
}
test-noexec-fails-properly() {
set +o errexit
local tmp=_tmp/osh-usage-noexec.txt
bin/osh -n -c 'echo; echo; |' > $tmp
assert $? -eq 2
read < $tmp
assert $? -eq 1 # shouldn't have read any lines!
echo "$tmp appears empty, as expected"
}
test-version() {
set +o errexit
bin/osh --version
assert $? -eq 0
}
run-for-release() {
run-other-suite-for-release osh-usage run-test-funcs
}
soil-run() {
run-test-funcs
}
"$@"