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