diff options
author | Akim Demaille <akim.demaille@gmail.com> | 2020-05-05 08:08:25 +0200 |
---|---|---|
committer | Akim Demaille <akim.demaille@gmail.com> | 2020-05-05 08:21:12 +0200 |
commit | cb9f4cb5439adc33f877f134e87b9b2233416c17 (patch) | |
tree | 2bea5dc0e9b32b716a98a71ec19f534f1deab3bb /examples | |
parent | b86dcaf40ba0e06ac2d8a3c3fcba5a092e3ed105 (diff) | |
download | bison-cb9f4cb5439adc33f877f134e87b9b2233416c17.tar.gz |
examples: fix handling of syntax errors
The shell grammar does not allow empty statements in then/else part of
an if, but examples/test failed to catch the syntax errors from the
script it ran. So exited with success anyway.
You would expect 'set -e' to suffice, but with bash 3.2 actually it
does not. As a matter of fact, I could find a way to have this behave
properly:
$ cat test.sh
set -e
cleanup ()
{
status=$?
echo "cleanup: $status"
exit $status
}
trap cleanup 0 1 2 13 15
. $1
s=$?
echo "test.sh: $s"
exit $s
$ cat bistro.test
if true; then
fi
$ /bin/sh ./test.sh ./bistro.test
./bistro.test: line 2: syntax error near unexpected token `fi'
cleanup: 0
$ echo $?
0
Remove the set -e (or the trap), and tada, it works... So we have to
deal with the error by hand.
* examples/test ($exit): Replace with...
($status): this.
Preserve the exit status of the test case.
* examples/c/bistromathic/bistromathic.test: Fix syntax error.
Diffstat (limited to 'examples')
-rwxr-xr-x | examples/c/bistromathic/bistromathic.test | 1 | ||||
-rwxr-xr-x | examples/test | 12 |
2 files changed, 7 insertions, 6 deletions
diff --git a/examples/c/bistromathic/bistromathic.test b/examples/c/bistromathic/bistromathic.test index 0f0b7898..3bb83b77 100755 --- a/examples/c/bistromathic/bistromathic.test +++ b/examples/c/bistromathic/bistromathic.test @@ -43,6 +43,7 @@ echo '0' | prog >effective if diff perfect effective >/dev/null 2>&1; then # Alles ist gut. + strip_prompt=false elif diff ok effective >/dev/null 2>&1; then strip_prompt=true else diff --git a/examples/test b/examples/test index 3bf6edd4..c80e919e 100755 --- a/examples/test +++ b/examples/test @@ -25,7 +25,7 @@ medir=$(dirname "$1" | sed -e 's,.*examples/,,') number=1 # Exit status of this script. -exit=true +status=0 # top_builddir. cwd=$(pwd) @@ -141,20 +141,20 @@ run () sed -e 's/^/ /' eff echo "$me: diff:" diff -u exp eff | sed -e 's/^/ /' - exit=false + status=1 fi else echo "$me: FAIL: $number (expected status: $sta_exp, effective: $sta_eff)" cat err_eff - exit=false + status=1 fi number=$(expr $number + 1) } # We have cd'd one level deeper. case $1 in - /*) . "$1";; - *) . "../$1";; + /*) . "$1" || status=2;; + *) . "../$1" || status=2;; esac -$exit +exit $status |