forked from oils-for-unix/oils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmoke.sh
executable file
·149 lines (115 loc) · 2.13 KB
/
smoke.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
#!/bin/bash
#
# Sanity checks for the shell.
#
# Usage:
# ./smoke.sh <function name>
set -o nounset
set -o pipefail
set -o errexit
readonly OSH=bin/osh
# Read from a file.
osh-file() {
echo ===== Hello
cat >_tmp/hi.sh <<EOF
echo hi
echo bye
func() {
echo "inside func"
}
func 1 2 3
# TODO: Test vars don't persist.
(echo "in subshell"; echo "another")
echo \$(echo ComSub)
EOF
$OSH _tmp/hi.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.
osh-stdin() {
$OSH < _tmp/hi.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
)
func() {
echo hi
}
EOF
# TODO: test while loop
}
osh-interactive() {
echo 'echo hi' | $OSH -i
echo 'exit' | $OSH -i
}
die() {
echo 1>&2 "$@"
exit 1
}
assert() {
test "$@" || die "$@ failed"
}
# Had a bug with these two cases.
empty() {
set +o errexit
bin/osh -c ''
assert $? -eq 0
echo -n '' | bin/osh
assert $? -eq 0
}
ast() {
bin/osh --no-exec --ast-output - -c 'echo hi'
bin/osh --no-exec --ast-output - --ast-format text -c 'echo hi'
bin/osh --no-exec --ast-output - --ast-format abbrev-html -c 'echo hi'
bin/osh --no-exec --ast-output - --ast-format html -c 'echo hi'
# Not dumping to terminal
if bin/osh --no-exec --ast-output - --ast-format oheap -c 'echo hi'; then
die "Should have failed"
fi
local ast_bin=_tmp/smoke-ast.bin
bin/osh --no-exec --ast-output $ast_bin --ast-format oheap -c 'echo hi'
ls -l $ast_bin
hexdump -C $ast_bin
}
help() {
set +o errexit
bin/oil osh --help
assert $? -eq 0
bin/osh --help
assert $? -eq 0
bin/oil --help
assert $? -eq 0
}
_error-case() {
echo
echo "$@"
echo
bin/osh -c "$@"
}
parse-errors() {
set +o errexit
_error-case 'echo < <<'
_error-case '${foo:}'
_error-case '$(( 1 + ))'
_error-case 'echo $( echo > >> )'
#_error-case 'echo ${'
}
"$@"