Sync with 1.22 from ckmame.

--HG--
branch : HEAD
diff --git a/regress/runtest b/regress/runtest
index ff38abf..8255699 100755
--- a/regress/runtest
+++ b/regress/runtest
@@ -1,6 +1,8 @@
 #!/bin/sh
 
-#  $NiH: runtest,v 1.1 2005/07/15 16:53:37 wiz Exp $
+#  $NiH$
+
+#  from ckmame:runtest,v 1.22 2005/12/27 09:41:51 dillo Exp
 #
 #  runtest -- run regression tests
 #  Copyright (C) 2002, 2003 Dieter Baron and Thomas Klausner
@@ -33,35 +35,41 @@
 #    The following commands are recognized; return and args must
 #    appear exactly once, the others are optional.
 #
-#	return RET
-#	    RET is the expected exit code
-#
 #	args ARGS
 #	    run program with command line arguments ARGS
 #	
+#	description TEXT
+#	    description of what test is for
+#
+#	file TEST IN OUT
+#	    copy file IN as TEST, compare against OUT after program run.
+#
+#	file-del TEST IN
+#	    copy file IN as TEST, check that it is removed by program.
+#
+#	file-new TEST OUT
+#	    check that file TEST is created by program and compare
+#	    against OUT.
+#
+#	mkdir MODE NAME
+#	    create directory NAME with permissions MODE.
+#
+#	program PRG
+#	    run PRG.
+#
+#	return RET
+#	    RET is the expected exit code
+#
+#	stderr TEXT
+#	    program is expected to produce the error message TEXT.  If
+#	    multiple stderr commands are used, the messages are
+#	    expected in the order given.
+#
 #	stdout TEXT
 #	    program is expected to print TEXT to stdout.  If multiple
 #	    stdout commands are used, the messages are expected in
 #	    the order given. 
 #   
-#	error TEXT
-#	    program is expected to produce the error message TEXT.  If
-#	    multiple error commands are used, the messages are
-#	    expected in the order given.
-#
-#	copy IN OUT
-#	    link file IN to OUT
-#
-#	file IN TEST OUT
-#           link zip file IN to TEST, check against OUT after
-#           program has run.
-#
-#	filenew CREATED EXPECTED
-#	    check that CREATED has been created and equals EXPECTED.
-#
-#	filedel IN TEST
-#	    link zip file IN to TEST, check that it is deleted.
-#
 # exit status
 #	runtest uses the following exit codes:
 #	    0: test passed
@@ -110,47 +118,55 @@
 	cd ..;
 	if [ -z "${NOCLEANUP}" ]
 	then
+		chmod -R u+rw ${DIR};
 		rm -r ${DIR};
 	fi
 }
 
-checkfile() {
+check_in_out_exists() {
     if [ ! -f "$2" ]
     then
 	fail "missing output file: '$2'"
-    else
-	if [ ! -f "$1" ]
+    elif [ ! -f "$1" ]
+    then
+	die "cannot find input file '$1'"
+    fi
+}
+
+checkdb() {
+    check_in_out_exists "$1" "$2"
+    out=`../dbdump "$2" | sort | diff ${DIFF_FLAGS} "$1" -`
+    if [ $? -ne 0 ]
+    then
+	if [ $VERBOSE ]
 	then
-	    die "cannot find input file $1"
+	    echo "$out"
 	fi
-	
-	diff "$1" "$2" > /dev/null
-	if [ $? -ne 0 ]
+	fail "$3"
+    fi
+
+}
+
+checkfile() {
+    check_in_out_exists "$1" "$2"
+    out=`diff ${DIFF_FLAGS} "$1" "$2"`
+    if [ $? -ne 0 ]
+    then
+	if [ $VERBOSE ]
 	then
-	    if [ ! -z "${VERBOSE}" ]
-	    then
-		diff -u "$1" "$2"
-	    fi
-	    fail "$3"
+	    echo "$out"
 	fi
+	fail "$3"
     fi
 }
 
 checkzip() {
-    if [ ! -f "$2" ]
+    check_in_out_exists "$1" "$2"
+    # quiet CRC errors
+    ${ZIPCMP} -t ${ZIPCMP_FLAGS} "$1" "$2" 2>/dev/null
+    if [ $? -ne 0 ]
     then
-	fail "missing output file: '$2'"
-    else
-	if [ ! -f "$1" ]
-	then
-	    die "cannot find input file $1"
-	fi
-	
-	${ZIPCMP} -t ${ZIPCMP_FLAGS} "$1" "$2"
-	if [ $? -ne 0 ]
-	then
-	    fail "$3"
-	fi
+	fail "$3"
     fi
 }
 
@@ -168,6 +184,23 @@
     fi
 }
 
+copy_file() {
+    if [ ! -f "$1" ]
+    then
+	die "source file '$1' does not exist"
+    fi
+    dir=`dirname "$2"`
+    if [ ! -d "$dir" ]
+    then
+	mkdir -p "$dir"
+    fi
+    cp "$1" "$2"
+}
+
+# GNU sort behaves differently on locales other than C, breaking tests
+LC_ALL=C
+export LC_ALL
+
 TEST=`echo $1 | sed 's/\.test$//'`
 shift
 
@@ -192,8 +225,10 @@
 
 if [ -z "${VERBOSE}" ]
 then
+    DIFF_FLAGS=''
     ZIPCMP_FLAGS='-q'
 else
+    DIFF_FLAGS='-u'
     ZIPCMP_FLAGS='-v'
 fi
 
@@ -208,56 +243,67 @@
 ARGS=''
 FILES=''
 FILES_SHOULD=''
+DESCR=''
 
-touch errors stdout
+touch stderr stdout
 
 while read cmd arg
 do
   case $cmd in
   \#*) ;;
+  args)
+    test_empty "${ARGS}" args
+    ARGS="$arg";;
+  description)
+    test_empty "${DESCR}" description
+    DESCR="$arg";;
+  file)
+    set $arg
+    copy_file "${srcdir}/$2" "$1"
+    FILES="${FILES} ${srcdir}/$3!$1";;
+  file-del)
+    set $arg
+    copy_file "${srcdir}/$2" "$1";;
+  file-new)
+    set $arg
+    FILES="${FILES} ${srcdir}/$2!$1";;
+  mkdir)
+    set $arg
+    mkdir "$2" && chmod "$1" "$2";;
   program)
-    PROGRAM=../$arg;;
+    PROGRAM=../"$arg";;
   return)
     test_empty "${RET}" return
     RET="$arg";;
-  args)
-    test_empty "${ARGS}" args
-    ARGS=$arg;;
-  copy)
-    set $arg
-    FILES_SHOULD="${FILES_SHOULD} $2"
-    cp "${srcdir}/$1" "$2";;
-  file)
-    set $arg
-    # XXX: check that $1 exists
-    FILES="${FILES} ${srcdir}/$3!$2";;
-  filenew)
-    set $arg
-    FILES="${FILES} ${srcdir}/$2!$1";;
-  filedel)
-    set $arg
-    # XXX: check that $1 exists
-    cp "${srcdir}/$1" "$2";;
+  stderr)
+    echo "${PROGRAM}: $arg" >> stderr;;
   stdout)
     echo "$arg" >> stdout;;
-  error)
-    echo "${PROGRAM}: $arg" >> errors;;
   *)
     die "unknown directive '$cmd'"
   esac
 done
 
+test_set "${RET}" return
+test_set "${ARGS}" args
+
 if [ -z "${PROGRAM}" ]
 then
     die no program to run given
 fi
 
-test_set "${RET}" return
+if [ ! -z "${SETUP_ONLY}" ]
+then
+    echo ${DIR}
+    exit 0
+fi
 
 if [ ! -z "${VERBOSE}" ]
 then
+	echo "${TEST}: ${DESCR}"
 	echo "running: ${PROGRAM} ${ARGS}"
 fi
+
 ${PROGRAM} ${ARGS} > gotout 2> goterr
 ret=$?
 
@@ -271,9 +317,9 @@
     fail "unexpected exit status: got $ret, expected ${RET}"
 fi
 
-FILES_SHOULD="${FILES_SHOULD} errors stdout gotout goterr"
+FILES_SHOULD="${FILES_SHOULD} stderr stdout gotout goterr"
 
-checkfile errors goterr "unexpected error output"
+checkfile stderr goterr "unexpected error output"
 checkfile stdout gotout "unexpected output"
 
 if [ ! -z "${FILES}" ]
@@ -282,11 +328,18 @@
     do
         set -- `echo ${fs} | tr '!' ' '`
 	FILES_SHOULD="${FILES_SHOULD} $2"
-	checkzip $1 $2 "zip file $2 wrong"
+	case "$2" in
+	*.db)
+	    checkdb "$1" "$2" "database $2 wrong";;
+	*.zip)
+	    checkzip "$1" "$2" "zip file $2 wrong";;
+	*)
+	    checkfile "$1" "$2" "file $2 wrong";;
+	esac 
     done
 fi
 
-# XXX: check that no additional files exist
+# check that no additional files exist
 echo gotfiles shouldfiles ${FILES_SHOULD} | tr ' ' '\012' | sort > shouldfiles
 touch gotfiles
 find . -type f -print | sed 's!^./!!' | sort > gotfiles