xmltest.sh revision 1.5.4.1 1 #! /usr/bin/env bash
2 # EXPAT TEST SCRIPT FOR W3C XML TEST SUITE
3 #
4 # This script can be used to exercise Expat against the
5 # w3c.org xml test suite, available from:
6 # https://www.w3.org/XML/Test/xmlts20020606.zip
7 #
8 # To run this script, first set XMLWF below so that xmlwf can be
9 # found, then set the output directory with OUTPUT.
10 #
11 # The script lists all test cases where Expat shows a discrepancy
12 # from the expected result. Test cases where only the canonical
13 # output differs are prefixed with "Output differs:", and a diff file
14 # is generated in the appropriate subdirectory under $OUTPUT.
15 #
16 # If there are output files provided, the script will use
17 # output from xmlwf and compare the desired output against it.
18 # However, one has to take into account that the canonical output
19 # produced by xmlwf conforms to an older definition of canonical XML
20 # and does not generate notation declarations.
21 #
22 # __ __ _
23 # ___\ \/ /_ __ __ _| |_
24 # / _ \\ /| '_ \ / _` | __|
25 # | __// \| |_) | (_| | |_
26 # \___/_/\_\ .__/ \__,_|\__|
27 # |_| XML parser
28 #
29 # Copyright (c) 2002-2004 Fred L. Drake, Jr. <fdrake (at] users.sourceforge.net>
30 # Copyright (c) 2002 Karl Waclawek <karl (at] waclawek.net>
31 # Copyright (c) 2008-2019 Sebastian Pipping <sebastian (at] pipping.org>
32 # Copyright (c) 2017 Rhodri James <rhodri (at] wildebeest.org.uk>
33 # Copyright (c) 2025 Hanno Bck <hanno (at] gentoo.org>
34 # Licensed under the MIT license:
35 #
36 # Permission is hereby granted, free of charge, to any person obtaining
37 # a copy of this software and associated documentation files (the
38 # "Software"), to deal in the Software without restriction, including
39 # without limitation the rights to use, copy, modify, merge, publish,
40 # distribute, sublicense, and/or sell copies of the Software, and to permit
41 # persons to whom the Software is furnished to do so, subject to the
42 # following conditions:
43 #
44 # The above copyright notice and this permission notice shall be included
45 # in all copies or substantial portions of the Software.
46 #
47 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
48 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
49 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
50 # NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
51 # DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
52 # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
53 # USE OR OTHER DEALINGS IN THE SOFTWARE.
54
55 shopt -s nullglob
56
57 # Note: OUTPUT must terminate with the directory separator.
58 OUTPUT="$PWD/tests/out/"
59 TS="$PWD/tests/"
60
61 MYDIR="`dirname \"$0\"`"
62 cd "$MYDIR"
63 MYDIR="`pwd`"
64 #XMLWF="${1:-`dirname \"$MYDIR\"`/xmlwf/xmlwf}"
65 XMLWF=/usr/bin/xmlwf
66 # Unicode-aware diff utility
67 DIFF="${MYDIR}/udiffer.py"
68
69
70 # RunXmlwfNotWF file reldir
71 # reldir includes trailing slash
72 RunXmlwfNotWF() {
73 file="$1"
74 reldir="$2"
75 if $XMLWF -p "$file" > /dev/null; then
76 echo "Expected not well-formed: $reldir$file"
77 return 1
78 else
79 return 0
80 fi
81 }
82
83 # RunXmlwfWF file reldir
84 # reldir includes trailing slash
85 RunXmlwfWF() {
86 file="$1"
87 reldir="$2"
88 $XMLWF -p -N -d "$OUTPUT$reldir" "$file" > outfile || return $?
89 read outdata < outfile
90 if test "$outdata" = "" ; then
91 if [ -f "out/$file" ] ; then
92 $DIFF "$OUTPUT$reldir$file" "out/$file" > outfile
93 if [ -s outfile ] ; then
94 cp outfile "$OUTPUT$reldir$file.diff"
95 echo "Output differs: $reldir$file"
96 return 1
97 fi
98 fi
99 return 0
100 else
101 echo "In $reldir: $outdata"
102 return 1
103 fi
104 }
105
106 SUCCESS=0
107 ERROR=0
108
109 UpdateStatus() {
110 if [ "$1" -eq 0 ] ; then
111 SUCCESS=`expr $SUCCESS + 1`
112 else
113 ERROR=`expr $ERROR + 1`
114 fi
115 }
116
117 ##########################
118 # well-formed test cases #
119 ##########################
120
121 cd "$TS/xmlconf"
122 for xmldir in ibm/valid/P* \
123 ibm/invalid/P* \
124 xmltest/valid/ext-sa \
125 xmltest/valid/not-sa \
126 xmltest/invalid \
127 xmltest/invalid/not-sa \
128 xmltest/valid/sa \
129 sun/valid \
130 sun/invalid ; do
131 cd "$TS/xmlconf/$xmldir"
132 mkdir -p "$OUTPUT$xmldir"
133 for xmlfile in $(ls -1 *.xml | sort -d) ; do
134 [[ -f "$xmlfile" ]] || continue
135 RunXmlwfWF "$xmlfile" "$xmldir/"
136 UpdateStatus $?
137 done
138 rm -f outfile
139 done
140
141 cd "$TS/xmlconf/oasis"
142 mkdir -p "$OUTPUT"oasis
143 for xmlfile in *pass*.xml ; do
144 RunXmlwfWF "$xmlfile" "oasis/"
145 UpdateStatus $?
146 done
147 rm outfile
148
149 ##############################
150 # not well-formed test cases #
151 ##############################
152
153 cd "$TS/xmlconf"
154 for xmldir in ibm/not-wf/P* \
155 ibm/not-wf/p28a \
156 ibm/not-wf/misc \
157 xmltest/not-wf/ext-sa \
158 xmltest/not-wf/not-sa \
159 xmltest/not-wf/sa \
160 sun/not-wf ; do
161 cd "$TS/xmlconf/$xmldir"
162 for xmlfile in *.xml ; do
163 RunXmlwfNotWF "$xmlfile" "$xmldir/"
164 UpdateStatus $?
165 done
166 done
167
168 cd "$TS/xmlconf/oasis"
169 for xmlfile in *fail*.xml ; do
170 RunXmlwfNotWF "$xmlfile" "oasis/"
171 UpdateStatus $?
172 done
173
174 echo "Passed: $SUCCESS"
175 echo "Failed: $ERROR"
176