<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>getopts_long.sh</filename>
    </added>
    <added>
      <filename>test/unit/test-dbg-opts.sh.in</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -1 +1,8 @@
 R. Bernstein (rocky@gnu.org)
+
+Kate Ward is the author of shunit2 used in unit testing
+
+St&#233;phane Chazelas is the author of getopts_long.sh for GNU long options 
+         processing 
+
+Nikolaj Schumacher is the author of elk-test.el used in GNU Emacs testing</diff>
      <filename>AUTHORS</filename>
    </modified>
    <modified>
      <diff>@@ -1,3 +1,19 @@
+#   Copyright (C) 2008 Rocky Bernstein rocky@gnu.org
+#
+#   zshdb is free software; you can redistribute it and/or modify it under
+#   the terms of the GNU General Public License as published by the Free
+#   Software Foundation; either version 2, or (at your option) any later
+#   version.
+#
+#   zshdb is distributed in the hope that it will be useful, but WITHOUT ANY
+#   WARRANTY; without even the implied warranty of MERCHANTABILITY or
+#   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+#   for more details.
+#   
+#   You should have received a copy of the GNU General Public License along
+#   with zshdb; see the file COPYING.  If not, write to the Free Software
+#   Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+
 SUBDIRS = command emacs lib test
 
 pkgdata_DATA =       \
@@ -5,12 +21,13 @@ pkgdata_DATA =       \
 	dbg-io.sh    \
 	dbg-main.sh  \
 	dbg-opts.sh  \
-	dbg-trace.sh
+	dbg-trace.sh \
+	getopts_long.sh
 
 # Set up the install target 
 bin_SCRIPTS = kshdb
 
-EXTRA_DIST = $(pkgdata_DATA) THANKS getopt-test.sh
+EXTRA_DIST = $(pkgdata_DATA) THANKS
 
 # cvs2cl
 MAINTAINERCLEANFILES = ChangeLog
@@ -36,5 +53,3 @@ ACLOCAL_AMFLAGS=-I .
 endif
 
 .PHONY: $(CL) test
-
-</diff>
      <filename>Makefile.am</filename>
    </modified>
    <modified>
      <diff>@@ -1,2 +1,5 @@
 Thanks to David Korn for the adding necessary support to ksh
 needed to get this off the ground and make debugging possible.
+
+Thanks to Kate Ward, St&#233;phane Chazelas and Nikolaj Schumacher for
+programs used in conjunction with zshdb.</diff>
      <filename>THANKS</filename>
    </modified>
    <modified>
      <diff>@@ -6,26 +6,6 @@ AM_PATH_LISPDIR
 AM_MAINTAINER_MODE
 AM_INIT_AUTOMAKE([no-define])
 
-AC_SUBST(TRY_GETOPT)
-
-AC_ARG_ENABLE([gnugetopt],
-	AC_HELP_STRING([--enable-getopt], 
-	[Allow GNU-style long options (default enabled)]))
-
-if test &quot;${enable_getopt}&quot; != &quot;no&quot; ; then
-  $SH_PROG ${srcdir}/getopt-test.sh
-  if test $? -eq 0 ; then
-    AC_MSG_RESULT([Good! Your long options seem to be working okay.])
-    TRY_GETOPT=1
-  else
-    AC_MSG_WARN([getopt doesn't seem to handle long options correctly.])
-    AC_MSG_WARN([Disabling long-options in] DEBUGGER[.])
-    TRY_GETOPT=0
-  fi  
-else
-  TRY_GETOPT=0
-fi
-
 AC_CONFIG_SRCDIR(DEBUGGER.in)
 if test x$srcdir = x ; then
   srcdir=$ac_pwd
@@ -48,8 +28,8 @@ then
 fi
 
 if test &quot;$SH_PROG&quot; = no; then
-  AC_MSG_ERROR([I didn't find the DEBUGGER executable.\
-  You might want to use the --with-DEBUGGER option.])
+  AC_MSG_ERROR([I didn't find the] POSIXSHELL [executable.\
+  You might want to use the] --with-POSIXSHELL [option.])
 fi
 
 AC_MSG_CHECKING([Checking whether $SH_PROG is compatible with DEBUGGER])
@@ -98,7 +78,8 @@ else
   fi
 fi
 
-AM_CONDITIONAL(INSTALL_EMACS_LISP, test &quot;x$lispdir&quot; != &quot;x&quot;)
+AM_CONDITIONAL(INSTALL_EMACS_LISP, 
+	       [test &quot;x$lispdir&quot; != &quot;x&quot; -a &quot;x$EMACS&quot; != &quot;xno&quot;])
 
 AC_CONFIG_FILES([ \
 	Makefile \
@@ -121,6 +102,8 @@ AC_CONFIG_FILES([test/example/hanoi.sh],
 AC_CONFIG_FILES([test/unit/test-alias.sh], [chmod +x test/unit/test-alias.sh])
 AC_CONFIG_FILES([test/unit/test-columns.sh], 
                 [chmod +x test/unit/test-columns.sh])
+AC_CONFIG_FILES([test/unit/test-dbg-opts.sh], 
+                [chmod +x test/unit/test-dbg-opts.sh])
 AC_CONFIG_FILES([test/unit/test-filecache.sh],
 	        [chmod +x test/unit/test-filecache.sh])
 AC_CONFIG_FILES([test/unit/test-fns.sh],   [chmod +x test/unit/test-fns.sh])</diff>
      <filename>configure.ac</filename>
    </modified>
    <modified>
      <diff>@@ -17,154 +17,139 @@
 #   with kshdb; see the file COPYING.  If not, write to the Free Software
 #   Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
 
-typeset    _Dbg_tmpdir=/tmp
-typeset -i _Dbg_opt_linetrace=0
-typeset -i o_no_quit=0 
+_Dbg_usage() {
+  printf &quot;Usage: 
+   ${_Dbg_pname} [OPTIONS] &lt;script_file&gt;
 
-# Use gdb-style annotate?
-typeset -i _Dbg_annotate=0
-
-function _Dbg_usage_long {
-  printf &quot;usage:
-    ${_Dbg_pname} [OPTIONS] &lt;script_file&gt;
-
-Runs bash &lt;script_file&gt; under a debugger.
+Runs zsh &lt;script_file&gt; under a debugger.
 
-options: 
-    -A | --annotate  LEVEL  set annotation level.
-    -B | --basename         basename only on source listings. 
+options:
+    -h | --help             Print this help.
+    -q | --quiet            Do not print introductory and quiet messages.
+    -A | --annotate  LEVEL  Set the annotation level.
+    -B | --basename         Show basename only on source file listings. 
                             (Needed in regression tests)
-    -h | --help             print this help
-    -n | --nx |--no-init    Don't run initialization files
-    -c cmd | --eval-command cmd  Run this passed argument as a script
-    -q | --quiet     Quiet. Do not print introductory and quiet messages.
     -L libdir | --library libdir
-                            set directory location of library helper file: $_Dbg_main
-                            The default directory is: $_Dbg_libdir
-    -T tmpdir | --tempdir   set directory location for temporary files: $_Dbg_tmpdir
-    -t tty | --tty tty | --terminal tty
-                            set debugger terminal
-    -x command | --command cmdfile
-                            execute debugger commands from cmdfile
-    -X | --trace            set line tracing
-    -V | --version          show version number and no-warranty and exit.
-
-Long options may be abbreviated, e.g. --lib is okay for --library.
-&quot; 1&gt;&amp;2
+                            Set the directory location of library helper file: $_Dbg_main
+    -n | --nx | --no-init   Don't run initialization files.
+    -V | --version          Print the debugger version number.
+    -x command | --command CMDFILE
+                            Execute debugger commands from CMDFILE.
+&quot; &gt;&amp;2
+  exit 100
 }
 
-_Dbg_usage_short() {
-  printf &quot;_Dbg_usage:
-    ${_Dbg_pname} [OPTIONS] &lt;script_file&gt;
-
-Runs script_file under a debugger.
-
-options: 
-    -A LEVEL     set annotation level.
-    -B           basename only on source listings. (Needed in regression tests)
-    -h           print this help
-    -n           Don't run initialization files
-    -c command   Run this passed command as a script
-    -q           Quiet. Do not print introductory and quiet messages.
-    -L libdir | --library libdir   
-                 set directory location of library helper file: $_Dbg_main
-                 the default directory is: $_Dbg_libdir
-    -T tmpdir    set directory location for temporary files: $_Dbg_tmpdir
-    -t tty       set debugger terminal
-    -x cmdfile   execute debugger commands from cmdfile
-    -X           set line tracing
-    -Y           set line tracing with variable expansion
-    -V           show version number and no-warranty and exit.
-&quot; 1&gt;&amp;2
+_Dbg_show_version() {
+  printf 'There is absolutely no warranty for kshdb.  Type &quot;show warranty&quot; for details.
+' &gt;&amp;2
+  exit 101
+
 }
 
-# Process using short or long options, depending on the availability
-# of getopt
-TEMP=`getopt -o testing t 2&gt;/dev/null`
-if ((_Dbg_try_getopt &amp;&amp; 0 == $? )) ; then
-  # Process using long options
-  # Note that we use `&quot;$@&quot;' to let each command-line parameter expand to a 
-  # separate word. The quotes around `$@' are essential!
-  # We need TEMP as the `eval set --' would nuke the return value of getopt.
-  TEMP=`getopt -o A:Bc:hL:nqt:T::x:XYV \
---long annotate:,basename,command:,debugger,exec-command,help,library:,no-init,quiet,tempdir:,terminal:,trace,tty,version \
-     -n 'kshdb' -- &quot;$@&quot;`
-
-  if [ $? != 0 ] ; then 
-    echo &quot;Use --help for option help. Terminating...&quot; &gt;&amp;2 ; 
-    exit 1 ; 
-  fi
-  
-  # Note the quotes around `$TEMP': they are essential!
-  eval set -- &quot;$TEMP&quot;
-  
-  while true ; do
-    case $1 in
-      -A|--annotate) _Dbg_annotate=&quot;$2&quot;; shift ;;
-      -B|--basename) _Dbg_basename_only=1 ;;
-      -c|--eval-command) _Dbg_cmd=&quot;$2&quot;; shift ;;
-      --debugger) ;;  # This option is for compatibility with bash --debugger
-      -h|--help) _Dbg_usage_long; exit 100 ;;
-      -L|--library) shift ;;  # Handled previously
-      -n|--nx|--no-init) _Dbg_no_init=1 ;;
-      -q|--quiet) _Dbg_quiet=1 ;;
-      -T|--tempdir) _Dbg_tmpdir=$2; shift ;;
-      -t|--terminal|--tty) 
-	if ! $(touch $2 &gt;/dev/null 2&gt;/dev/null); then 
-	  echo &quot;${_Dbg_pname}: Can't access $2 for writing.&quot;
-	elif [[ ! -w $2 ]] ; then
-	  echo &quot;${_Dbg_pname}: terminal $2 needs to be writable.&quot;
-	else
-	  _Dbg_tty=$2 ;
-	fi
-	shift
-	;;
-      -x|--command) DBG_INPUT=&quot;$DBG_INPUT $2&quot;; shift ;;  
-      -X|--trace) _Dbg_opt_linetrace=1 ;;  
-      # -Y|--vtrace) _Dbg_opt_linetrace=1 ; _Dbg_opt_linetrace_expand=1 ;;  
-      -V|--version) show_version=1 ;;
-      --) shift ; break ;;
-      *) 
-	echo &quot;Use --help for option help. Terminating...&quot;
-	exit 2 ;;
-    esac
-    shift
-  done
-else 
-  # Process using short options
-  while getopts :A:Bc:hL:nqt:T:x:XYV opt; do
-    case $opt in
-      A) _Dbg_annotate=1 ;;
-      B) _Dbg_basename_only=1 ;;
-      c) _Dbg_cmd=&quot;$OPTARG&quot; ;;
-      h) _Dbg_usage_short; exit 100 ;;
-      n) _Dbg_no_init=1 ;;
-      q) _Dbg_quiet=1 ;;
-      L)  ;; # Handled previously
-      T) _Dbg_tmpdir=$OPTARG ;;
-      t) 
-	if ! $(touch $OPTARG &gt;/dev/null 2&gt;/dev/null); then 
-	  echo &quot;${_Dbg_pname}: Can't access $OPTARG for writing.&quot;
-	elif [[ ! -w $OPTARG ]] ; then
-	  echo &quot;${_Dbg_pname}: terminal $OPTARG needs to be writable.&quot;
-	else
-	  _Dbg_tty=$OPTARG
-	fi
-	;;
-      V) show_version=1 ;;
-      x) DBG_INPUT=&quot;$OPTARG&quot; ;;
-      X) _Dbg_opt_linetrace=1 ;;  
-      # Y) _Dbg_opt_linetrace=1 ; _Dbg_opt_linetrace_expand=1 ;;  
-      *) 
-	if ((_Dbg_basename_only == 1)) ; then
-	  echo &quot;${_Dbg_pname}: unrecognized option -- $OPTARG&quot;
+# Script arguments before adulteration by _Dbg_parse_otps
+typeset -a _Dbg_orig_script_args
+_Dbg_orig_script_args=($@)
+
+
+# The following globals are set by _Dbg_parse_opts. Any values set are 
+# the default values.
+typeset -a _Dbg_script_args
+
+typeset -i _Dbg_annotate=0
+typeset -i _Dbg_linetrace=0
+typeset -i _Dbg_basename_only=0
+typeset -i _Dbg_o_nx=0
+
+
+_Dbg_parse_options() {
+
+    . ${_Dbg_libdir}/getopts_long.sh
+
+    typeset -i _Dbg_o_quiet=0
+    typeset -i _Dbg_o_version=0
+
+    while getopts_long A:Bx:hL:nqV opt   \
+	annotate required_argument       \
+	basename 0                       \
+	cmdfile  required_argument       \
+    	help     0                       \
+	'?'      0                       \
+	library  required_argument       \
+	no-init  0                       \
+	nx       0                       \
+	quiet    0                       \
+	version  0                       \
+	'' &quot;$@&quot;
+    do
+	case &quot;$opt&quot; in 
+	    A | annotate ) 
+		_Dbg_o_annotate=$OPTLARG
+		;;
+	    B | basename )
+		_Dbg_basename_only=1
+		;;
+	    x | command )
+		DBG_INPUT=$OPTLARG
+		;;
+	    h | '?' | help )
+		_Dbg_usage
+		;;
+	    L | library ) 
+		;;
+	    V | version )
+		_Dbg_o_version=1
+		;;
+	    n | nx | no-init )
+		_Dbg_o_nx=1
+		;;
+	    q | quiet )
+		_Dbg_o_quiet=1
+		;;
+	    * ) 
+		print &quot;Unknown option $opt. Use -h or --help to see options&quot; &gt;&amp;2
+		exit 2
+		;;
+	esac
+    done
+    shift &quot;$(($OPTLIND - 1))&quot;
+    
+    if (( ! _Dbg_o_quiet &amp;&amp; ! _Dbg_o_version )); then 
+	print &quot;Zsh Shell Debugger, release $_Dbg_release&quot;
+	printf '
+Copyright 2008 Rocky Bernstein
+This is free software, covered by the GNU General Public License, and you are
+welcome to change it and/or distribute copies of it under certain conditions.
+
+'
+    fi
+    (( _Dbg_o_version )) &amp;&amp; _Dbg_show_version
+
+    if [[ -n $_Dbg_o_annotate ]] ; then
+	if [[ ${_Dbg_o_annotate} == [0-9]* ]] ; then
+	    _Dbg_annotate=$_Dbg_o_annotate
+	    if (( _Dbg_annotate &gt; 3 || _Dbg_annotate &lt; 0)); then
+		print &quot;Annotation level must be less between 0 and 3. Got: $_Dbg_annotate.&quot; &gt;&amp;2
+		print &quot;Setting Annotation level to 0.&quot; &gt;&amp;2
+		_Dbg_annotate=0
+	    fi
 	else
-	  echo &quot;$0: unrecognized option -- $OPTARG&quot;
+	    print &quot;Annotate option should be an integer, got ${_Dbg_o_annotate}.&quot; &gt;&amp;2
+	    print &quot;Setting annotation level to 0.&quot; &gt;&amp;2
 	fi
-	echo &quot;Use -h for option help. Terminating...&quot;
-	exit 2 
-	;;
-    esac
-  done
-  shift $(($OPTIND - 1))
+    fi
+    unset _Dbg_o_annotate _Dbg_o_version _Dbg_o_quiet
+    _Dbg_script_args=($@)
+}
+
+[[ -n $DBG_INPUT ]] &amp;&amp; typeset -p DBG_INPUT
+
+
+# Stand-alone Testing. 
+if [[ -n &quot;$_Dbg_dbg_opts_test&quot; ]] ; then
+    OPTLIND=1
+    _Dbg_libdir='.'
+    _Dbg_parse_options &quot;$@&quot;
+    typeset -p _Dbg_annotate
+    typeset -p _Dbg_linetrace
+    typeset -p _Dbg_basename_only
 fi</diff>
      <filename>dbg-opts.sh</filename>
    </modified>
    <modified>
      <diff>@@ -38,8 +38,6 @@ typeset -r _Dbg_release='0.01git'
 # Will be set to 1 if the top-level call is a debugger.
 typeset -i _Dbg_script=0
 
-typeset -i _Dbg_basename_only=0
-
 # Expand filename given as $1.
 # we echo the expanded name or return $1 unchanged if a bad filename.
 # Return is 0 if good or 1 if bad.
@@ -56,7 +54,7 @@ function _Dbg_expand_filename {
   typeset -x dirname=${filename%/*}
 
   # No slash given in filename? Then use . for dirname
-  [[ $dirname == $basename ]] &amp;&amp; dirname='.'
+  [[ $dirname == $basename ]] &amp;&amp; [[ $filename != '/' ]] &amp;&amp; dirname='.'
 
   # Dirname is ''? Then use / for dirname
   dirname=${dirname:-/}
@@ -64,11 +62,11 @@ function _Dbg_expand_filename {
   # Handle tilde expansion in dirname
   dirname=$(echo $dirname)
 
-  typeset long_path;
+  typeset long_path
 
   [[ $basename == '.' ]] &amp;&amp; basename=''
   if long_path=$( (cd &quot;$dirname&quot; ; pwd) ) ; then
-    if [[ $long_path == '/' ]] ; then
+    if [[ &quot;$long_path&quot; == '/' ]] ; then
       echo &quot;/$basename&quot;
     else
       echo &quot;$long_path/$basename&quot;
@@ -91,6 +89,8 @@ _Dbg_tempname() {
 
 # Process command-line options
 . ${_Dbg_libdir}/dbg-opts.sh
+OPTLIND=1
+_Dbg_parse_options &quot;$@&quot;
 
 if [[ ! -d $_Dbg_tmpdir ]] &amp;&amp; [[ ! -w $_Dbg_tmpdir ]] ; then
   echo &quot;${_Dbg_pname}: cannot write to temp directory $_Dbg_tmpdir.&quot; &gt;&amp;2
@@ -108,9 +108,6 @@ typeset _Dbg_init_cwd=$PWD
 #   fi
 # fi
 
-typeset -a _Dbg_script_args
-_Dbg_script_args=($@)
-
 typeset -i _Dbg_running=1      # True we are not finished running the program
 
 typeset -i _Dbg_currentbp=0    # If nonzero, the breakpoint number that we </diff>
      <filename>dbg-pre.sh</filename>
    </modified>
    <modified>
      <diff>@@ -3,6 +3,7 @@
 /Makefile.in
 /test-alias.sh
 /test-columns.sh
+/test-dbg-opts.sh
 /test-filecache.sh
 /test-fns.sh
 /test-frame.sh</diff>
      <filename>test/unit/.gitignore</filename>
    </modified>
    <modified>
      <diff>@@ -3,6 +3,7 @@
 
 TESTS = test-alias.sh        \
 	test-columns.sh      \
+	test-dbg-opts.sh     \
 	test-filecache.sh    \
 	test-fns.sh          \
 	test-frame.sh        \
@@ -20,6 +21,7 @@ abs_builddir=@abs_builddir@
 EXTRA_DIST = $(TESTS) $(check_DATA) \
 	test-alias.sh.in            \
 	test-columns.sh.in          \
+	test-dbg-opts.sh.in         \
 	test-filecache.sh.in        \
 	test-fns.sh.in              \
 	test-frame.sh.in            \</diff>
      <filename>test/unit/Makefile.am</filename>
    </modified>
    <modified>
      <diff>@@ -1,4 +1,4 @@
-# $Id: shunit2 211 2008-07-17 14:32:33Z kate.ward@forestent.com $
+# $Id: shunit2 224 2008-09-03 22:20:42Z kate.ward@forestent.com $
 # vim:et:ft=sh:sts=2:sw=2
 # vim:foldmethod=marker:foldmarker=/**,*/
 #
@@ -72,10 +72,18 @@ unset shunit_const_ shunit_constants_ shunit_ro_opts_
 __shunit_skip=${SHUNIT_FALSE}
 __shunit_suite=''
 
+# counts of tests
+__shunit_testSuccess=${SHUNIT_TRUE}
+__shunit_testsTotal=0
 __shunit_testsPassed=0
 __shunit_testsFailed=0
-__shunit_testsSkipped=0
-__shunit_testsTotal=0
+
+# counts of asserts
+__shunit_assertsTotal=0
+__shunit_assertsPassed=0
+__shunit_assertsFailed=0
+__shunit_assertsSkipped=0
+
 __shunit_reportGenerated=${SHUNIT_FALSE}
 
 # macros
@@ -116,7 +124,7 @@ assertEquals()
 
   [ -z &quot;${shunit_message_:-}&quot; ] &amp;&amp; shunit_message_=''
   if [ $# -eq 3 ]; then
-    shunit_message_=&quot;${shunit_message_}$1&quot;
+    shunit_message_=&quot;$1&quot;
     shift
   fi
   shunit_expected_=$1
@@ -124,7 +132,7 @@ assertEquals()
 
   shunit_return=${SHUNIT_TRUE}
   if [ &quot;${shunit_expected_}&quot; = &quot;${shunit_actual_}&quot; ]; then
-    _shunit_testPassed
+    _shunit_assertPass
   else
     failNotEquals &quot;${shunit_message_}&quot; &quot;${shunit_expected_}&quot; &quot;${shunit_actual_}&quot;
     shunit_return=${SHUNIT_FALSE}
@@ -166,7 +174,7 @@ assertNotEquals()
 
   [ -z &quot;${shunit_message_:-}&quot; ] &amp;&amp; shunit_message_=''
   if [ $# -eq 3 ]; then
-    shunit_message_=&quot;${shunit_message_}$1&quot;
+    shunit_message_=&quot;$1&quot;
     shift
   fi
   shunit_unexpected_=$1
@@ -174,7 +182,7 @@ assertNotEquals()
 
   shunit_return=${SHUNIT_TRUE}
   if [ &quot;${shunit_unexpected_}&quot; != &quot;${shunit_actual_}&quot; ]; then
-    _shunit_testPassed
+    _shunit_assertPass
   else
     failSame &quot;${shunit_message_}&quot; &quot;$@&quot;
     shunit_return=${SHUNIT_FALSE}
@@ -394,9 +402,9 @@ assertTrue()
 
   # record the test
   if [ ${shunit_return} -eq ${SHUNIT_TRUE} ]; then
-    _shunit_testPassed
+    _shunit_assertPass
   else
-    _shunit_testFailed &quot;${shunit_message_}&quot;
+    _shunit_assertFail &quot;${shunit_message_}&quot;
   fi
 
   unset shunit_message_ shunit_condition_ shunit_match_
@@ -464,9 +472,9 @@ assertFalse()
 
   # record the test
   if [ ${shunit_return} -eq ${SHUNIT_TRUE} ]; then
-    _shunit_testPassed
+    _shunit_assertPass
   else
-    _shunit_testFailed &quot;${shunit_message_}&quot;
+    _shunit_assertFail &quot;${shunit_message_}&quot;
   fi
 
   unset shunit_message_ shunit_condition_ shunit_match_
@@ -509,7 +517,7 @@ fail()
     shift
   fi
 
-  _shunit_testFailed &quot;${shunit_message_}&quot;
+  _shunit_assertFail &quot;${shunit_message_}&quot;
 
   unset shunit_message_
   return ${SHUNIT_FALSE}
@@ -547,13 +555,13 @@ failNotEquals()
 
   [ -z &quot;${shunit_message_:-}&quot; ] &amp;&amp; shunit_message_=''
   if [ $# -eq 3 ]; then
-    shunit_message_=&quot;${shunit_message_}$1&quot;
+    shunit_message_=&quot;$1&quot;
     shift
   fi
   shunit_unexpected_=$1
   shunit_actual_=$2
 
-  _shunit_testFailed &quot;${shunit_message_:+${shunit_message_} }expected:&lt;${shunit_unexpected_}&gt; but was:&lt;${shunit_actual_}&gt;&quot;
+  _shunit_assertFail &quot;${shunit_message_:+${shunit_message_} }expected:&lt;${shunit_unexpected_}&gt; but was:&lt;${shunit_actual_}&gt;&quot;
 
   unset shunit_message_ shunit_unexpected_ shunit_actual_
   return ${SHUNIT_FALSE}
@@ -588,11 +596,11 @@ failSame()
 
   [ -z &quot;${shunit_message_:-}&quot; ] &amp;&amp; shunit_message_=''
   if [ $# -eq 3 ]; then
-    shunit_message_=&quot;${shunit_message_}$1&quot;
+    shunit_message_=&quot;$1&quot;
     shift
   fi
 
-  _shunit_testFailed &quot;${shunit_message_:+${shunit_message_} }expected not same&quot;
+  _shunit_assertFail &quot;${shunit_message_:+${shunit_message_} }expected not same&quot;
 
   unset shunit_message_
   return ${SHUNIT_FALSE}
@@ -755,11 +763,12 @@ isSkipping()
 #*/
 suite_addTest()
 {
-  _su_func=${1:-}
+  shunit_func_=${1:-}
 
-  __shunit_suite=&quot;${__shunit_suite:+${__shunit_suite} }${_su_func}&quot;
+  __shunit_suite=&quot;${__shunit_suite:+${__shunit_suite} }${shunit_func_}&quot;
+  __shunit_testsTotal=`expr ${__shunit_testsTotal} + 1`
 
-  unset _su_func
+  unset shunit_func_
 }
 
 #/**
@@ -854,17 +863,61 @@ suite_addTest()
 # internal shUnit2 functions
 #
 
+# this function is a cross-platform temporary directory creation tool. not all
+# OSes have the mktemp function, so one is included here.
+_shunit_mktempDir()
+{
+  # try the standard mktemp function
+  ( exec mktemp -dqt shunit.XXXXXX 2&gt;/dev/null ) &amp;&amp; return
+
+  # the standard mktemp didn't work.  doing our own.
+  if [ -r '/dev/urandom' ]; then
+    _shunit_random_=`od -vAn -N4 -tx4 &lt;/dev/urandom |sed 's/^[^0-9a-f]*//'`
+  elif [ -n &quot;${RANDOM:-}&quot; ]; then
+    # $RANDOM works
+    _shunit_random_=${RANDOM}${RANDOM}${RANDOM}$$
+  else
+    # $RANDOM doesn't work
+    _shunit_date_=`date '+%Y%m%d%H%M%S'`
+    _shunit_random_=`expr ${_shunit_date_} / $$`
+  fi
+
+  _shunit_tmpDir_=&quot;${TMPDIR:-/tmp}/shunit.${_shunit_random_}&quot;
+  ( umask 077 &amp;&amp; mkdir &quot;${_shunit_tmpDir_}&quot; ) || {
+    _shunit_fatal 'could not create temporary directory! exiting'
+    exit ${SHUNIT_FALSE}
+  }
+
+  echo ${_shunit_tmpDir_}
+  unset _shunit_date_ _shunit_random_ _shunit_tmpDir_
+}
+
+# this function is here to work around issues in Cygwin
+_shunit_mktempFunc()
+{
+  for _shunit_func_ in oneTimeSetUp oneTimeTearDown setUp tearDown suite; do
+    _shunit_file_=&quot;${__shunit_tmpDir}/${_shunit_func_}&quot;
+    cat &lt;&lt;EOF &gt;&quot;${_shunit_file_}&quot;
+#! /bin/sh
+exit ${SHUNIT_TRUE}
+EOF
+    chmod +x &quot;${_shunit_file_}&quot;
+  done
+
+  unset _shunit_file_
+}
+
 _shunit_cleanup()
 {
-  name=$1
+  _shunit_name_=$1
 
-  case ${name} in
-    EXIT) signal=0 ;;
-    INT) signal=2 ;;
-    TERM) signal=15 ;;
+  case ${_shunit_name_} in
+    EXIT) _shunit_signal_=0 ;;
+    INT) _shunit_signal_=2 ;;
+    TERM) _shunit_signal_=15 ;;
     *)
-      _shunit_warn &quot;unrecognized trap value (${name})&quot;
-      signal=0
+      _shunit_warn &quot;unrecognized trap value (${_shunit_name_})&quot;
+      _shunit_signal_=0
       ;;
   esac
 
@@ -872,25 +925,27 @@ _shunit_cleanup()
   rm -fr &quot;${__shunit_tmpDir}&quot;
 
   # exit for all non-EXIT signals
-  if [ ${name} != 'EXIT' ]; then
-    _shunit_warn &quot;trapped and now handling the (${name}) signal&quot;
-    _shunit_generateReport
+  if [ ${_shunit_name_} != 'EXIT' ]; then
+    _shunit_warn &quot;trapped and now handling the (${_shunit_name_}) signal&quot;
     # disable EXIT trap
     trap 0
     # add 128 to signal and exit
-    exit `expr ${signal} + 128`
+    exit `expr ${_shunit_signal_} + 128`
   elif [ ${__shunit_reportGenerated} -eq ${SHUNIT_FALSE} ] ; then
-    _shunit_testFailed 'Unknown failure encountered running a test'
+    _shunit_assertFail 'Unknown failure encountered running a test'
     _shunit_generateReport
+    exit ${SHUNIT_ERROR}
   fi
+
+  unset _shunit_name_ _shunit_signal_
 }
 
+# The actual running of the tests happens here.
 _shunit_execSuite()
 {
-  echo '#'
-  echo '# Performing tests'
-  echo '#'
-  for _su_func in ${__shunit_suite}; do
+  for _shunit_test_ in ${__shunit_suite}; do
+    __shunit_testSuccess=${SHUNIT_TRUE}
+
     # disable skipping
     endSkipping
 
@@ -898,121 +953,94 @@ _shunit_execSuite()
     setUp
 
     # execute the test
-    echo &quot;${_su_func}&quot;
-    eval ${_su_func}
+    echo &quot;${_shunit_test_}&quot;
+    eval ${_shunit_test_}
 
     # execute the per-test tear-down function
     tearDown
+
+    # update stats
+    if [ ${__shunit_testSuccess} -eq ${SHUNIT_TRUE} ]; then
+      __shunit_testsPassed=`expr ${__shunit_testsPassed} + 1`
+    else
+      __shunit_testsFailed=`expr ${__shunit_testsFailed} + 1`
+    fi
   done
 
-  unset _su_func
+  unset _shunit_test_
 }
 
+# This function exits shUnit2 with the appropriate error code and OK/FAILED
+# message.
 _shunit_generateReport()
 {
-  _su__awkPercent='{printf(&quot;%4d %3.0f%%&quot;, $1, $1*100/$2)}'
-  if [ ${__shunit_testsTotal:-0} -gt 0 ]; then
-    _su__passed=`echo ${__shunit_testsPassed} ${__shunit_testsTotal} |\
-        awk &quot;${_su__awkPercent}&quot;`
-    _su__failed=`echo ${__shunit_testsFailed} ${__shunit_testsTotal} |\
-        awk &quot;${_su__awkPercent}&quot;`
-    _su__skipped=`echo ${__shunit_testsSkipped} ${__shunit_testsTotal} |\
-        awk &quot;${_su__awkPercent}&quot;`
-    _su__total=`echo ${__shunit_testsTotal} 100 |\
-        awk '{printf(&quot;%4d %3d%%&quot;, $1, $2)}'`
-  else
-    _su__passed=`echo 0 0 |awk '{printf(&quot;%4d %3d%%&quot;, $1, $2)}'`
-    _su__failed=${_su__passed}
-    _su__skipped=${_su__passed}
-    _su__total=${_su__passed}
-  fi
-
-  cat &lt;&lt;EOF
-
-#
-# Test report
-#
-tests passed:  ${_su__passed}
-tests failed:  ${_su__failed}
-tests skipped: ${_su__skipped}
-tests total:   ${_su__total}
-EOF
-  __shunit_reportGenerated=${SHUNIT_TRUE}
-
-  unset _su__awkPercent _su__passed _su__failed _su__skipped _su__total
-}
+  _shunit_ok_=${SHUNIT_TRUE}
 
-# this function is a cross-platform temporary directory creation tool. not all
-# OSes have the mktemp function, so one is included here.
-_shunit_mktempDir()
-{
-  # try the standard mktemp function
-  ( exec mktemp -dqt shunit.XXXXXX 2&gt;/dev/null ) &amp;&amp; return
+  # if no exit code was provided one, determine an appropriate one
+  [ ${__shunit_testsFailed} -gt 0 \
+      -o ${__shunit_testSuccess} -eq ${SHUNIT_FALSE} ] \
+          &amp;&amp; _shunit_ok_=${SHUNIT_FALSE}
 
-  # the standard mktemp didn't work.  doing our own.
-  if [ -r '/dev/urandom' ]; then
-    _su__random=`od -vAn -N4 -tx4 &lt;/dev/urandom |sed 's/^[^0-9a-f]*//'`
-  elif [ -n &quot;${RANDOM:-}&quot; ]; then
-    # $RANDOM works
-    _su__random=${RANDOM}${RANDOM}${RANDOM}$$
+  echo
+  if [ ${__shunit_testsTotal} -eq 1 ]; then
+    echo &quot;Ran ${__shunit_testsTotal} test.&quot;
   else
-    # $RANDOM doesn't work
-    _su__date=`date '+%Y%m%d%H%M%S'`
-    _su__random=`expr ${_su__date} / $$`
+    echo &quot;Ran ${__shunit_testsTotal} tests.&quot;
   fi
 
-  _su__tmpDir=&quot;${TMPDIR:-/tmp}/shunit.${_su__random}&quot;
-  ( umask 077 &amp;&amp; mkdir &quot;${_su__tmpDir}&quot; ) || {
-    echo 'shUnit:FATAL could not create temporary directory! exiting' &gt;&amp;2
-    exit 1
-  }
-
-  echo ${_su__tmpDir}
-  unset _su__date _su__random _su__tmpDir
-}
+  _shunit_failures_=''
+  _shunit_skipped_=''
+  [ ${__shunit_assertsFailed} -gt 0 ] \
+      &amp;&amp; _shunit_failures_=&quot;failures=${__shunit_assertsFailed}&quot;
+  [ ${__shunit_assertsSkipped} -gt 0 ] \
+      &amp;&amp; _shunit_skipped_=&quot;skipped=${__shunit_assertsSkipped}&quot;
+
+  if [ ${_shunit_ok_} -eq ${SHUNIT_TRUE} ]; then
+    _shunit_msg_='OK'
+    [ -n &quot;${_shunit_skipped_}&quot; ] \
+        &amp;&amp; _shunit_msg_=&quot;${_shunit_msg_} (${_shunit_skipped_})&quot;
+  else
+    _shunit_msg_=&quot;FAILED (${_shunit_failures_}&quot;
+    [ -n &quot;${_shunit_skipped_}&quot; ] \
+        &amp;&amp; _shunit_msg_=&quot;${_shunit_msg_},${_shunit_skipped_}&quot;
+    _shunit_msg_=&quot;${_shunit_msg_})&quot;
+  fi
 
-# this function is here to work around issues in Cygwin
-_shunit_mktempFunc()
-{
-  for _su__func in oneTimeSetUp oneTimeTearDown setUp tearDown suite; do
-    _su__file=&quot;${__shunit_tmpDir}/${_su__func}&quot;
-    cat &lt;&lt;EOF &gt;&quot;${_su__file}&quot;
-#! /bin/sh
-exit 0
-EOF
-    chmod +x &quot;${_su__file}&quot;
-  done
+  echo
+  echo ${_shunit_msg_}
+  __shunit_reportGenerated=${SHUNIT_TRUE}
 
-  unset _su__file
+  unset _shunit_failures_ _shunit_msg_ _shunit_ok_ _shunit_skipped_
 }
 
 _shunit_shouldSkip()
 {
   [ ${__shunit_skip} -eq ${SHUNIT_FALSE} ] &amp;&amp; return ${SHUNIT_FALSE}
-  _shunit_testSkipped
+  _shunit_assertSkip
 }
 
-_shunit_testPassed()
+_shunit_assertPass()
 {
-  __shunit_testsPassed=`expr ${__shunit_testsPassed} + 1`
-  __shunit_testsTotal=`expr ${__shunit_testsTotal} + 1`
+  __shunit_assertsPassed=`expr ${__shunit_assertsPassed} + 1`
+  __shunit_assertsTotal=`expr ${__shunit_assertsTotal} + 1`
 }
 
-_shunit_testFailed()
+_shunit_assertFail()
 {
-  _su__msg=$1
+  _shunit_msg_=$1
 
-  __shunit_testsFailed=`expr ${__shunit_testsFailed} + 1`
-  __shunit_testsTotal=`expr ${__shunit_testsTotal} + 1`
-  echo &quot;${__SHUNIT_ASSERT_MSG_PREFIX}${_su__msg}&quot; &gt;&amp;2
+  __shunit_testSuccess=${SHUNIT_FALSE}
+  __shunit_assertsFailed=`expr ${__shunit_assertsFailed} + 1`
+  __shunit_assertsTotal=`expr ${__shunit_assertsTotal} + 1`
+  echo &quot;${__SHUNIT_ASSERT_MSG_PREFIX}${_shunit_msg_}&quot;
 
-  unset _su__msg
+  unset _shunit_msg_
 }
 
-_shunit_testSkipped()
+_shunit_assertSkip()
 {
-  __shunit_testsSkipped=`expr ${__shunit_testsSkipped} + 1`
-  __shunit_testsTotal=`expr ${__shunit_testsTotal} + 1`
+  __shunit_assertsSkipped=`expr ${__shunit_assertsSkipped} + 1`
+  __shunit_assertsTotal=`expr ${__shunit_assertsTotal} + 1`
 }
 
 #------------------------------------------------------------------------------
@@ -1054,10 +1082,12 @@ _shunit_execSuite
 # execute the oneTimeTearDown function (if it exists)
 oneTimeTearDown
 
-# generate report
+# generate the report
 _shunit_generateReport
 
-[ ${__shunit_testsFailed} -eq 0 ] || exit 1
+# that's it folks
+[ ${__shunit_testsFailed} -eq 0 ]
+exit $?
 
 #/**
 # &lt;/s:shelldoc&gt;</diff>
      <filename>test/unit/shunit2</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>e6815e5f690674f33ff4a39cc49b9db40c988132</id>
    </parent>
  </parents>
  <author>
    <name>R. Bernstein</name>
    <email>rocky@gnu.org</email>
  </author>
  <url>http://github.com/rocky/kshdb/commit/999996f63ab05d8268c842d716f23674f3c65de3</url>
  <id>999996f63ab05d8268c842d716f23674f3c65de3</id>
  <committed-date>2008-09-29T20:14:33-07:00</committed-date>
  <authored-date>2008-09-29T20:14:33-07:00</authored-date>
  <message>Use getopt_long from St&#233;phane Chazelas. Thanks St&#233;phane!</message>
  <tree>91844e7a5de38e82e76c514376d9fcd6bb956a0c</tree>
  <committer>
    <name>R. Bernstein</name>
    <email>rocky@gnu.org</email>
  </committer>
</commit>
