Home | History | Annotate | Line # | Download | only in tests
xmltest.sh revision 1.2
      1  1.2   spz #! /usr/bin/env bash
      2  1.1  tron 
      3  1.1  tron #   EXPAT TEST SCRIPT FOR W3C XML TEST SUITE
      4  1.1  tron 
      5  1.1  tron # This script can be used to exercise Expat against the
      6  1.1  tron # w3c.org xml test suite, available from
      7  1.1  tron # http://www.w3.org/XML/Test/xmlts20020606.zip.
      8  1.1  tron 
      9  1.2   spz # To run this script, first set XMLWF below so that xmlwf can be
     10  1.1  tron # found, then set the output directory with OUTPUT.
     11  1.1  tron 
     12  1.1  tron # The script lists all test cases where Expat shows a discrepancy
     13  1.1  tron # from the expected result. Test cases where only the canonical
     14  1.1  tron # output differs are prefixed with "Output differs:", and a diff file
     15  1.1  tron # is generated in the appropriate subdirectory under $OUTPUT.
     16  1.1  tron 
     17  1.1  tron # If there are output files provided, the script will use
     18  1.1  tron # output from xmlwf and compare the desired output against it.
     19  1.1  tron # However, one has to take into account that the canonical output
     20  1.1  tron # produced by xmlwf conforms to an older definition of canonical XML
     21  1.1  tron # and does not generate notation declarations.
     22  1.1  tron 
     23  1.2   spz shopt -s nullglob
     24  1.2   spz 
     25  1.1  tron MYDIR="`dirname \"$0\"`"
     26  1.1  tron cd "$MYDIR"
     27  1.1  tron MYDIR="`pwd`"
     28  1.2   spz # XMLWF="`dirname \"$MYDIR\"`/xmlwf/xmlwf"
     29  1.2   spz XMLWF=/usr/bin/xmlwf
     30  1.1  tron TS="$MYDIR/XML-Test-Suite"
     31  1.1  tron # OUTPUT must terminate with the directory separator.
     32  1.1  tron OUTPUT="$TS/out/"
     33  1.1  tron # OUTPUT=/home/tmp/xml-testsuite-out/
     34  1.1  tron 
     35  1.1  tron 
     36  1.1  tron # RunXmlwfNotWF file reldir
     37  1.1  tron # reldir includes trailing slash
     38  1.1  tron RunXmlwfNotWF() {
     39  1.1  tron   file="$1"
     40  1.1  tron   reldir="$2"
     41  1.1  tron   $XMLWF -p "$file" > outfile || return $?
     42  1.1  tron   read outdata < outfile
     43  1.1  tron   if test "$outdata" = "" ; then
     44  1.2   spz       echo "Expected not well-formed: $reldir$file"
     45  1.1  tron       return 1
     46  1.1  tron   else
     47  1.1  tron       return 0
     48  1.1  tron   fi 
     49  1.1  tron }
     50  1.1  tron 
     51  1.1  tron # RunXmlwfWF file reldir
     52  1.1  tron # reldir includes trailing slash
     53  1.1  tron RunXmlwfWF() {
     54  1.1  tron   file="$1"
     55  1.1  tron   reldir="$2"
     56  1.1  tron   $XMLWF -p -d "$OUTPUT$reldir" "$file" > outfile || return $?
     57  1.1  tron   read outdata < outfile 
     58  1.1  tron   if test "$outdata" = "" ; then 
     59  1.1  tron       if [ -f "out/$file" ] ; then 
     60  1.2   spz           diff -u "$OUTPUT$reldir$file" "out/$file" > outfile 
     61  1.1  tron           if [ -s outfile ] ; then 
     62  1.1  tron               cp outfile "$OUTPUT$reldir$file.diff"
     63  1.1  tron               echo "Output differs: $reldir$file"
     64  1.1  tron               return 1
     65  1.1  tron           fi 
     66  1.1  tron       fi 
     67  1.1  tron       return 0
     68  1.1  tron   else 
     69  1.1  tron       echo "In $reldir: $outdata"
     70  1.1  tron       return 1
     71  1.1  tron   fi 
     72  1.1  tron }
     73  1.1  tron 
     74  1.1  tron SUCCESS=0
     75  1.1  tron ERROR=0
     76  1.1  tron 
     77  1.1  tron UpdateStatus() {
     78  1.1  tron   if [ "$1" -eq 0 ] ; then
     79  1.1  tron     SUCCESS=`expr $SUCCESS + 1`
     80  1.1  tron   else
     81  1.1  tron     ERROR=`expr $ERROR + 1`
     82  1.1  tron   fi
     83  1.1  tron }
     84  1.1  tron 
     85  1.1  tron ##########################
     86  1.1  tron # well-formed test cases #
     87  1.1  tron ##########################
     88  1.1  tron 
     89  1.1  tron cd "$TS/xmlconf"
     90  1.1  tron for xmldir in ibm/valid/P* \
     91  1.1  tron               ibm/invalid/P* \
     92  1.1  tron               xmltest/valid/ext-sa \
     93  1.1  tron               xmltest/valid/not-sa \
     94  1.1  tron               xmltest/invalid \
     95  1.1  tron               xmltest/invalid/not-sa \
     96  1.1  tron               xmltest/valid/sa \
     97  1.1  tron               sun/valid \
     98  1.1  tron               sun/invalid ; do
     99  1.1  tron   cd "$TS/xmlconf/$xmldir"
    100  1.1  tron   mkdir -p "$OUTPUT$xmldir"
    101  1.1  tron   for xmlfile in *.xml ; do
    102  1.1  tron       RunXmlwfWF "$xmlfile" "$xmldir/"
    103  1.1  tron       UpdateStatus $?
    104  1.1  tron   done
    105  1.2   spz   rm -f outfile
    106  1.1  tron done
    107  1.1  tron 
    108  1.1  tron cd "$TS/xmlconf/oasis"
    109  1.1  tron mkdir -p "$OUTPUT"oasis
    110  1.1  tron for xmlfile in *pass*.xml ; do
    111  1.1  tron     RunXmlwfWF "$xmlfile" "oasis/"
    112  1.1  tron     UpdateStatus $?
    113  1.1  tron done
    114  1.1  tron rm outfile
    115  1.1  tron 
    116  1.1  tron ##############################
    117  1.1  tron # not well-formed test cases #
    118  1.1  tron ##############################
    119  1.1  tron 
    120  1.1  tron cd "$TS/xmlconf"
    121  1.1  tron for xmldir in ibm/not-wf/P* \
    122  1.2   spz               ibm/not-wf/p28a \
    123  1.1  tron               ibm/not-wf/misc \
    124  1.1  tron               xmltest/not-wf/ext-sa \
    125  1.1  tron               xmltest/not-wf/not-sa \
    126  1.1  tron               xmltest/not-wf/sa \
    127  1.1  tron               sun/not-wf ; do
    128  1.1  tron   cd "$TS/xmlconf/$xmldir"
    129  1.1  tron   for xmlfile in *.xml ; do
    130  1.1  tron       RunXmlwfNotWF "$xmlfile" "$xmldir/"
    131  1.1  tron       UpdateStatus $?
    132  1.1  tron   done
    133  1.1  tron   rm outfile
    134  1.1  tron done
    135  1.1  tron 
    136  1.1  tron cd "$TS/xmlconf/oasis"
    137  1.1  tron for xmlfile in *fail*.xml ; do
    138  1.1  tron     RunXmlwfNotWF "$xmlfile" "oasis/"
    139  1.1  tron     UpdateStatus $?
    140  1.1  tron done
    141  1.1  tron rm outfile
    142  1.1  tron 
    143  1.1  tron echo "Passed: $SUCCESS"
    144  1.1  tron echo "Failed: $ERROR"
    145