1302305Sdelphij#! /usr/bin/env bash 2104349Sphk 3104349Sphk# EXPAT TEST SCRIPT FOR W3C XML TEST SUITE 4104349Sphk 5104349Sphk# This script can be used to exercise Expat against the 6104349Sphk# w3c.org xml test suite, available from 7104349Sphk# http://www.w3.org/XML/Test/xmlts20020606.zip. 8104349Sphk 9247296Sdelphij# To run this script, first set XMLWF below so that xmlwf can be 10104349Sphk# found, then set the output directory with OUTPUT. 11104349Sphk 12104349Sphk# The script lists all test cases where Expat shows a discrepancy 13104349Sphk# from the expected result. Test cases where only the canonical 14104349Sphk# output differs are prefixed with "Output differs:", and a diff file 15104349Sphk# is generated in the appropriate subdirectory under $OUTPUT. 16104349Sphk 17104349Sphk# If there are output files provided, the script will use 18104349Sphk# output from xmlwf and compare the desired output against it. 19104349Sphk# However, one has to take into account that the canonical output 20104349Sphk# produced by xmlwf conforms to an older definition of canonical XML 21104349Sphk# and does not generate notation declarations. 22104349Sphk 23302305Sdelphijshopt -s nullglob 24302305Sdelphij 25355604Sdelphij# Note: OUTPUT must terminate with the directory separator. 26355604SdelphijOUTPUT="$PWD/tests/out/" 27355604SdelphijTS="$PWD/tests/" 28355604Sdelphij 29104349SphkMYDIR="`dirname \"$0\"`" 30104349Sphkcd "$MYDIR" 31104349SphkMYDIR="`pwd`" 32355604SdelphijXMLWF="${1:-`dirname \"$MYDIR\"`/xmlwf/xmlwf}" 33355604Sdelphij# Unicode-aware diff utility 34355604SdelphijDIFF="${MYDIR}/udiffer.py" 35104349Sphk 36104349Sphk 37178848Scokane# RunXmlwfNotWF file reldir 38178848Scokane# reldir includes trailing slash 39104349SphkRunXmlwfNotWF() { 40178848Scokane file="$1" 41178848Scokane reldir="$2" 42355604Sdelphij if $XMLWF -p "$file" > /dev/null; then 43247296Sdelphij echo "Expected not well-formed: $reldir$file" 44104349Sphk return 1 45104349Sphk else 46104349Sphk return 0 47104349Sphk fi 48104349Sphk} 49104349Sphk 50178848Scokane# RunXmlwfWF file reldir 51178848Scokane# reldir includes trailing slash 52104349SphkRunXmlwfWF() { 53178848Scokane file="$1" 54178848Scokane reldir="$2" 55355604Sdelphij $XMLWF -p -N -d "$OUTPUT$reldir" "$file" > outfile || return $? 56104349Sphk read outdata < outfile 57104349Sphk if test "$outdata" = "" ; then 58178848Scokane if [ -f "out/$file" ] ; then 59355604Sdelphij $DIFF "$OUTPUT$reldir$file" "out/$file" > outfile 60104349Sphk if [ -s outfile ] ; then 61178848Scokane cp outfile "$OUTPUT$reldir$file.diff" 62178848Scokane echo "Output differs: $reldir$file" 63104349Sphk return 1 64104349Sphk fi 65104349Sphk fi 66104349Sphk return 0 67104349Sphk else 68178848Scokane echo "In $reldir: $outdata" 69104349Sphk return 1 70104349Sphk fi 71104349Sphk} 72104349Sphk 73104349SphkSUCCESS=0 74104349SphkERROR=0 75104349Sphk 76178848ScokaneUpdateStatus() { 77178848Scokane if [ "$1" -eq 0 ] ; then 78178848Scokane SUCCESS=`expr $SUCCESS + 1` 79178848Scokane else 80178848Scokane ERROR=`expr $ERROR + 1` 81178848Scokane fi 82178848Scokane} 83178848Scokane 84104349Sphk########################## 85104349Sphk# well-formed test cases # 86104349Sphk########################## 87104349Sphk 88104349Sphkcd "$TS/xmlconf" 89178848Scokanefor xmldir in ibm/valid/P* \ 90178848Scokane ibm/invalid/P* \ 91178848Scokane xmltest/valid/ext-sa \ 92178848Scokane xmltest/valid/not-sa \ 93178848Scokane xmltest/invalid \ 94178848Scokane xmltest/invalid/not-sa \ 95178848Scokane xmltest/valid/sa \ 96178848Scokane sun/valid \ 97178848Scokane sun/invalid ; do 98104349Sphk cd "$TS/xmlconf/$xmldir" 99104349Sphk mkdir -p "$OUTPUT$xmldir" 100355604Sdelphij for xmlfile in $(ls -1 *.xml | sort -d) ; do 101355604Sdelphij [[ -f "$xmlfile" ]] || continue 102178848Scokane RunXmlwfWF "$xmlfile" "$xmldir/" 103178848Scokane UpdateStatus $? 104104349Sphk done 105302305Sdelphij rm -f outfile 106104349Sphkdone 107104349Sphk 108104349Sphkcd "$TS/xmlconf/oasis" 109178848Scokanemkdir -p "$OUTPUT"oasis 110104349Sphkfor xmlfile in *pass*.xml ; do 111178848Scokane RunXmlwfWF "$xmlfile" "oasis/" 112178848Scokane UpdateStatus $? 113104349Sphkdone 114104349Sphkrm outfile 115104349Sphk 116104349Sphk############################## 117104349Sphk# not well-formed test cases # 118104349Sphk############################## 119104349Sphk 120104349Sphkcd "$TS/xmlconf" 121178848Scokanefor xmldir in ibm/not-wf/P* \ 122247296Sdelphij ibm/not-wf/p28a \ 123178848Scokane ibm/not-wf/misc \ 124178848Scokane xmltest/not-wf/ext-sa \ 125178848Scokane xmltest/not-wf/not-sa \ 126178848Scokane xmltest/not-wf/sa \ 127178848Scokane sun/not-wf ; do 128104349Sphk cd "$TS/xmlconf/$xmldir" 129104349Sphk for xmlfile in *.xml ; do 130178848Scokane RunXmlwfNotWF "$xmlfile" "$xmldir/" 131178848Scokane UpdateStatus $? 132104349Sphk done 133104349Sphkdone 134104349Sphk 135104349Sphkcd "$TS/xmlconf/oasis" 136104349Sphkfor xmlfile in *fail*.xml ; do 137178848Scokane RunXmlwfNotWF "$xmlfile" "oasis/" 138178848Scokane UpdateStatus $? 139104349Sphkdone 140104349Sphk 141104349Sphkecho "Passed: $SUCCESS" 142104349Sphkecho "Failed: $ERROR" 143