Skip to content

Commit

Permalink
A script to build known versions of all shells we test against.
Browse files Browse the repository at this point in the history
Right now they are the versions that come with Ubuntu 16.04.

test/spec.sh: If possible, use these hermetic shell binaries for spec
tests.

Addresses issue #42.

I'm not sure why, but I had to adjust two tests.

glob.test.sh:
  Upstream dash 0.5.8 also has the same bug as mksh.

  I'm not sure why the Ubuntu package, which is marked 0.5.8, doesn't
  have it.  Maybe they ported a patch over?

quote.test.sh:
  hermetic ash doesn't have this bug for some reason.

Also: the regex test is currently failing for ZSH because we're not
building with regex support.  To be fixed.
  • Loading branch information
Andy Chu committed Jul 4, 2018
1 parent 5fc5f8a commit 5151cf8
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 9 deletions.
3 changes: 2 additions & 1 deletion spec/glob.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ echo [[z] []z] # also accepted
## END

#### Glob of negated unescaped [[] and []]
# osh does this "correctly" because it defers to libc!
touch $TMP/_G
cd $TMP
echo _[^\[z] _[^\]z] # the right way to do it
Expand All @@ -207,7 +208,7 @@ echo _[^[z] _[^]z] # also accepted
_G _G
_G _G
## END
## BUG mksh STDOUT:
## BUG dash/mksh STDOUT:
_[^[z] _[^]z]
_[^[z] _[^]z]
## END
Expand Down
3 changes: 0 additions & 3 deletions spec/quote.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,6 @@ echo -n $'\001' $'\377' | od -A n -c | sed 's/ \+/ /g'
## N-I dash STDOUT:
$ 001 $ 377
## END
## BUG ash STDOUT:
001 0O7
## END

#### $'' octal escapes with fewer than 3 chars
echo $'\1 \11 \11 \111' | od -A n -c | sed 's/ \+/ /g'
Expand Down
65 changes: 65 additions & 0 deletions test/spec-bin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/bin/bash
#
# Build binaries for the spec tests.
#
# Usage:
# ./spec-bin.sh <function name>

set -o nounset
set -o pipefail
set -o errexit

readonly DIR=_tmp/spec-bin

download() {
mkdir -p $DIR
wget --no-clobber --directory $DIR \
https://www.oilshell.org/blob/spec-bin/bash-4.3.tar.gz \
https://www.oilshell.org/blob/spec-bin/busybox-1.22.0.tar.bz2 \
https://www.oilshell.org/blob/spec-bin/dash-0.5.8.tar.gz \
https://www.oilshell.org/blob/spec-bin/mksh-R52c.tgz \
https://www.oilshell.org/blob/spec-bin/zsh-5.1.1.tar.xz
}

extract-all() {
pushd $DIR
for archive in *.tar.* *.tgz; do
echo $archive
tar --extract --file $archive
done
mv -v mksh mksh-R52c # so it doesn't collide
popd
}

build-all() {
# bash/dash/zsh: ./configure; make
# mksh: sh Build.sh
# busybox: make defconfig (default config); make

pushd $DIR
# TODO: Are they all different?
popd
}

link-all() {
pushd $DIR
ln -s -f -v bash-4.3/bash .
ln -s -f -v dash-0.5.8/src/dash .
ln -s -f -v zsh-5.1.1/Src/zsh .
ln -s -f -v mksh-R52c/mksh .
ln -s -f -v busybox-1.22.0/busybox ./ash
popd
}

test-all() {
for sh in bash dash zsh mksh ash; do
$DIR/$sh -c 'echo "Hello from $0"'

# bash and zsh depend on libtinfo, but others don't
# ash and zsh depend on libm, but others don't
# bash and zsh depend on libdl, but others don't
ldd $DIR/$sh
done
}

"$@"
25 changes: 20 additions & 5 deletions test/spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,26 @@ die() {
exit 1
}

readonly DASH=$(which dash 2>/dev/null || echo /bin/sh)
readonly BASH=$(which bash)
readonly MKSH=$(which mksh)
readonly ZSH=$(which zsh)
readonly BUSYBOX_ASH=_tmp/shells/ash
# For now, fall back to the shell in $PATH.
shell-path() {
local name=$1
if test -f _tmp/spec-bin/$name; then
echo _tmp/spec-bin/$name
else
which $name
fi
}

readonly DASH=$(shell-path dash)
readonly BASH=$(shell-path bash)
readonly MKSH=$(shell-path mksh)
readonly ZSH=$(shell-path zsh)

if test -f _tmp/spec-bin/ash; then
readonly BUSYBOX_ASH=_tmp/spec-bin/ash
else
readonly BUSYBOX_ASH=_tmp/shells/ash
fi

readonly OSH_PYTHON=${OSH_PYTHON:-bin/osh}
readonly OSH_OVM=${OSH_OVM:-_bin/osh}
Expand Down

0 comments on commit 5151cf8

Please sign in to comment.