From: "Thorsten Dahlheimer" <tdahlheim@gmx.net>
To: <zsh-workers@sunsite.dk>
Subject: PATCH: Slightly improve test harness
Date: Mon, 8 Aug 2005 20:23:54 +0200 [thread overview]
Message-ID: <028601c59c46$56d0dea0$cc74fea9@pcdahl4201> (raw)
[-- Attachment #1: Type: text/plain, Size: 694 bytes --]
This patch makes the following changes to the test harness:
- abort the test if %prep code returns a non-zero status, as is
documented in B01cd.ztst
- don't abort the test run if a testcase fails (unless there's a syntax
error in the test file)
- make sure cleanup is always performed when exiting
- ZTST_getsect() used to always tolerate one junk line immediately
before the beginning of a section; correct that
- don't print ZTST_message and ZTST_failmsg for syntax errors in the
test file; instead always print the line number in that case
- make sure ZTST_message and ZTST_failmsg are always cleared upon exit
from ZTST_test()
- improve progress bar
Regards,
Thorsten Dahlheimer
[-- Attachment #2: ztst.patch --]
[-- Type: application/octet-stream, Size: 9258 bytes --]
Index: Test/ztst.zsh
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/ztst.zsh,v
retrieving revision 1.21
diff -u -p -r1.21 ztst.zsh
--- Test/ztst.zsh 13 Jan 2005 10:34:21 -0000 1.21
+++ Test/ztst.zsh 8 Aug 2005 16:43:55 -0000
@@ -117,19 +117,34 @@ ZTST_cleanup() {
# This cleanup always gets performed, even if we abort. Later,
# we should try and arrange that any test-specific cleanup
# always gets called as well.
-trap - 'print cleaning up...
-ZTST_cleanup' INT QUIT TERM
+trap 'print cleaning up...
+ZTST_cleanup
+exit 2' INT QUIT TERM
# Make sure it's clean now.
rm -rf dummy.tmp *.tmp
+# Exit from this test run. Print test result, clean up,
+# and set exit status according to $ZTST_testfailed.
+ZTST_exit() {
+ if [[ -n "$ZTST_unimplemented" ]]; then
+ print -r "$ZTST_testname: skipped ($ZTST_unimplemented)"
+ elif (( $ZTST_testfailed )); then
+ print -r "$ZTST_testname: test failed."
+ else
+ print -r "$ZTST_testname: all tests successful."
+ fi
+ ZTST_cleanup
+ exit $(( ZTST_testfailed ))
+}
+
# Report failure. Note that all output regarding the tests goes to stdout.
# That saves an unpleasant mixture of stdout and stderr to sort out.
ZTST_testfailed() {
+ ZTST_clearline
print -r "Test $ZTST_testname failed: $1"
if [[ -n $ZTST_message ]]; then
print -r "Was testing: $ZTST_message"
fi
- print -r "$ZTST_testname: test failed."
if [[ -n $ZTST_failmsg ]]; then
print -r "The following may (or may not) help identifying the cause:
$ZTST_failmsg"
@@ -138,20 +153,42 @@ $ZTST_failmsg"
return 1
}
+# Report a syntax error in the test file.
+ZTST_syntaxerror() {
+ # Don't print the test-specific messages in this case
+ local ZTST_message='' ZTST_failmsg=''
+ if [[ $1 == *: ]]; then
+ ZTST_testfailed "$1
+line $ZTST_curlineno: $ZTST_curline"
+ else
+ ZTST_testfailed "$1 (near line $ZTST_curlineno)"
+ fi
+}
+
# Print messages if $ZTST_verbose is non-empty
ZTST_verbose() {
local lev=$1
shift
[[ -n $ZTST_verbose && $ZTST_verbose -ge $lev ]] && print -r -- $* >&8
}
+
+# Print progress indicator if not verbose...
ZTST_hashmark() {
- [[ ZTST_verbose -le 0 && -t 8 ]] && print -nu8 ${(pl:SECONDS::\#::\#\r:)}
- (( SECONDS > COLUMNS+1 && (SECONDS -= COLUMNS) ))
+ (( SECONDS > COLUMNS && (SECONDS -= COLUMNS) ))
+ if [[ ZTST_verbose -le 0 && -t 8 ]]; then
+ print -nu8 ${(l:COLUMNS::#:)${(l:COLUMNS-SECONDS:)}}'\r'
+ fi
+}
+# ...and clear it again.
+ZTST_clearline() {
+ if [[ ZTST_verbose -le 0 && -t 8 ]]; then
+ print -nu8 ${(l:COLUMNS:)}'\r'
+ fi
}
if [[ ! -r $ZTST_testname ]]; then
ZTST_testfailed "can't read test file."
- exit 1
+ ZTST_exit
fi
exec 8>&1
@@ -159,6 +196,8 @@ exec 9<$ZTST_testname
# The current line read from the test file.
ZTST_curline=''
+# The current line number
+integer ZTST_curlineno=0
# The current section being run
ZTST_cursect=''
@@ -167,6 +206,7 @@ ZTST_cursect=''
ZTST_getline() {
local IFS=
while true; do
+ (( ZTST_curlineno++ ))
read -r ZTST_curline <&9 || return 1
[[ $ZTST_curline == \#* ]] || return 0
done
@@ -180,13 +220,11 @@ ZTST_getsect() {
local match mbegin mend
while [[ $ZTST_curline != '%'(#b)([[:alnum:]]##)* ]]; do
- ZTST_getline || return 1
- [[ $ZTST_curline = [[:blank:]]# ]] && continue
- if [[ $# -eq 0 && $ZTST_curline != '%'[[:alnum:]]##* ]]; then
- ZTST_testfailed "bad line found before or after section:
-$ZTST_curline"
- exit 1
+ if [[ $# -eq 0 && $ZTST_curline != [[:blank:]]# ]]; then
+ ZTST_syntaxerror "bad line found before or after section:"
+ ZTST_exit
fi
+ ZTST_getline || return 1
done
# have the next line ready waiting
ZTST_getline
@@ -234,7 +272,7 @@ case $char in
;;
('?') fn=$ZTST_err
;;
- (*) ZTST_testfailed "bad redir operator: $char"
+ (*) ZTST_syntaxerror "bad redir operator: $char"
return 1
;;
esac
@@ -268,7 +306,7 @@ ZTST_prepclean() {
ZTST_execchunk >/dev/null || [[ -n $1 ]] || {
[[ -n "$ZTST_unimplemented" ]] ||
ZTST_testfailed "non-zero status from preparation code:
-$ZTST_code" && return 0
+$ZTST_code" && return 1
}
done
}
@@ -280,7 +318,8 @@ ZTST_diff() {
diff_out=$(diff "$@")
diff_ret="$?"
if [[ "$diff_ret" != "0" ]]; then
- echo "$diff_out"
+ ZTST_clearline
+ print -r -- "$diff_out"
fi
return "$diff_ret"
@@ -288,6 +327,10 @@ ZTST_diff() {
ZTST_test() {
local last match mbegin mend found
+ local -i failed=0
+ # Make sure messages are reset upon exit from this function
+ # to keep ZTST_testfailed output correct
+ local ZTST_message ZTST_failmsg
while true; do
rm -f $ZTST_in $ZTST_out $ZTST_err
@@ -323,8 +366,7 @@ $ZTST_curline"
ZTST_flags=$match[2]
ZTST_message=${match[3]:+${match[3][2,-1]}}
else
- ZTST_testfailed "expecting test status at:
-$ZTST_curline"
+ ZTST_syntaxerror "expecting test status at:"
return 1
fi
ZTST_getline
@@ -344,8 +386,7 @@ $ZTST_curline"
ZTST_getline
found=1
;;
- (*) ZTST_testfailed "bad line in test block:
-$ZTST_curline"
+ (*) ZTST_syntaxerror "bad line in test block:"
return 1
;;
esac
@@ -366,7 +407,7 @@ $ZTST_curline"
$ZTST_code${$(<$ZTST_terr):+
Error output:
$(<$ZTST_terr)}"
- return 1
+ (( failed++ ))
fi
ZTST_verbose 2 "ZTST_test: test produced standard output:
@@ -380,22 +421,25 @@ $(<$ZTST_terr)"
$ZTST_code${$(<$ZTST_terr):+
Error output:
$(<$ZTST_terr)}"
- return 1
+ (( failed++ ))
fi
if [[ $ZTST_flags != *D* ]] && ! ZTST_diff -c $ZTST_err $ZTST_terr; then
ZTST_testfailed "error output differs from expected as shown above for:
$ZTST_code"
- return 1
+ (( failed++ ))
fi
fi
ZTST_verbose 1 "Test successful."
[[ -n $last ]] && break
done
- ZTST_verbose 2 "ZTST_test: all tests successful"
-
- # reset message to keep ZTST_testfailed output correct
- ZTST_message=''
+ ZTST_clearline
+ if [[ $failed -gt 0 ]]; then
+ ZTST_verbose 2 "ZTST_test: $failed tests failed"
+ else
+ ZTST_verbose 2 "ZTST_test: all tests successful"
+ fi
+ return $failed
}
@@ -403,7 +447,7 @@ $ZTST_code"
typeset -A ZTST_sects
ZTST_sects=(prep 0 test 0 clean 0)
-print "$ZTST_testname: starting."
+print -r "$ZTST_testname: starting."
# Now go through all the different sections until the end.
# prep section may set ZTST_unimplemented, in this case the actual
@@ -414,16 +458,16 @@ while [[ -z "$ZTST_unimplemented" ]] &&
case $ZTST_cursect in
(prep) if (( ${ZTST_sects[prep]} + ${ZTST_sects[test]} + \
${ZTST_sects[clean]} )); then
- ZTST_testfailed "\`prep' section must come first"
- exit 1
+ ZTST_syntaxerror "\`prep' section must come first"
+ ZTST_exit
fi
- ZTST_prepclean
+ ZTST_prepclean || ZTST_exit
ZTST_sects[prep]=1
;;
(test)
if (( ${ZTST_sects[test]} + ${ZTST_sects[clean]} )); then
- ZTST_testfailed "bad placement of \`test' section"
- exit 1
+ ZTST_syntaxerror "bad placement of \`test' section"
+ ZTST_exit
fi
# careful here: we can't execute ZTST_test before || or &&
# because that affects the behaviour of traps in the tests.
@@ -433,22 +477,16 @@ while [[ -z "$ZTST_unimplemented" ]] &&
;;
(clean)
if (( ${ZTST_sects[test]} == 0 || ${ZTST_sects[clean]} )); then
- ZTST_testfailed "bad use of \`clean' section"
+ ZTST_syntaxerror "bad use of \`clean' section"
else
ZTST_prepclean 1
ZTST_sects[clean]=1
fi
ZTST_skipok=
;;
- *) ZTST_testfailed "bad section name: $ZTST_cursect"
+ (*) ZTST_syntaxerror "bad section name: $ZTST_cursect"
;;
esac
done
-if [[ -n "$ZTST_unimplemented" ]]; then
- print "$ZTST_testname: skipped ($ZTST_unimplemented)"
-elif (( ! $ZTST_testfailed )); then
- print "$ZTST_testname: all tests successful."
-fi
-ZTST_cleanup
-exit $(( ZTST_testfailed ))
+ZTST_exit
Index: Test/C03traps.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/C03traps.ztst,v
retrieving revision 1.7
diff -u -p -r1.7 C03traps.ztst
--- Test/C03traps.ztst 1 May 2005 01:23:54 -0000 1.7
+++ Test/C03traps.ztst 8 Aug 2005 14:47:17 -0000
@@ -65,6 +65,7 @@
>Exited.
fn1() {
+ trap -
trap
trap 'print INT1' INT
fn2() { trap 'print INT2' INT; trap; }
@@ -79,6 +80,7 @@
>trap -- 'print INT1' INT
fn1() {
+ trap -
trap
TRAPINT() { print INT1; }
fn2() { TRAPINT() { print INT2; }; trap; }
@@ -87,7 +89,7 @@
trap
}
fn1
-0: Nested `trap ... INT', not triggered
+0: Nested TRAPINT, not triggered
>TRAPINT () {
> print INT1
>}
@@ -99,6 +101,7 @@
>}
fn1() {
+ trap -
trap 'print INT1' INT
fn2() { trap - INT; trap; }
trap
next reply other threads:[~2005-08-08 18:15 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-08-08 18:23 Thorsten Dahlheimer [this message]
2005-08-09 7:39 ` Wayne Davison
2005-08-15 16:02 ` Thorsten Dahlheimer
2005-08-11 15:45 ` Bart Schaefer
2005-08-15 16:02 ` Thorsten Dahlheimer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='028601c59c46$56d0dea0$cc74fea9@pcdahl4201' \
--to=tdahlheim@gmx.net \
--cc=zsh-workers@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).