diff options
| -rw-r--r-- | bench/README.md | 19 | ||||
| -rwxr-xr-x | bench/compat.sh | 54 |
2 files changed, 73 insertions, 0 deletions
diff --git a/bench/README.md b/bench/README.md index f70dd06..c984b31 100644 --- a/bench/README.md +++ b/bench/README.md @@ -268,6 +268,25 @@ It matters for anything that starts zash often: a script with a `#!` line, `zash -c`, a spawned subshell. It does not matter for a long interactive session. +## The host's sh + +`compat.sh` runs every `tests/posix` script under zash and under the +shell this host calls `sh`, each in its own directory, and lists the ones +whose output or status differ: + +```sh +sh bench/compat.sh ./zash [/bin/sh] +``` + +The `.exp` files are a reference shell's output, so this is not a test. +It measures how close a script that names `#!/bin/sh` gets to the meaning +that name has here, which is the compatibility zash aims for. On z/OS +today, 10 of the 38 scripts agree and 28 differ: most differences are +wording that POSIX leaves to the shell (an IBM sh says `FSUM7351 not +found` where zash says `not found`), and the rest are behaviour worth +reading one at a time. Linux numbers are lower-information, because +`/bin/sh` there is usually bash while the `.exp` files come from dash. + Measured with 100 starts each: `-c :` is a bare start, `script` is the kernel starting the shell on a one-line file, which is what a `#!` line does. diff --git a/bench/compat.sh b/bench/compat.sh new file mode 100755 index 0000000..7575fd1 --- /dev/null +++ b/bench/compat.sh @@ -0,0 +1,54 @@ +#!/bin/sh +# How far is zash from the shell this host calls sh? +# +# sh bench/compat.sh ./zash [/bin/sh] +# +# Every tests/posix script is run under both shells, each in its own empty +# directory, and the scripts whose output or status differ are listed with +# the first difference. +# +# This is not a pass/fail test. The suite's .exp files come from a +# reference shell (tests/regen.sh), and on z/OS /bin/sh is IBM's ksh lineage +# shell with behaviour of its own. What the count says is how close a +# script that names #!/bin/sh gets to its meaning here, which is the +# compatibility zash aims for; a script that zash runs and the host's sh +# does not is either a zash extension or a zash bug, and the diff says +# which one to look at. +# +# The scripts need the same PATH the suite does on z/OS (build/zos-tools +# for sleep); see tests/run.sh. +here=$(cd "$(dirname "$0")" && pwd) +tests=$here/../tests +zash=${1:?usage: compat.sh zash-shell [other-shell]} +other=${2:-/bin/sh} +case $zash in /*) ;; *) zash=$PWD/$zash ;; esac +# Some posix scripts start a shell of their own through $TSH; give them the +# one under test, as tests/run.sh does. +TSH=$zash +export TSH +work=${TMPDIR:-/tmp}/zash-compat.$$ +mkdir -p "$work" || exit 1 +trap 'rm -rf "$work"' EXIT + +run() { # shell script dir out + mkdir -p "$3" || exit 1 + ( cd "$3" && "$1" "$2" ) >"$work/$4" 2>&1 + echo "[status $?]" >>"$work/$4" +} + +same=0 +differ=0 +for t in "$tests"/posix/*.sh; do + name=$(basename "$t" .sh) + run "$zash" "$t" "$work/$name/zash" z.out + run "$other" "$t" "$work/$name/other" o.out + if cmp -s "$work/z.out" "$work/o.out"; then + same=$((same + 1)) + continue + fi + differ=$((differ + 1)) + echo "=== $name" + diff "$work/o.out" "$work/z.out" | sed -n '1,10p' +done + +echo "$same agree, $differ differ from $other" |
