b061adfd1cf0c78a5d5b15682f9d5bce30343edd
[yaz-moved-to-github.git] / test / tstmarc.sh
1 #!/bin/sh
2 # $Id: tstmarc.sh,v 1.4 2007-09-25 07:34:03 adam Exp $
3 # Tests reading of ISO2709 and checks that we get identical MARCXML
4
5 # Reads marc?.marc files , Generates marc*.xml files
6 # If Libxml2 is present, the marc*.xml files are parsed again..
7 srcdir=${srcdir:-.}
8 ecode=0
9
10 ../util/yaz-marcdump -i marcxml >/dev/null 2>&1
11 if test $? = "3"; then
12     noxml=1
13 fi
14
15 for f in ${srcdir}/marc[0-9].marc; do
16     fb=`basename ${f} .marc`
17     CHR=${srcdir}/${fb}.chr
18     NEW=${fb}.new.xml
19     OLD=${srcdir}/${fb}.xml
20     DIFF=`basename ${f}`.diff
21     ../util/yaz-marcdump -f `cat $CHR` -t utf-8 -o marcxml $f > $NEW
22     if test $? != "0"; then
23         echo "$f: yaz-marcdump returned error"
24         ecode=1
25     elif test -f $OLD; then
26         if diff $OLD $NEW >$DIFF; then
27             rm $DIFF
28             rm $NEW
29         else
30             echo "$f: $NEW and $OLD differ"
31             ecode=1
32         fi
33     else
34         echo "$f: Making test result $OLD for the first time"
35         if test -x /usr/bin/xmllint; then
36             if xmllint --noout $NEW >out 2>stderr; then
37                 echo "$f: $NEW is well-formed"
38                 mv $NEW $OLD
39             else
40                 echo "$f: $NEW not well-formed"
41                 ecode=1
42             fi
43         else
44             echo "xmllint not found. install libxml2-utils"
45             ecode=1
46         fi
47     fi
48
49     if test -z "$noxml"; then
50         f=$OLD
51         OLD=${f}.marc
52         NEW=`basename ${f}`.new.marc
53         DIFF=`basename ${f}`.diff
54         ../util/yaz-marcdump -f utf-8 -t utf-8 -i marcxml -o marc $f > $NEW
55         if test $? != "0"; then
56             echo "Failed decode of $f"
57             ecode=1
58         elif test -f $OLD; then
59             if diff $OLD $NEW >$DIFF; then
60                 rm $DIFF
61                 rm $NEW
62             else
63                 echo "$f: $NEW and $OLD Differ"
64                 ecode=1
65             fi
66         else
67             echo "$f: Making test result $OLD for the first time"
68             mv $NEW $OLD
69         fi
70     fi
71     
72 done
73 exit $ecode
74
75 # Local Variables:
76 # mode:shell-script
77 # sh-indentation: 2
78 # sh-basic-offset: 4
79 # End: