133ab7b2bSbluhm#! /usr/bin/env bash 233ab7b2bSbluhm# EXPAT TEST SCRIPT FOR W3C XML TEST SUITE 3*08819b41Sbluhm# 433ab7b2bSbluhm# This script can be used to exercise Expat against the 533ab7b2bSbluhm# w3c.org xml test suite, available from 633ab7b2bSbluhm# http://www.w3.org/XML/Test/xmlts20020606.zip. 7*08819b41Sbluhm# 833ab7b2bSbluhm# To run this script, first set XMLWF below so that xmlwf can be 933ab7b2bSbluhm# found, then set the output directory with OUTPUT. 10*08819b41Sbluhm# 1133ab7b2bSbluhm# The script lists all test cases where Expat shows a discrepancy 1233ab7b2bSbluhm# from the expected result. Test cases where only the canonical 1333ab7b2bSbluhm# output differs are prefixed with "Output differs:", and a diff file 1433ab7b2bSbluhm# is generated in the appropriate subdirectory under $OUTPUT. 15*08819b41Sbluhm# 1633ab7b2bSbluhm# If there are output files provided, the script will use 1733ab7b2bSbluhm# output from xmlwf and compare the desired output against it. 1833ab7b2bSbluhm# However, one has to take into account that the canonical output 1933ab7b2bSbluhm# produced by xmlwf conforms to an older definition of canonical XML 2033ab7b2bSbluhm# and does not generate notation declarations. 21*08819b41Sbluhm# 22*08819b41Sbluhm# __ __ _ 23*08819b41Sbluhm# ___\ \/ /_ __ __ _| |_ 24*08819b41Sbluhm# / _ \\ /| '_ \ / _` | __| 25*08819b41Sbluhm# | __// \| |_) | (_| | |_ 26*08819b41Sbluhm# \___/_/\_\ .__/ \__,_|\__| 27*08819b41Sbluhm# |_| XML parser 28*08819b41Sbluhm# 29*08819b41Sbluhm# Copyright (c) 2002-2004 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> 30*08819b41Sbluhm# Copyright (c) 2002 Karl Waclawek <karl@waclawek.net> 31*08819b41Sbluhm# Copyright (c) 2008-2019 Sebastian Pipping <sebastian@pipping.org> 32*08819b41Sbluhm# Copyright (c) 2017 Rhodri James <rhodri@wildebeest.org.uk> 33*08819b41Sbluhm# Licensed under the MIT license: 34*08819b41Sbluhm# 35*08819b41Sbluhm# Permission is hereby granted, free of charge, to any person obtaining 36*08819b41Sbluhm# a copy of this software and associated documentation files (the 37*08819b41Sbluhm# "Software"), to deal in the Software without restriction, including 38*08819b41Sbluhm# without limitation the rights to use, copy, modify, merge, publish, 39*08819b41Sbluhm# distribute, sublicense, and/or sell copies of the Software, and to permit 40*08819b41Sbluhm# persons to whom the Software is furnished to do so, subject to the 41*08819b41Sbluhm# following conditions: 42*08819b41Sbluhm# 43*08819b41Sbluhm# The above copyright notice and this permission notice shall be included 44*08819b41Sbluhm# in all copies or substantial portions of the Software. 45*08819b41Sbluhm# 46*08819b41Sbluhm# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 47*08819b41Sbluhm# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 48*08819b41Sbluhm# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 49*08819b41Sbluhm# NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 50*08819b41Sbluhm# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 51*08819b41Sbluhm# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 52*08819b41Sbluhm# USE OR OTHER DEALINGS IN THE SOFTWARE. 5333ab7b2bSbluhm 5433ab7b2bSbluhmshopt -s nullglob 5533ab7b2bSbluhm 5628ce3119Sbluhm# Note: OUTPUT must terminate with the directory separator. 5728ce3119SbluhmOUTPUT="$PWD/tests/out/" 5828ce3119SbluhmTS="$PWD/tests/" 5928ce3119Sbluhm 6033ab7b2bSbluhmMYDIR="`dirname \"$0\"`" 6133ab7b2bSbluhmcd "$MYDIR" 6233ab7b2bSbluhmMYDIR="`pwd`" 6333ab7b2bSbluhmXMLWF="${1:-`dirname \"$MYDIR\"`/xmlwf/xmlwf}" 649b8e2351Sbluhm# Unicode-aware diff utility 6528ce3119SbluhmDIFF="${MYDIR}/udiffer.py" 6633ab7b2bSbluhm 6733ab7b2bSbluhm 6833ab7b2bSbluhm# RunXmlwfNotWF file reldir 6933ab7b2bSbluhm# reldir includes trailing slash 7033ab7b2bSbluhmRunXmlwfNotWF() { 7133ab7b2bSbluhm file="$1" 7233ab7b2bSbluhm reldir="$2" 7328ce3119Sbluhm if $XMLWF -p "$file" > /dev/null; then 7433ab7b2bSbluhm echo "Expected not well-formed: $reldir$file" 7533ab7b2bSbluhm return 1 7633ab7b2bSbluhm else 7733ab7b2bSbluhm return 0 7833ab7b2bSbluhm fi 7933ab7b2bSbluhm} 8033ab7b2bSbluhm 8133ab7b2bSbluhm# RunXmlwfWF file reldir 8233ab7b2bSbluhm# reldir includes trailing slash 8333ab7b2bSbluhmRunXmlwfWF() { 8433ab7b2bSbluhm file="$1" 8533ab7b2bSbluhm reldir="$2" 869b8e2351Sbluhm $XMLWF -p -N -d "$OUTPUT$reldir" "$file" > outfile || return $? 8733ab7b2bSbluhm read outdata < outfile 8833ab7b2bSbluhm if test "$outdata" = "" ; then 8933ab7b2bSbluhm if [ -f "out/$file" ] ; then 909b8e2351Sbluhm $DIFF "$OUTPUT$reldir$file" "out/$file" > outfile 9133ab7b2bSbluhm if [ -s outfile ] ; then 9233ab7b2bSbluhm cp outfile "$OUTPUT$reldir$file.diff" 9333ab7b2bSbluhm echo "Output differs: $reldir$file" 9433ab7b2bSbluhm return 1 9533ab7b2bSbluhm fi 9633ab7b2bSbluhm fi 9733ab7b2bSbluhm return 0 9833ab7b2bSbluhm else 9933ab7b2bSbluhm echo "In $reldir: $outdata" 10033ab7b2bSbluhm return 1 10133ab7b2bSbluhm fi 10233ab7b2bSbluhm} 10333ab7b2bSbluhm 10433ab7b2bSbluhmSUCCESS=0 10533ab7b2bSbluhmERROR=0 10633ab7b2bSbluhm 10733ab7b2bSbluhmUpdateStatus() { 10833ab7b2bSbluhm if [ "$1" -eq 0 ] ; then 10933ab7b2bSbluhm SUCCESS=`expr $SUCCESS + 1` 11033ab7b2bSbluhm else 11133ab7b2bSbluhm ERROR=`expr $ERROR + 1` 11233ab7b2bSbluhm fi 11333ab7b2bSbluhm} 11433ab7b2bSbluhm 11533ab7b2bSbluhm########################## 11633ab7b2bSbluhm# well-formed test cases # 11733ab7b2bSbluhm########################## 11833ab7b2bSbluhm 11933ab7b2bSbluhmcd "$TS/xmlconf" 12033ab7b2bSbluhmfor xmldir in ibm/valid/P* \ 12133ab7b2bSbluhm ibm/invalid/P* \ 12233ab7b2bSbluhm xmltest/valid/ext-sa \ 12333ab7b2bSbluhm xmltest/valid/not-sa \ 12433ab7b2bSbluhm xmltest/invalid \ 12533ab7b2bSbluhm xmltest/invalid/not-sa \ 12633ab7b2bSbluhm xmltest/valid/sa \ 12733ab7b2bSbluhm sun/valid \ 12833ab7b2bSbluhm sun/invalid ; do 12933ab7b2bSbluhm cd "$TS/xmlconf/$xmldir" 13033ab7b2bSbluhm mkdir -p "$OUTPUT$xmldir" 13133ab7b2bSbluhm for xmlfile in $(ls -1 *.xml | sort -d) ; do 13233ab7b2bSbluhm [[ -f "$xmlfile" ]] || continue 13333ab7b2bSbluhm RunXmlwfWF "$xmlfile" "$xmldir/" 13433ab7b2bSbluhm UpdateStatus $? 13533ab7b2bSbluhm done 13633ab7b2bSbluhm rm -f outfile 13733ab7b2bSbluhmdone 13833ab7b2bSbluhm 13933ab7b2bSbluhmcd "$TS/xmlconf/oasis" 14033ab7b2bSbluhmmkdir -p "$OUTPUT"oasis 14133ab7b2bSbluhmfor xmlfile in *pass*.xml ; do 14233ab7b2bSbluhm RunXmlwfWF "$xmlfile" "oasis/" 14333ab7b2bSbluhm UpdateStatus $? 14433ab7b2bSbluhmdone 14533ab7b2bSbluhmrm outfile 14633ab7b2bSbluhm 14733ab7b2bSbluhm############################## 14833ab7b2bSbluhm# not well-formed test cases # 14933ab7b2bSbluhm############################## 15033ab7b2bSbluhm 15133ab7b2bSbluhmcd "$TS/xmlconf" 15233ab7b2bSbluhmfor xmldir in ibm/not-wf/P* \ 15333ab7b2bSbluhm ibm/not-wf/p28a \ 15433ab7b2bSbluhm ibm/not-wf/misc \ 15533ab7b2bSbluhm xmltest/not-wf/ext-sa \ 15633ab7b2bSbluhm xmltest/not-wf/not-sa \ 15733ab7b2bSbluhm xmltest/not-wf/sa \ 15833ab7b2bSbluhm sun/not-wf ; do 15933ab7b2bSbluhm cd "$TS/xmlconf/$xmldir" 16033ab7b2bSbluhm for xmlfile in *.xml ; do 16133ab7b2bSbluhm RunXmlwfNotWF "$xmlfile" "$xmldir/" 16233ab7b2bSbluhm UpdateStatus $? 16333ab7b2bSbluhm done 16433ab7b2bSbluhmdone 16533ab7b2bSbluhm 16633ab7b2bSbluhmcd "$TS/xmlconf/oasis" 16733ab7b2bSbluhmfor xmlfile in *fail*.xml ; do 16833ab7b2bSbluhm RunXmlwfNotWF "$xmlfile" "oasis/" 16933ab7b2bSbluhm UpdateStatus $? 17033ab7b2bSbluhmdone 17133ab7b2bSbluhm 17233ab7b2bSbluhmecho "Passed: $SUCCESS" 17333ab7b2bSbluhmecho "Failed: $ERROR" 174