From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20427 invoked from network); 8 Aug 2005 18:15:28 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 8 Aug 2005 18:15:28 -0000 Received: (qmail 11859 invoked from network); 8 Aug 2005 18:15:22 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 8 Aug 2005 18:15:22 -0000 Received: (qmail 5050 invoked by alias); 8 Aug 2005 18:15:19 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 21580 Received: (qmail 5041 invoked from network); 8 Aug 2005 18:15:19 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 8 Aug 2005 18:15:19 -0000 Received: (qmail 11579 invoked from network); 8 Aug 2005 18:15:19 -0000 Received: from mail.gmx.net (213.165.64.20) by a.mx.sunsite.dk with SMTP; 8 Aug 2005 18:15:14 -0000 Received: (qmail invoked by alias); 08 Aug 2005 18:15:11 -0000 Received: from Bc93f.b.pppool.de (EHLO pcdahl4201) [213.7.201.63] by mail.gmx.net (mp016) with SMTP; 08 Aug 2005 20:15:11 +0200 X-Authenticated: #21620914 Message-ID: <028601c59c46$56d0dea0$cc74fea9@pcdahl4201> From: "Thorsten Dahlheimer" To: Subject: PATCH: Slightly improve test harness Date: Mon, 8 Aug 2005 20:23:54 +0200 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_027F_01C59C57.1943F8E0" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 X-Y-GMX-Trusted: 0 X-Spam-Checker-Version: SpamAssassin 3.0.4 (2005-06-05) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00, MIME_QP_LONG_LINE autolearn=ham version=3.0.4 This is a multi-part message in MIME format. ------=_NextPart_000_027F_01C59C57.1943F8E0 Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: 7bit 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 ------=_NextPart_000_027F_01C59C57.1943F8E0 Content-Type: application/octet-stream; name="ztst.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="ztst.patch" Index: Test/ztst.zsh=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= RCS file: /cvsroot/zsh/zsh/Test/ztst.zsh,v=0A= retrieving revision 1.21=0A= diff -u -p -r1.21 ztst.zsh=0A= --- Test/ztst.zsh 13 Jan 2005 10:34:21 -0000 1.21=0A= +++ Test/ztst.zsh 8 Aug 2005 16:43:55 -0000=0A= @@ -117,19 +117,34 @@ ZTST_cleanup() {=0A= # This cleanup always gets performed, even if we abort. Later,=0A= # we should try and arrange that any test-specific cleanup=0A= # always gets called as well.=0A= -trap - 'print cleaning up...=0A= -ZTST_cleanup' INT QUIT TERM=0A= +trap 'print cleaning up...=0A= +ZTST_cleanup=0A= +exit 2' INT QUIT TERM=0A= # Make sure it's clean now.=0A= rm -rf dummy.tmp *.tmp=0A= =0A= +# Exit from this test run. Print test result, clean up,=0A= +# and set exit status according to $ZTST_testfailed.=0A= +ZTST_exit() {=0A= + if [[ -n "$ZTST_unimplemented" ]]; then=0A= + print -r "$ZTST_testname: skipped ($ZTST_unimplemented)"=0A= + elif (( $ZTST_testfailed )); then=0A= + print -r "$ZTST_testname: test failed."=0A= + else=0A= + print -r "$ZTST_testname: all tests successful."=0A= + fi=0A= + ZTST_cleanup=0A= + exit $(( ZTST_testfailed ))=0A= +}=0A= +=0A= # Report failure. Note that all output regarding the tests goes to = stdout.=0A= # That saves an unpleasant mixture of stdout and stderr to sort out.=0A= ZTST_testfailed() {=0A= + ZTST_clearline=0A= print -r "Test $ZTST_testname failed: $1"=0A= if [[ -n $ZTST_message ]]; then=0A= print -r "Was testing: $ZTST_message"=0A= fi=0A= - print -r "$ZTST_testname: test failed."=0A= if [[ -n $ZTST_failmsg ]]; then=0A= print -r "The following may (or may not) help identifying the cause:=0A= $ZTST_failmsg"=0A= @@ -138,20 +153,42 @@ $ZTST_failmsg"=0A= return 1=0A= }=0A= =0A= +# Report a syntax error in the test file.=0A= +ZTST_syntaxerror() {=0A= + # Don't print the test-specific messages in this case=0A= + local ZTST_message=3D'' ZTST_failmsg=3D''=0A= + if [[ $1 =3D=3D *: ]]; then=0A= + ZTST_testfailed "$1=0A= +line $ZTST_curlineno: $ZTST_curline"=0A= + else=0A= + ZTST_testfailed "$1 (near line $ZTST_curlineno)"=0A= + fi=0A= +}=0A= +=0A= # Print messages if $ZTST_verbose is non-empty=0A= ZTST_verbose() {=0A= local lev=3D$1=0A= shift=0A= [[ -n $ZTST_verbose && $ZTST_verbose -ge $lev ]] && print -r -- $* >&8=0A= }=0A= +=0A= +# Print progress indicator if not verbose...=0A= ZTST_hashmark() {=0A= - [[ ZTST_verbose -le 0 && -t 8 ]] && print -nu8 = ${(pl:SECONDS::\#::\#\r:)}=0A= - (( SECONDS > COLUMNS+1 && (SECONDS -=3D COLUMNS) ))=0A= + (( SECONDS > COLUMNS && (SECONDS -=3D COLUMNS) ))=0A= + if [[ ZTST_verbose -le 0 && -t 8 ]]; then=0A= + print -nu8 ${(l:COLUMNS::#:)${(l:COLUMNS-SECONDS:)}}'\r'=0A= + fi=0A= +}=0A= +# ...and clear it again.=0A= +ZTST_clearline() {=0A= + if [[ ZTST_verbose -le 0 && -t 8 ]]; then=0A= + print -nu8 ${(l:COLUMNS:)}'\r'=0A= + fi=0A= }=0A= =0A= if [[ ! -r $ZTST_testname ]]; then=0A= ZTST_testfailed "can't read test file."=0A= - exit 1=0A= + ZTST_exit=0A= fi=0A= =0A= exec 8>&1=0A= @@ -159,6 +196,8 @@ exec 9<$ZTST_testname=0A= =0A= # The current line read from the test file.=0A= ZTST_curline=3D''=0A= +# The current line number=0A= +integer ZTST_curlineno=3D0=0A= # The current section being run=0A= ZTST_cursect=3D''=0A= =0A= @@ -167,6 +206,7 @@ ZTST_cursect=3D''=0A= ZTST_getline() {=0A= local IFS=3D=0A= while true; do=0A= + (( ZTST_curlineno++ ))=0A= read -r ZTST_curline <&9 || return 1=0A= [[ $ZTST_curline =3D=3D \#* ]] || return 0=0A= done=0A= @@ -180,13 +220,11 @@ ZTST_getsect() {=0A= local match mbegin mend=0A= =0A= while [[ $ZTST_curline !=3D '%'(#b)([[:alnum:]]##)* ]]; do=0A= - ZTST_getline || return 1=0A= - [[ $ZTST_curline =3D [[:blank:]]# ]] && continue=0A= - if [[ $# -eq 0 && $ZTST_curline !=3D '%'[[:alnum:]]##* ]]; then=0A= - ZTST_testfailed "bad line found before or after section:=0A= -$ZTST_curline"=0A= - exit 1=0A= + if [[ $# -eq 0 && $ZTST_curline !=3D [[:blank:]]# ]]; then=0A= + ZTST_syntaxerror "bad line found before or after section:"=0A= + ZTST_exit=0A= fi=0A= + ZTST_getline || return 1=0A= done=0A= # have the next line ready waiting=0A= ZTST_getline=0A= @@ -234,7 +272,7 @@ case $char in=0A= ;;=0A= ('?') fn=3D$ZTST_err=0A= ;;=0A= - (*) ZTST_testfailed "bad redir operator: $char"=0A= + (*) ZTST_syntaxerror "bad redir operator: $char"=0A= return 1=0A= ;;=0A= esac=0A= @@ -268,7 +306,7 @@ ZTST_prepclean() {=0A= ZTST_execchunk >/dev/null || [[ -n $1 ]] || {=0A= [[ -n "$ZTST_unimplemented" ]] ||=0A= ZTST_testfailed "non-zero status from preparation code:=0A= -$ZTST_code" && return 0=0A= +$ZTST_code" && return 1=0A= }=0A= done=0A= }=0A= @@ -280,7 +318,8 @@ ZTST_diff() {=0A= diff_out=3D$(diff "$@")=0A= diff_ret=3D"$?"=0A= if [[ "$diff_ret" !=3D "0" ]]; then=0A= - echo "$diff_out"=0A= + ZTST_clearline=0A= + print -r -- "$diff_out"=0A= fi=0A= =0A= return "$diff_ret"=0A= @@ -288,6 +327,10 @@ ZTST_diff() {=0A= =0A= ZTST_test() {=0A= local last match mbegin mend found=0A= + local -i failed=3D0=0A= + # Make sure messages are reset upon exit from this function=0A= + # to keep ZTST_testfailed output correct=0A= + local ZTST_message ZTST_failmsg=0A= =0A= while true; do=0A= rm -f $ZTST_in $ZTST_out $ZTST_err=0A= @@ -323,8 +366,7 @@ $ZTST_curline"=0A= ZTST_flags=3D$match[2]=0A= ZTST_message=3D${match[3]:+${match[3][2,-1]}}=0A= else=0A= - ZTST_testfailed "expecting test status at:=0A= -$ZTST_curline"=0A= + ZTST_syntaxerror "expecting test status at:"=0A= return 1=0A= fi=0A= ZTST_getline=0A= @@ -344,8 +386,7 @@ $ZTST_curline"=0A= ZTST_getline=0A= found=3D1=0A= ;;=0A= - (*) ZTST_testfailed "bad line in test block:=0A= -$ZTST_curline"=0A= + (*) ZTST_syntaxerror "bad line in test block:"=0A= return 1=0A= ;;=0A= esac=0A= @@ -366,7 +407,7 @@ $ZTST_curline"=0A= $ZTST_code${$(<$ZTST_terr):+=0A= Error output:=0A= $(<$ZTST_terr)}"=0A= - return 1=0A= + (( failed++ ))=0A= fi=0A= =0A= ZTST_verbose 2 "ZTST_test: test produced standard output:=0A= @@ -380,22 +421,25 @@ $(<$ZTST_terr)"=0A= $ZTST_code${$(<$ZTST_terr):+=0A= Error output:=0A= $(<$ZTST_terr)}"=0A= - return 1=0A= + (( failed++ ))=0A= fi=0A= if [[ $ZTST_flags !=3D *D* ]] && ! ZTST_diff -c $ZTST_err = $ZTST_terr; then=0A= ZTST_testfailed "error output differs from expected as shown above for:=0A= $ZTST_code"=0A= - return 1=0A= + (( failed++ ))=0A= fi=0A= fi=0A= ZTST_verbose 1 "Test successful."=0A= [[ -n $last ]] && break=0A= done=0A= =0A= - ZTST_verbose 2 "ZTST_test: all tests successful"=0A= -=0A= - # reset message to keep ZTST_testfailed output correct=0A= - ZTST_message=3D''=0A= + ZTST_clearline=0A= + if [[ $failed -gt 0 ]]; then=0A= + ZTST_verbose 2 "ZTST_test: $failed tests failed"=0A= + else=0A= + ZTST_verbose 2 "ZTST_test: all tests successful"=0A= + fi=0A= + return $failed=0A= }=0A= =0A= =0A= @@ -403,7 +447,7 @@ $ZTST_code"=0A= typeset -A ZTST_sects=0A= ZTST_sects=3D(prep 0 test 0 clean 0)=0A= =0A= -print "$ZTST_testname: starting."=0A= +print -r "$ZTST_testname: starting."=0A= =0A= # Now go through all the different sections until the end.=0A= # prep section may set ZTST_unimplemented, in this case the actual=0A= @@ -414,16 +458,16 @@ while [[ -z "$ZTST_unimplemented" ]] && =0A= case $ZTST_cursect in=0A= (prep) if (( ${ZTST_sects[prep]} + ${ZTST_sects[test]} + \=0A= ${ZTST_sects[clean]} )); then=0A= - ZTST_testfailed "\`prep' section must come first"=0A= - exit 1=0A= + ZTST_syntaxerror "\`prep' section must come first"=0A= + ZTST_exit=0A= fi=0A= - ZTST_prepclean=0A= + ZTST_prepclean || ZTST_exit=0A= ZTST_sects[prep]=3D1=0A= ;;=0A= (test)=0A= if (( ${ZTST_sects[test]} + ${ZTST_sects[clean]} )); then=0A= - ZTST_testfailed "bad placement of \`test' section"=0A= - exit 1=0A= + ZTST_syntaxerror "bad placement of \`test' section"=0A= + ZTST_exit=0A= fi=0A= # careful here: we can't execute ZTST_test before || or &&=0A= # because that affects the behaviour of traps in the tests.=0A= @@ -433,22 +477,16 @@ while [[ -z "$ZTST_unimplemented" ]] && =0A= ;;=0A= (clean)=0A= if (( ${ZTST_sects[test]} =3D=3D 0 || ${ZTST_sects[clean]} )); then=0A= - ZTST_testfailed "bad use of \`clean' section"=0A= + ZTST_syntaxerror "bad use of \`clean' section"=0A= else=0A= ZTST_prepclean 1=0A= ZTST_sects[clean]=3D1=0A= fi=0A= ZTST_skipok=3D=0A= ;;=0A= - *) ZTST_testfailed "bad section name: $ZTST_cursect"=0A= + (*) ZTST_syntaxerror "bad section name: $ZTST_cursect"=0A= ;;=0A= esac=0A= done=0A= =0A= -if [[ -n "$ZTST_unimplemented" ]]; then=0A= - print "$ZTST_testname: skipped ($ZTST_unimplemented)"=0A= -elif (( ! $ZTST_testfailed )); then=0A= - print "$ZTST_testname: all tests successful."=0A= -fi=0A= -ZTST_cleanup=0A= -exit $(( ZTST_testfailed ))=0A= +ZTST_exit=0A= Index: Test/C03traps.ztst=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= RCS file: /cvsroot/zsh/zsh/Test/C03traps.ztst,v=0A= retrieving revision 1.7=0A= diff -u -p -r1.7 C03traps.ztst=0A= --- Test/C03traps.ztst 1 May 2005 01:23:54 -0000 1.7=0A= +++ Test/C03traps.ztst 8 Aug 2005 14:47:17 -0000=0A= @@ -65,6 +65,7 @@=0A= >Exited.=0A= =0A= fn1() {=0A= + trap -=0A= trap=0A= trap 'print INT1' INT=0A= fn2() { trap 'print INT2' INT; trap; }=0A= @@ -79,6 +80,7 @@=0A= >trap -- 'print INT1' INT=0A= =0A= fn1() {=0A= + trap -=0A= trap=0A= TRAPINT() { print INT1; }=0A= fn2() { TRAPINT() { print INT2; }; trap; }=0A= @@ -87,7 +89,7 @@=0A= trap=0A= }=0A= fn1=0A= -0: Nested `trap ... INT', not triggered=0A= +0: Nested TRAPINT, not triggered=0A= >TRAPINT () {=0A= > print INT1=0A= >}=0A= @@ -99,6 +101,7 @@=0A= >}=0A= =0A= fn1() {=0A= + trap -=0A= trap 'print INT1' INT=0A= fn2() { trap - INT; trap; }=0A= trap=0A= ------=_NextPart_000_027F_01C59C57.1943F8E0--