zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: Slightly improve test harness
@ 2005-08-08 18:23 Thorsten Dahlheimer
  2005-08-09  7:39 ` Wayne Davison
  2005-08-11 15:45 ` Bart Schaefer
  0 siblings, 2 replies; 5+ messages in thread
From: Thorsten Dahlheimer @ 2005-08-08 18:23 UTC (permalink / raw)
  To: zsh-workers

[-- 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: PATCH: Slightly improve test harness
  2005-08-08 18:23 PATCH: Slightly improve test harness Thorsten Dahlheimer
@ 2005-08-09  7:39 ` Wayne Davison
  2005-08-15 16:02   ` Thorsten Dahlheimer
  2005-08-11 15:45 ` Bart Schaefer
  1 sibling, 1 reply; 5+ messages in thread
From: Wayne Davison @ 2005-08-09  7:39 UTC (permalink / raw)
  To: Thorsten Dahlheimer; +Cc: zsh-workers

On Mon, Aug 08, 2005 at 08:23:54PM +0200, Thorsten Dahlheimer wrote:
> - don't abort the test run if a testcase fails (unless there's a syntax
>   error in the test file)

That change results in an erroneous "Test successful" message when a
test fails and verbosity is at least 1.  Did you check if any of the
test cases expected the success of an earlier test in a later test?
If so, it might be best to just leave the abort-after-the-first-failure
behavior unchanged.

> - make sure cleanup is always performed when exiting

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.

In the meantime, I've checked in a change that just disables the trap
line (since zsh now complains about its incorrect syntax).

..wayne..


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: PATCH: Slightly improve test harness
  2005-08-08 18:23 PATCH: Slightly improve test harness Thorsten Dahlheimer
  2005-08-09  7:39 ` Wayne Davison
@ 2005-08-11 15:45 ` Bart Schaefer
  2005-08-15 16:02   ` Thorsten Dahlheimer
  1 sibling, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2005-08-11 15:45 UTC (permalink / raw)
  To: zsh-workers

On Mon, 8 Aug 2005, Thorsten Dahlheimer wrote:

> This patch makes the following changes to the test harness:
>
> - don't abort the test run if a testcase fails (unless there's a syntax
>   error in the test file)

As others have noted, the tests may be cascaded, expecting previous tests
to have finished successfully.  Please don't make this change.

> - improve progress bar

What was wrong with it before, and how does this differ?


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: PATCH: Slightly improve test harness
  2005-08-09  7:39 ` Wayne Davison
@ 2005-08-15 16:02   ` Thorsten Dahlheimer
  0 siblings, 0 replies; 5+ messages in thread
From: Thorsten Dahlheimer @ 2005-08-15 16:02 UTC (permalink / raw)
  To: Wayne Davison; +Cc: zsh-workers

[-- 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: PATCH: Slightly improve test harness
  2005-08-11 15:45 ` Bart Schaefer
@ 2005-08-15 16:02   ` Thorsten Dahlheimer
  0 siblings, 0 replies; 5+ messages in thread
From: Thorsten Dahlheimer @ 2005-08-15 16:02 UTC (permalink / raw)
  To: Bart Schaefer, zsh-workers

Bart Schaefer wrote:
> > - improve progress bar
> 
> What was wrong with it before, and how does this differ?

Looking at it again, I see now that there is actually nothing wrong
with it; I had just made a thinko.  (The only difference would have
been that the progress bar wouldn't have wrapped, but shrunk back
to the beginning of the line.)  So, never mind.

Thorsten


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-08-15 15:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-08-08 18:23 PATCH: Slightly improve test harness Thorsten Dahlheimer
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

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).