zsh-workers
 help / color / mirror / code / Atom feed
From: "Thorsten Dahlheimer" <tdahlheim@gmx.net>
To: "Wayne Davison" <wayned@users.sourceforge.net>
Cc: <zsh-workers@sunsite.dk>
Subject: Re: PATCH: Slightly improve test harness
Date: Mon, 15 Aug 2005 18:02:38 +0200	[thread overview]
Message-ID: <019001c5a1b2$c3f21500$e221fea9@pcdahl4201> (raw)
In-Reply-To: <20050809073927.GC12952@blorf.net>

[-- Attachment #1: Type: text/plain, Size: 652 bytes --]

Wayne Davison wrote:
> If so, it might be best to just leave the abort-after-the-first-failure
> behavior unchanged.

Ok, I've attached a new patch with this change undone.  It also corrects
an erroneous testcase in A06assign.ztst and replaces various hardcoded
paths to the newly-compiled zsh executable in the test files with
$ZTST_exe.
 
> That fixed trap code seems to make it impossible to Ctrl-C out of the
> tests, though I'm not sure why yet.  Perhaps it's a bug in trap
> handling, but zsh hangs when that cleanup trap in place and Ctrl-C is
> pressed.

I could reproduce this when running on linux, so I left the trap
commented out.

Thorsten

[-- Attachment #2: ztst_2.patch --]
[-- Type: application/octet-stream, Size: 11764 bytes --]

Index: Test/A01grammar.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/A01grammar.ztst,v
retrieving revision 1.12
diff -u -r1.12 A01grammar.ztst
--- Test/A01grammar.ztst	11 Apr 2005 10:23:57 -0000	1.12
+++ Test/A01grammar.ztst	15 Aug 2005 15:22:35 -0000
@@ -50,7 +50,7 @@
 #
 # Tests for `Precommand Modifiers'
 #
-  - $ZTST_testdir/../Src/zsh -fc "[[ \$0 = \"-$ZTST_testdir/../Src/zsh\" ]]"
+  - $ZTST_testdir/$ZTST_exe -fc "[[ \$0 = \"-$ZTST_testdir/$ZTST_exe\" ]]"
 0:`-' precommand modifier
 
   echo f*
@@ -441,18 +441,18 @@
 0:Handling of &&'s and ||'s with a for loop in between
 >no
 
-  $ZTST_testdir/../Src/zsh -f unmatched_quote.txt
+  $ZTST_testdir/$ZTST_exe -f unmatched_quote.txt
 1:Parse error with file causes non-zero exit status
 ?unmatched_quote.txt:2: unmatched '
 
-  $ZTST_testdir/../Src/zsh -f <unmatched_quote.txt
+  $ZTST_testdir/$ZTST_exe -f <unmatched_quote.txt
 1:Parse error on standard input causes non-zero exit status
 ?zsh: unmatched '
 
-  $ZTST_testdir/../Src/zsh -f -c "'"
+  $ZTST_testdir/$ZTST_exe -f -c "'"
 1:Parse error on inline command causes non-zero exit status
 ?zsh: unmatched '
 
-  $ZTST_testdir/../Src/zsh -f NonExistentScript
+  $ZTST_testdir/$ZTST_exe -f NonExistentScript
 127q:Non-existent script causes exit status 127
-?$ZTST_testdir/../Src/zsh: can't open input file: NonExistentScript
+?$ZTST_testdir/$ZTST_exe: can't open input file: NonExistentScript
Index: Test/A06assign.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/A06assign.ztst,v
retrieving revision 1.3
diff -u -r1.3 A06assign.ztst
--- Test/A06assign.ztst	2 Feb 2005 17:03:51 -0000	1.3
+++ Test/A06assign.ztst	15 Aug 2005 15:22:35 -0000
@@ -61,8 +61,8 @@
 0:add to float
 >5.7
 
- typeset -A hash
- hash=(one 1)
+ typeset -A h
+ h=(one 1)
  h+=string
  [[ $h[@] == string ]]
 0:add scalar to association
Index: Test/D02glob.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/D02glob.ztst,v
retrieving revision 1.11
diff -u -r1.11 D02glob.ztst
--- Test/D02glob.ztst	21 Jun 2005 08:58:46 -0000	1.11
+++ Test/D02glob.ztst	15 Aug 2005 15:22:36 -0000
@@ -6,7 +6,7 @@
   mkdir glob.tmp/dir3/subdir
   : >glob.tmp/{,{dir1,dir2}/}{a,b,c}
 
-  globtest () { $ZTST_testdir/../Src/zsh -f $ZTST_srcdir/../Misc/$1 }
+  globtest () { $ZTST_testdir/$ZTST_exe -f $ZTST_srcdir/../Misc/$1 }
 
   regress_absolute_path_and_core_dump() {
     local absolute_dir=$(cd glob.tmp && pwd -P)
Index: Test/Y01completion.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/Y01completion.ztst,v
retrieving revision 1.4
diff -u -r1.4 Y01completion.ztst
--- Test/Y01completion.ztst	11 Mar 2004 19:14:42 -0000	1.4
+++ Test/Y01completion.ztst	15 Aug 2005 15:22:39 -0000
@@ -5,7 +5,7 @@
     . $ZTST_srcdir/comptest
     mkdir comp.tmp
     cd comp.tmp
-    comptestinit -z $ZTST_testdir/../Src/zsh &&
+    comptestinit -z $ZTST_testdir/$ZTST_exe &&
     {
       mkdir dir1 &&
       mkdir dir2 &&
Index: Test/Y02compmatch.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/Y02compmatch.ztst,v
retrieving revision 1.3
diff -u -r1.3 Y02compmatch.ztst
--- Test/Y02compmatch.ztst	11 Mar 2004 19:14:42 -0000	1.3
+++ Test/Y02compmatch.ztst	15 Aug 2005 15:22:40 -0000
@@ -15,7 +15,7 @@
     . $ZTST_srcdir/comptest
     mkdir match.tmp
     cd match.tmp
-    comptestinit -z $ZTST_testdir/../Src/zsh &&
+    comptestinit -z $ZTST_testdir/$ZTST_exe &&
     {
       list1=(IndianRed IndianRed2 IndianRed3 IndianRed4)
       test_code () {
Index: Test/Y03arguments.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/Y03arguments.ztst,v
retrieving revision 1.6
diff -u -r1.6 Y03arguments.ztst
--- Test/Y03arguments.ztst	11 Mar 2004 19:14:42 -0000	1.6
+++ Test/Y03arguments.ztst	15 Aug 2005 15:22:41 -0000
@@ -5,7 +5,7 @@
     . $ZTST_srcdir/comptest
     mkdir comp.tmp
     cd comp.tmp
-    comptestinit -z $ZTST_testdir/../Src/zsh &&
+    comptestinit -z $ZTST_testdir/$ZTST_exe &&
     {
       comptesteval 'compdef _tst tst'
       tst_arguments () { comptesteval "_tst () { _arguments ${${(@qq)*}} }" }
Index: Test/ztst.zsh
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/ztst.zsh,v
retrieving revision 1.22
diff -u -r1.22 ztst.zsh
--- Test/ztst.zsh	9 Aug 2005 06:51:40 -0000	1.22
+++ Test/ztst.zsh	15 Aug 2005 15:22:43 -0000
@@ -118,18 +118,33 @@
 # we should try and arrange that any test-specific cleanup
 # always gets called as well.
 ##trap 'print cleaning up...
-##ZTST_cleanup' INT QUIT TERM
+##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,40 @@
   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) ))
 }
+# ...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 +194,8 @@
 
 # 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 +204,7 @@
 ZTST_getline() {
   local IFS=
   while true; do
+    (( ZTST_curlineno++ ))
     read -r ZTST_curline <&9 || return 1
     [[ $ZTST_curline == \#* ]] || return 0
   done
@@ -174,19 +212,17 @@
 
 # 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.
-# If argument present, it's OK to skip the reset of the current section,
+# If argument present, it's OK to skip the rest of the current section,
 # so no error if we find garbage.
 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 +270,7 @@
        ;;
   ('?') fn=$ZTST_err
        ;;
-   (*)  ZTST_testfailed "bad redir operator: $char"
+   (*)  ZTST_syntaxerror "bad redir operator: $char"
        return 1
        ;;
 esac
@@ -268,7 +304,7 @@
     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 +316,8 @@
   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 +325,9 @@
     
 ZTST_test() {
   local last match mbegin mend found
+  # 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 +363,7 @@
 	    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 +383,7 @@
 	  ZTST_getline
 	  found=1
           ;;
-	(*) ZTST_testfailed "bad line in test block:
-$ZTST_curline"
+	(*) ZTST_syntaxerror "bad line in test block:"
 	  return 1
           ;;
       esac
@@ -393,9 +431,6 @@
   done
 
   ZTST_verbose 2 "ZTST_test: all tests successful"
-
-  # reset message to keep ZTST_testfailed output correct
-  ZTST_message=''
 }
 
 
@@ -403,7 +438,7 @@
 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 +449,16 @@
   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 +468,16 @@
 	  ;;
     (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

  reply	other threads:[~2005-08-15 15:53 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-08-08 18:23 Thorsten Dahlheimer
2005-08-09  7:39 ` Wayne Davison
2005-08-15 16:02   ` Thorsten Dahlheimer [this message]
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='019001c5a1b2$c3f21500$e221fea9@pcdahl4201' \
    --to=tdahlheim@gmx.net \
    --cc=wayned@users.sourceforge.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).