summaryrefslogtreecommitdiffhomepage
path: root/tests/regen.sh
blob: d41927dc53cb73be678486e4fdeb19c4657a1862 (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
#!/bin/sh
# Regenerate expected output.
#
#   sh tests/regen.sh posix dash       # reference shell for portable tests
#   sh tests/regen.sh zash ./zash      # after reviewing a behaviour change
#   sh tests/regen.sh proc ./zash
#
# Review the resulting diff before committing it: an .exp file is a claim
# about what is correct.
group=${1:?usage: regen.sh group shell}
shell=${2:?usage: regen.sh group shell}
case $shell in
*/*) shell=$(cd "$(dirname "$shell")" && pwd)/$(basename "$shell") ;;
*) shell=$(command -v "$shell") ;;
esac
TSH=$shell
export TSH
here=$(cd "$(dirname "$0")" && pwd)
TESTS=$here
export TESTS
work=${TMPDIR:-/tmp}/zash-regen.$$
trap 'rm -rf "$work"' EXIT
[ "$group" = proc ] && ZASH_PROCSTAT=1 && export ZASH_PROCSTAT
for t in "$here/$group"/*.sh; do
    rm -rf "$work"
    mkdir -p "$work/d"
    (
        cd "$work/d" || exit 1
        "$shell" "$t" </dev/null >"$work/out" 2>&1
        echo "[status $?]" >>"$work/out"
    )
    sed -e "s|$t|SCRIPT|g" -e "s|$shell|SHELL|g" "$work/out" >"${t%.sh}.exp"
done