OILS / test / smoosh.sh View on Github | oilshell.org

220 lines, 130 significant
1#!/usr/bin/env bash
2#
3# Install smoosh. Based on a shell script by Michael Greenberg.
4#
5# Usage:
6# test/smoosh.sh <function name>
7
8set -o nounset
9set -o pipefail
10set -o errexit
11
12readonly OPAM=~/.opam
13
14readonly REPO_ROOT=$(cd $(dirname $0)/.. && pwd)
15
16# Copies of lem we built inside the repo.
17export PATH="$PWD/lem/bin:${PATH}"
18export LEMLIB="$PWD/lem/library"
19
20
21# IMPORTANT: Every function uses this OCaml environment!
22# TODO: make-spec doesn't need it though!
23if command -v opam; then
24 eval $(opam config env)
25fi
26
27update() {
28 #cd ~/git/languages
29 #git clone https://github.com/mgree/smoosh
30 git pull
31 git submodule update --init
32}
33
34install-system-deps() {
35 # system support for libdash; libgmp for zarith for lem
36 sudo apt install autoconf autotools-dev libtool pkg-config libffi-dev libgmp-dev
37 # (NOTE: already had all of these.)
38
39 sudo apt install opam
40}
41
42opam-switch() {
43 # list compilers:
44 # opam switch list
45
46 # Version that upstream developers use. 4.02 is the system compiler on
47 # Ubuntu 16.04, but that's too old (Sys.int_size not defined)
48 opam switch 4.07.0
49}
50
51# NOTE: I didn't have opam modify .bashrc. So from now on it's:
52#
53# eval $(opam config env)
54#
55# State is in ~/.opam
56
57install-ocaml-deps() {
58 # make sure we have ocamlfind and ocamlbuild
59 opam install ocamlfind ocamlbuild
60
61 # set up FFI for libdash; num library for lem; extunix for shell syscalls
62 opam pin add ctypes 0.11.5
63 opam install ctypes-foreign
64 opam install num
65 opam install extunix
66}
67
68link-this-script() {
69 local this_script=$PWD/test/smoosh.sh
70
71 ln -s -f -v $this_script ~/git/languages/smoosh
72}
73
74
75deps1() {
76 # zarith already installed error?
77
78 # Why is this being installed with the system compiler?
79 # I have to do "opam switch" as root?
80
81 pushd lem/ocaml-lib
82 opam config exec -- sudo make install_dependencies
83 popd
84}
85
86build-lem() {
87 set -x
88
89 # set up lem
90 pushd lem
91 opam config exec -- make
92 opam config exec -- make install
93 popd
94}
95
96build-libdash() {
97 # build libdash, expose shared object
98 pushd libdash
99 ./autogen.sh && ./configure --prefix=/usr --libdir=/usr/lib/x86_64-linux-gnu
100 make
101 sudo make install
102 popd
103
104 # build ocaml bindings
105 pushd libdash/ocaml
106 opam config exec -- make && opam config exec -- make install
107 popd
108}
109
110build-smoosh() {
111 # build smoosh
112 pushd src
113 opam config exec -- make all test
114 popd
115}
116
117#
118# Translate tests to our spec test format
119#
120
121test-hangs() {
122 case $1 in
123 # causes a problem for the sh_spec parser
124 semantics.empty.test)
125 return 0
126 ;;
127 # hangs on BASH even with 'timeout 1s'? How?
128 builtin.history.nonposix.test|parse.error.test|semantics.interactive.expansion.exit.test|sh.interactive.ps1.test|sh.ps1.override.test)
129 return 0
130 ;;
131 # hangs on DASH even with 'timeout 1s'? How?
132 builtin.readonly.assign.interactive.test)
133 return 0
134 ;;
135 esac
136 return 1
137}
138
139
140test-cases() {
141 local translate=${1:-} # translate or just print
142 local hang=${2:-} # which suite: smoosh or smoosh-hang
143
144 local i=0
145
146 # REF_SHELLS
147 echo '## compare_shells: bash dash mksh'
148
149 pushd ~/git/languages/smoosh/tests/shell >/dev/null
150 for t in *.test; do
151 if [[ $t == semantics.empty.test ]]; then
152 continue;
153 fi
154
155 if test -n "$hang"; then
156 if ! test-hangs $t; then
157 continue
158 fi
159 else
160 if test-hangs $t; then
161 continue
162 fi
163 fi
164
165 local prefix=${t%.test}
166
167 if test -z "$translate"; then
168 echo $t
169 continue
170 fi
171
172 # Print the test case
173
174 echo "#### $t"
175 cat $t
176 echo
177
178 # If no file, it's zero
179 local ec="$prefix.ec"
180 if test -f "$ec"; then
181 echo "## status: $(cat $ec)"
182 fi
183
184 local stdout="$prefix.out"
185 if test -f "$stdout"; then
186 # Choose between STDOUT and stdout-json assertions.
187 $REPO_ROOT/test/smoosh_import.py "$stdout"
188 fi
189
190 if false; then
191 local stderr="$prefix.err"
192 if test -f "$stderr"; then
193 echo '## STDERR:'
194 cat $stderr
195 echo '## END'
196 fi
197 fi
198
199 echo
200
201 i=$((i + 1))
202
203 done
204 popd >/dev/null
205
206 echo "Translated $i test cases" >&2
207}
208
209make-spec() {
210 local out=_tmp/smoosh.test.sh
211 test-cases translate > $out
212 echo "Wrote $out"
213
214 out=_tmp/smoosh-hang.test.sh
215 test-cases translate hang > $out
216 echo "Wrote $out"
217}
218
219
220"$@"