X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=test%2Ftest_marc.sh;h=5ced5259bfc8a270fc699c875580202258d33a23;hp=2996bb437e415a97df5d600e30070d2133eba0fc;hb=8cb8947e3a7bff4dbf8f124871cb4905df1adce7;hpb=b756b711841bac38e5b69baa51939ca9e1c01adb diff --git a/test/test_marc.sh b/test/test_marc.sh index 2996bb4..5ced525 100755 --- a/test/test_marc.sh +++ b/test/test_marc.sh @@ -1,10 +1,10 @@ #!/bin/sh # Tests reading of ISO2709 and checks that we get identical MARCXML -# +# # Reads marc?.marc files , Generates marc*.xml files -# If Libxml2 is present, also turbomarc*xml. -# as well as reverse transformation from *marc*.xml files are parsed again.. -# +# If Libxml2 is present, also turbomarc*xml. +# as well as reverse transformation from *marc*.xml files are parsed again.. +# srcdir=${srcdir:-.} ecode=0 @@ -18,17 +18,17 @@ if test $? = "4"; then noxmlwrite=1 fi -binmarc_convert() { +binmarc_convert() { OUTPUT_FORMAT="$1" REVERT_FORMAT="$2" PREFIX="$3" + SUFFIX="$4" for f in ${srcdir}/marc[0-9].marc; do fb=`basename ${f} .marc` CHR=`cat ${srcdir}/${fb}.chr` - NEW=${PREFIX}${fb}.new.xml - OLD=${srcdir}/${PREFIX}${fb}.xml + NEW=${PREFIX}${fb}.new.${SUFFIX} + OLD=${srcdir}/${PREFIX}${fb}.${SUFFIX} DIFF=`basename ${f}`.diff - #echo "../util/yaz-marcdump -f $CHR -t utf-8 -i marc -o ${OUTPUT_FORMAT} $f > $NEW" ../util/yaz-marcdump -f $CHR -t utf-8 -i marc -o ${OUTPUT_FORMAT} $f > $NEW if test $? != "0"; then echo "$f: yaz-marcdump returned error" @@ -43,20 +43,33 @@ binmarc_convert() { fi else 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 "$f: $NEW is well-formed" - mv $NEW $OLD + if test "$SUFFIX" = "xml"; then + if test -x /usr/bin/xmllint; then + if xmllint --noout $NEW >out 2>stderr; then + echo "$f: $NEW is well-formed" + mv $NEW $OLD + else + echo "$f: $NEW not well-formed" + ecode=1 + fi else - echo "$f: $NEW not well-formed" + echo "xmllint not found. install libxml2-utils" ecode=1 fi - else - echo "xmllint not found. install libxml2-utils" - ecode=1 - fi + elif test "$SUFFIX" = "json"; then + if ../util/yaz-json-parse < $NEW >out 2>stderr; then + echo "$f: $NEW is JSON OK" + mv $NEW $OLD + else + echo "$f: $NEW is NOT JSON OK" + ecode=1 + fi + else + echo "Bad suffix $SUFFIX" + ecode = 1 + fi fi - + if test -z "$noxml"; then ORIGINAL=${f} f=$OLD @@ -64,7 +77,7 @@ binmarc_convert() { OLD=${f}.marc NEW=`basename ${f}`.new.marc DIFF=`basename ${f}`.diff - #echo "../util/yaz-marcdump -f utf-8 -t utf-8 -i ${REVERT_FORMAT} -o marc $f > $NEW" + # echo "../util/yaz-marcdump -f utf-8 -t utf-8 -i ${REVERT_FORMAT} -o marc $f > $NEW" ../util/yaz-marcdump -f utf-8 -t utf-8 -i ${REVERT_FORMAT} -o marc $f > $NEW if test $? != "0"; then echo "Failed decode of $f" @@ -84,7 +97,7 @@ binmarc_convert() { # check with original REVERT=`basename ${f}`.marc.revert #../util/yaz-marcdump -f utf-8 -t $CHR -i ${REVERT_FORMAT} -o marc $f > $REVERT - #hexdump -cx $REVERT > $REVERT.hex + #hexdump -cx $REVERT > $REVERT.hex #hexdump -cx $ORIGINAL > $ORIGINAL.hex #diff $REVERT.hex $ORIGINAL.hex > $REVERT.diff fi @@ -92,23 +105,33 @@ binmarc_convert() { return $ecode } -binmarc_convert "marcxml" "marcxml" "" -echo "binmarc -> marcxml: $?" +for f in ${srcdir}/marc[0-9].marc; do + ../util/yaz-marcdump $f > /dev/null + if test $? != "0"; then + echo "$f: yaz-marcdump returned error" + ecode=1 + fi +done +binmarc_convert "marcxml" "marcxml" "" xml +echo "binmarc -> marcxml: $?" if test -z "$noxmlwrite"; then -binmarc_convert "xml,marcxml" "marcxml" "xml2" -echo "binmarc -> marcxml(libxml2): $?" + binmarc_convert "xml,marcxml" "marcxml" "xml2" xml + echo "binmarc -> marcxml(libxml2): $?" fi -binmarc_convert "turbomarc" "turbomarc" "t" -echo "binmarc -> turbomarc: $?" +binmarc_convert "turbomarc" "turbomarc" "t" xml +echo "binmarc -> turbomarc: $?" if test -z "$noxmlwrite"; then -binmarc_convert "xml,turbomarc" "turbomarc" "xml2t" -echo "binmarc -> turbomarc(libxml2): $?" + binmarc_convert "xml,turbomarc" "turbomarc" "xml2t" xml + echo "binmarc -> turbomarc(libxml2): $?" fi +binmarc_convert "json" "json" "" json +echo "binmarc -> json: $?" + exit $ecode # Local Variables: