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