1
0
mirror of git://git.code.sf.net/p/zsh/code synced 2024-11-19 13:33:52 +01:00

14430: handle cleanup better in Test/ztst.zsh

This commit is contained in:
Peter Stephenson 2001-05-22 09:27:25 +00:00
parent 86486827b3
commit 87f45de409
2 changed files with 42 additions and 12 deletions

@ -1,3 +1,8 @@
2001-05-22 Peter Stephenson <pws@csr.com>
* 14430: Test/ztst.zsh: Be less cavalier about exiting on failure
so as to perform cleanup.
2001-05-21 Clint Adams <clint@zsh.org> 2001-05-21 Clint Adams <clint@zsh.org>
* 14419: Src/Builtins/rlimits.awk: handle glibc 2.2.3 * 14419: Src/Builtins/rlimits.awk: handle glibc 2.2.3
@ -18,6 +23,8 @@
2001-05-21 Peter Stephenson <pws@csr.com> 2001-05-21 Peter Stephenson <pws@csr.com>
* unposted: Config/version.mk: 4.0.1-pre-5.
* 14408: Test/C02cond.ztst: do chmod +w to work around rm -f * 14408: Test/C02cond.ztst: do chmod +w to work around rm -f
problem in Cygwin. problem in Cygwin.

@ -53,6 +53,8 @@ ZTST_mainopts=(${(kv)options})
ZTST_testdir=$PWD ZTST_testdir=$PWD
ZTST_testname=$1 ZTST_testname=$1
integer ZTST_testfailed
# The source directory is not necessarily the current directory, # The source directory is not necessarily the current directory,
# but if $0 doesn't contain a `/' assume it is. # but if $0 doesn't contain a `/' assume it is.
if [[ $0 = */* ]]; then if [[ $0 = */* ]]; then
@ -99,8 +101,8 @@ ZTST_testfailed() {
print -r "Was testing: $ZTST_message" print -r "Was testing: $ZTST_message"
fi fi
print -r "$ZTST_testname: test failed." print -r "$ZTST_testname: test failed."
ZTST_cleanup ZTST_testfailed=1
exit 1 return 1
} }
# Print messages if $ZTST_verbose is non-empty # Print messages if $ZTST_verbose is non-empty
@ -114,7 +116,10 @@ ZTST_hashmark() {
(( SECONDS > COLUMNS+1 && (SECONDS -= COLUMNS) )) (( SECONDS > COLUMNS+1 && (SECONDS -= COLUMNS) ))
} }
[[ ! -r $ZTST_testname ]] && ZTST_testfailed "can't read test file." if [[ ! -r $ZTST_testname ]]; then
ZTST_testfailed "can't read test file."
exit 1
fi
exec 8>&1 exec 8>&1
exec 9<$ZTST_testname exec 9<$ZTST_testname
@ -136,15 +141,18 @@ ZTST_getline() {
# Get the name of the section. It may already have been read into # Get the name of the section. It may already have been read into
# $curline, or we may have to skip some initial comments to find it. # $curline, or we may have to skip some initial comments to find it.
# If argument present, it's OK to skip the reset of the current section,
# so no error if we find garbage.
ZTST_getsect() { ZTST_getsect() {
local match mbegin mend local match mbegin mend
while [[ $ZTST_curline != '%'(#b)([[:alnum:]]##)* ]]; do while [[ $ZTST_curline != '%'(#b)([[:alnum:]]##)* ]]; do
ZTST_getline || return 1 ZTST_getline || return 1
[[ $ZTST_curline = [[:blank:]]# ]] && continue [[ $ZTST_curline = [[:blank:]]# ]] && continue
if [[ $ZTST_curline != '%'[[:alnum:]]##* ]]; then if [[ $# -eq 0 && $ZTST_curline != '%'[[:alnum:]]##* ]]; then
ZTST_testfailed "bad line found before or after section: ZTST_testfailed "bad line found before or after section:
$ZTST_curline" $ZTST_curline"
exit 1
fi fi
done done
# have the next line ready waiting # have the next line ready waiting
@ -194,6 +202,7 @@ case $char in
'?') fn=$ZTST_err '?') fn=$ZTST_err
;; ;;
*) ZTST_testfailed "bad redir operator: $char" *) ZTST_testfailed "bad redir operator: $char"
return 1
;; ;;
esac esac
if [[ $ZTST_flags = *q* ]]; then if [[ $ZTST_flags = *q* ]]; then
@ -201,6 +210,8 @@ if [[ $ZTST_flags = *q* ]]; then
else else
print -r -- "$ZTST_redir" >>$fn print -r -- "$ZTST_redir" >>$fn
fi fi
return 0
} }
# Execute an indented chunk. Redirections will already have # Execute an indented chunk. Redirections will already have
@ -278,21 +289,23 @@ $ZTST_curline"
else else
ZTST_testfailed "expecting test status at: ZTST_testfailed "expecting test status at:
$ZTST_curline" $ZTST_curline"
return 1
fi fi
ZTST_getline ZTST_getline
found=1 found=1
;; ;;
'<'*) ZTST_getredir '<'*) ZTST_getredir || return 1
found=1 found=1
;; ;;
'>'*) ZTST_getredir '>'*) ZTST_getredir || return 1
found=1 found=1
;; ;;
'?'*) ZTST_getredir '?'*) ZTST_getredir || return 1
found=1 found=1
;; ;;
*) ZTST_testfailed "bad line in test block: *) ZTST_testfailed "bad line in test block:
$ZTST_curline" $ZTST_curline"
return 1
;; ;;
esac esac
done done
@ -311,6 +324,7 @@ $ZTST_curline"
$ZTST_code${$(<$ZTST_terr):+ $ZTST_code${$(<$ZTST_terr):+
Error output: Error output:
$(<$ZTST_terr)}" $(<$ZTST_terr)}"
return 1
fi fi
ZTST_verbose 2 "ZTST_test: test produced standard output: ZTST_verbose 2 "ZTST_test: test produced standard output:
@ -324,6 +338,7 @@ $(<$ZTST_terr)"
$ZTST_code${$(<$ZTST_terr):+ $ZTST_code${$(<$ZTST_terr):+
Error output: Error output:
$(<$ZTST_terr)}" $(<$ZTST_terr)}"
return 1
fi fi
if [[ $ZTST_flags != *D* ]] && ! ZTST_diff -c $ZTST_err $ZTST_terr; then if [[ $ZTST_flags != *D* ]] && ! ZTST_diff -c $ZTST_err $ZTST_terr; then
ZTST_testfailed "error output differs from expected as shown above for: ZTST_testfailed "error output differs from expected as shown above for:
@ -348,11 +363,13 @@ ZTST_sects=(prep 0 test 0 clean 0)
print "$ZTST_testname: starting." print "$ZTST_testname: starting."
# Now go through all the different sections until the end. # Now go through all the different sections until the end.
while ZTST_getsect; do ZTST_skipok=
while ZTST_getsect $ZTST_skipok; do
case $ZTST_cursect in case $ZTST_cursect in
prep) if (( ${ZTST_sects[prep]} + ${ZTST_sects[test]} + \ prep) if (( ${ZTST_sects[prep]} + ${ZTST_sects[test]} + \
${ZTST_sects[clean]} )); then ${ZTST_sects[clean]} )); then
ZTST_testfailed "\`prep' section must come first" ZTST_testfailed "\`prep' section must come first"
exit 1
fi fi
ZTST_prepclean ZTST_prepclean
ZTST_sects[prep]=1 ZTST_sects[prep]=1
@ -360,22 +377,28 @@ while ZTST_getsect; do
test) test)
if (( ${ZTST_sects[test]} + ${ZTST_sects[clean]} )); then if (( ${ZTST_sects[test]} + ${ZTST_sects[clean]} )); then
ZTST_testfailed "bad placement of \`test' section" ZTST_testfailed "bad placement of \`test' section"
exit 1
fi fi
# careful here: we can't execute ZTST_test before || or &&
# because that affects the behaviour of traps in the tests.
ZTST_test ZTST_test
(( $? )) && ZTST_skipok=1
ZTST_sects[test]=1 ZTST_sects[test]=1
;; ;;
clean) clean)
if (( ${ZTST_sects[test]} == 0 || ${ZTST_sects[clean]} )); then if (( ${ZTST_sects[test]} == 0 || ${ZTST_sects[clean]} )); then
ZTST_testfailed "bad use of \`clean' section" ZTST_testfailed "bad use of \`clean' section"
else
ZTST_prepclean 1
ZTST_sects[clean]=1
fi fi
ZTST_prepclean 1 ZTST_skipok=
ZTST_sects[clean]=1
;; ;;
*) ZTST_testfailed "bad section name: $ZTST_cursect" *) ZTST_testfailed "bad section name: $ZTST_cursect"
;; ;;
esac esac
done done
print "$ZTST_testname: all tests successful." (( $ZTST_testfailed )) || print "$ZTST_testname: all tests successful."
ZTST_cleanup ZTST_cleanup
exit 0 exit $(( ZTST_testfailed ))