summaryrefslogtreecommitdiffhomepage
path: root/bench/compat.sh
blob: 7575fd1c41307ac1796b1b6883be02cde3e0d7da (plain)
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
#!/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"