-
-
Notifications
You must be signed in to change notification settings - Fork 146
/
gold.sh
executable file
·218 lines (170 loc) · 4.68 KB
/
gold.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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#!/usr/bin/env bash
#
# Run real shell code with osh and bash, and compare the results.
#
# Limitation: If a script shells out to another bash script, osh won't be run.
# TODO: --hijack-shebang or just 'sed' all the scripts in a repo?
#
# Usage:
# ./gold-test.sh <function name>
set -o nounset
set -o pipefail
set -o errexit
shopt -s strict:all 2>/dev/null || true # dogfood for OSH
source test/common.sh # for $OSH
readonly GOLD_DIR='test/gold'
# Runs an command (argv) the normal way (with its shebang) and then with
# OSH, and compares the stdout and exit code.
#
# Also puts $PWD/bin on the front of $PATH, in order to read bin/readlink
# and so forth.
_compare() {
set +o errexit
# NOTE: This will be wrong with OSH_HIJACK_SHEBANG!
"$@" >_tmp/shebang.txt
local expected_status=$?
$OSH "$@" >_tmp/osh.txt
local osh_status=$?
set -o errexit
#md5sum _tmp/shebang.txt _tmp/osh.txt
if ! diff -u _tmp/shebang.txt _tmp/osh.txt; then
echo FAIL
exit 1
fi
if test $expected_status != $osh_status; then
echo "FAIL: Got status $osh_status but expected $expected_status"
echo "in test case: $@"
exit 1
fi
return 0
}
# Uses
# - { busybox || true; } | head
# - $1
version-text() {
_compare test/spec.sh version-text
}
# Uses {core,osh}/*.py
count() {
_compare metrics/source-code.sh all
}
# Uses $(cd $(dirname $0) && pwd)
one-spec-test() {
_compare test/spec.sh builtin-special
}
# Uses redirect of functions.
html-summary() {
# BUG: in the devtools/release.sh process, there's nothing to summarize here
# because _tmp/spec is deleted.
_compare test/spec-runner.sh html-summary osh
}
gen-module-init() {
local modules='time datetime'
_compare build/actions.sh gen-module-init $modules
}
wild() {
_compare test/wild.sh all '^distro/usr-bin'
}
# NOTE: zsh behaves differently under sh and bin/osh! Looks like it is an
# inherited file descriptor issue.
#
# A bin/osh app bundle also behaves differently. Maybe because of the internal
# environment variables.
startup-benchmark() {
_compare benchmarks/startup.sh compare-strace
}
configure() { _compare ./configure; }
configure-bug() { _compare $GOLD_DIR/configure-bug.sh; }
nix() { _compare $GOLD_DIR/nix.sh isElfSimpleWithStdin; }
and-or() { _compare $GOLD_DIR/and-or.sh test-simple; }
comments() { _compare $GOLD_DIR/comments.sh; }
readonly_() { _compare $GOLD_DIR/readonly.sh; }
export-case() { _compare $GOLD_DIR/export.sh; }
glob() { _compare $GOLD_DIR/glob.sh; }
no-op() { _compare metrics/source-code.sh; }
complex-here-docs() { _compare $GOLD_DIR/complex-here-docs.sh; }
big-here-doc() { _compare $GOLD_DIR/big-here-doc.sh; }
case-in-subshell() { _compare $GOLD_DIR/case-in-subshell.sh; }
command-sub() { _compare $GOLD_DIR/command-sub.sh; }
command-sub-2() { _compare $GOLD_DIR/command-sub-2.sh; }
char-class() { _compare $GOLD_DIR/char-class.sh demo; }
strip-op-char-class() { _compare $GOLD_DIR/strip-op-char-class.sh; }
# Similar tests for backslash escaping.
echo-e() { _compare $GOLD_DIR/echo-e.sh; }
dollar-sq() { _compare $GOLD_DIR/dollar-sq.sh; }
word-eval() { _compare $GOLD_DIR/word-eval.sh; }
abuild() {
_compare $GOLD_DIR/abuild.sh is_function is_function
}
# Needs declare -p
declare() { _compare $GOLD_DIR/declare.sh demo; }
# Needs declare -p
scope() { _compare $GOLD_DIR/scope.sh; }
readlink-case() {
$GOLD_DIR/readlink.sh compare
}
errexit() { _compare $GOLD_DIR/errexit.sh all; }
# Hm this isn't tickling the bug?
errexit-confusion() {
_compare $GOLD_DIR/errexit-confusion.sh run-for-release-OLD
_compare $GOLD_DIR/errexit-confusion.sh run-for-release-FIXED
}
parse-help() {
local dir=benchmarks/parse-help
# This is not hermetic since it calls 'ls'
_compare $dir/excerpt.sh _parse_help ls
}
# Gah, bash gets this from compile-time configuration generated with autoconf,
# not uname(). It looks like 'linux-gnu' on Ubuntu. In Alpine, it's
# 'linux-musl'.
_ostype() {
echo $OSTYPE
}
ostype() {
_compare $0 _ostype
}
readonly -a PASSING=(
# FLAKY: This one differs by timestamp
#version-text
configure
configure-bug
nix
and-or
comments
readonly_
export-case
glob
no-op
complex-here-docs
# BUG IN OSH!
# big-here-doc
case-in-subshell
command-sub
command-sub-2
echo-e
dollar-sq
word-eval
char-class
strip-op-char-class
abuild
count
one-spec-test
html-summary
gen-module-init
readlink-case
errexit
errexit-confusion
parse-help
# This one takes a little long, but it's realistic.
#wild
# There are slight differences in the number of syscalls reported. Not sure
# of the cause.
#startup-benchmark
)
all-passing() {
run-all "${PASSING[@]}"
}
run-for-release() {
run-other-suite-for-release gold all-passing
}
"$@"