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
