1 1.1.1.3 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.1.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.1.1.3 spz shopt -s nullglob 24 1.1.1.3 spz 25 1.1.1.5 maya # Note: OUTPUT must terminate with the directory separator. 26 1.1.1.5 maya OUTPUT="$PWD/tests/out/" 27 1.1.1.5 maya TS="$PWD/tests/" 28 1.1.1.5 maya 29 1.1 tron MYDIR="`dirname \"$0\"`" 30 1.1 tron cd "$MYDIR" 31 1.1 tron MYDIR="`pwd`" 32 1.1.1.4 christos XMLWF="${1:-`dirname \"$MYDIR\"`/xmlwf/xmlwf}" 33 1.1.1.5 maya # Unicode-aware diff utility 34 1.1.1.5 maya DIFF="${MYDIR}/udiffer.py" 35 1.1 tron 36 1.1 tron 37 1.1 tron # RunXmlwfNotWF file reldir 38 1.1 tron # reldir includes trailing slash 39 1.1 tron RunXmlwfNotWF() { 40 1.1 tron file="$1" 41 1.1 tron reldir="$2" 42 1.1.1.5 maya if $XMLWF -p "$file" > /dev/null; then 43 1.1.1.2 spz echo "Expected not well-formed: $reldir$file" 44 1.1 tron return 1 45 1.1 tron else 46 1.1 tron return 0 47 1.1 tron fi 48 1.1 tron } 49 1.1 tron 50 1.1 tron # RunXmlwfWF file reldir 51 1.1 tron # reldir includes trailing slash 52 1.1 tron RunXmlwfWF() { 53 1.1 tron file="$1" 54 1.1 tron reldir="$2" 55 1.1.1.5 maya $XMLWF -p -N -d "$OUTPUT$reldir" "$file" > outfile || return $? 56 1.1 tron read outdata < outfile 57 1.1 tron if test "$outdata" = "" ; then 58 1.1 tron if [ -f "out/$file" ] ; then 59 1.1.1.5 maya $DIFF "$OUTPUT$reldir$file" "out/$file" > outfile 60 1.1 tron if [ -s outfile ] ; then 61 1.1 tron cp outfile "$OUTPUT$reldir$file.diff" 62 1.1 tron echo "Output differs: $reldir$file" 63 1.1 tron return 1 64 1.1 tron fi 65 1.1 tron fi 66 1.1 tron return 0 67 1.1 tron else 68 1.1 tron echo "In $reldir: $outdata" 69 1.1 tron return 1 70 1.1 tron fi 71 1.1 tron } 72 1.1 tron 73 1.1 tron SUCCESS=0 74 1.1 tron ERROR=0 75 1.1 tron 76 1.1 tron UpdateStatus() { 77 1.1 tron if [ "$1" -eq 0 ] ; then 78 1.1 tron SUCCESS=`expr $SUCCESS + 1` 79 1.1 tron else 80 1.1 tron ERROR=`expr $ERROR + 1` 81 1.1 tron fi 82 1.1 tron } 83 1.1 tron 84 1.1 tron ########################## 85 1.1 tron # well-formed test cases # 86 1.1 tron ########################## 87 1.1 tron 88 1.1 tron cd "$TS/xmlconf" 89 1.1 tron for xmldir in ibm/valid/P* \ 90 1.1 tron ibm/invalid/P* \ 91 1.1 tron xmltest/valid/ext-sa \ 92 1.1 tron xmltest/valid/not-sa \ 93 1.1 tron xmltest/invalid \ 94 1.1 tron xmltest/invalid/not-sa \ 95 1.1 tron xmltest/valid/sa \ 96 1.1 tron sun/valid \ 97 1.1 tron sun/invalid ; do 98 1.1 tron cd "$TS/xmlconf/$xmldir" 99 1.1 tron mkdir -p "$OUTPUT$xmldir" 100 1.1.1.4 christos for xmlfile in $(ls -1 *.xml | sort -d) ; do 101 1.1.1.4 christos [[ -f "$xmlfile" ]] || continue 102 1.1 tron RunXmlwfWF "$xmlfile" "$xmldir/" 103 1.1 tron UpdateStatus $? 104 1.1 tron done 105 1.1.1.3 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.1.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 done 134 1.1 tron 135 1.1 tron cd "$TS/xmlconf/oasis" 136 1.1 tron for xmlfile in *fail*.xml ; do 137 1.1 tron RunXmlwfNotWF "$xmlfile" "oasis/" 138 1.1 tron UpdateStatus $? 139 1.1 tron done 140 1.1 tron 141 1.1 tron echo "Passed: $SUCCESS" 142 1.1 tron echo "Failed: $ERROR" 143