Name .diff file differently
[yaz-moved-to-github.git] / test / tstmarc.sh
index 1b0aae9..ff0b686 100755 (executable)
@@ -1,31 +1,42 @@
 #!/bin/sh
-# $Id: tstmarc.sh,v 1.1 2004-10-01 11:43:43 adam Exp $
+# Tests reading of ISO2709 and checks that we get identical MARCXML
+# 
+# Reads marc?.marc files , Generates marc*.xml files
+# If Libxml2 is present, the marc*.xml files are parsed again..
 srcdir=${srcdir:-.}
 ecode=0
-for f in ${srcdir}/marc?; do
-    NEW=${f}.new.xml
-    OLD=${f}.xml
-    DIFF=${f}.diff
-    ../util/yaz-marcdump -f iso-8859-1 -t utf-8 -X $f > $NEW
+
+../util/yaz-marcdump -i marcxml >/dev/null 2>&1
+if test $? = "3"; then
+    noxml=1
+fi
+
+for f in ${srcdir}/marc[0-9].marc; do
+    fb=`basename ${f} .marc`
+    CHR=${srcdir}/${fb}.chr
+    NEW=${fb}.new.xml
+    OLD=${srcdir}/${fb}.xml
+    DIFF=`basename ${f}`.diff
+    ../util/yaz-marcdump -f `cat $CHR` -t utf-8 -o marcxml $f > $NEW
     if test $? != "0"; then
-       echo "Failed decode of $f"
+       echo "$f: yaz-marcdump returned error"
        ecode=1
     elif test -f $OLD; then
         if diff $OLD $NEW >$DIFF; then
            rm $DIFF
            rm $NEW
        else
-           echo "Differ in $f"
+           echo "$f: $NEW and $OLD differ"
            ecode=1
        fi
     else
-       echo "Making test $f for the first time"
+       echo "$f: Making test result $OLD for the first time"
        if test -x /usr/bin/xmllint; then
            if xmllint --noout $NEW >out 2>stderr; then
-               echo "XML for $f is OK"
+               echo "$f: $NEW is well-formed"
                mv $NEW $OLD
            else
-               echo "XML for $f is invalid"
+               echo "$f: $NEW not well-formed"
                ecode=1
            fi
        else
@@ -33,5 +44,35 @@ for f in ${srcdir}/marc?; do
            ecode=1
        fi
     fi
+
+    if test -z "$noxml"; then
+       f=$OLD
+       OLD=${f}.marc
+       NEW=`basename ${f}`.new.marc
+       DIFF=`basename ${f}`.diff
+       ../util/yaz-marcdump -f utf-8 -t utf-8 -i marcxml -o marc $f > $NEW
+       if test $? != "0"; then
+           echo "Failed decode of $f"
+           ecode=1
+       elif test -f $OLD; then
+           if diff $OLD $NEW >$DIFF; then
+               rm $DIFF
+               rm $NEW
+           else
+               echo "$f: $NEW and $OLD Differ"
+               ecode=1
+           fi
+       else
+           echo "$f: Making test result $OLD for the first time"
+           mv $NEW $OLD
+       fi
+    fi
+    
 done
-exit $ecode
\ No newline at end of file
+exit $ecode
+
+# Local Variables:
+# mode:shell-script
+# sh-indentation: 2
+# sh-basic-offset: 4
+# End: