xmltest.sh revision 1.1.1.7 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 # Unicode-aware diff utility
66 DIFF="${MYDIR}/udiffer.py"
67
68
69 # RunXmlwfNotWF file reldir
70 # reldir includes trailing slash
71 RunXmlwfNotWF() {
72 file="$1"
73 reldir="$2"
74 if $XMLWF -p "$file" > /dev/null; then
75 echo "Expected not well-formed: $reldir$file"
76 return 1
77 else
78 return 0
79 fi
80 }
81
82 # RunXmlwfWF file reldir
83 # reldir includes trailing slash
84 RunXmlwfWF() {
85 file="$1"
86 reldir="$2"
87 $XMLWF -p -N -d "$OUTPUT$reldir" "$file" > outfile || return $?
88 read outdata < outfile
89 if test "$outdata" = "" ; then
90 if [ -f "out/$file" ] ; then
91 $DIFF "$OUTPUT$reldir$file" "out/$file" > outfile
92 if [ -s outfile ] ; then
93 cp outfile "$OUTPUT$reldir$file.diff"
94 echo "Output differs: $reldir$file"
95 return 1
96 fi
97 fi
98 return 0
99 else
100 echo "In $reldir: $outdata"
101 return 1
102 fi
103 }
104
105 SUCCESS=0
106 ERROR=0
107
108 UpdateStatus() {
109 if [ "$1" -eq 0 ] ; then
110 SUCCESS=`expr $SUCCESS + 1`
111 else
112 ERROR=`expr $ERROR + 1`
113 fi
114 }
115
116 ##########################
117 # well-formed test cases #
118 ##########################
119
120 cd "$TS/xmlconf"
121 for xmldir in ibm/valid/P* \
122 ibm/invalid/P* \
123 xmltest/valid/ext-sa \
124 xmltest/valid/not-sa \
125 xmltest/invalid \
126 xmltest/invalid/not-sa \
127 xmltest/valid/sa \
128 sun/valid \
129 sun/invalid ; do
130 cd "$TS/xmlconf/$xmldir"
131 mkdir -p "$OUTPUT$xmldir"
132 for xmlfile in $(ls -1 *.xml | sort -d) ; do
133 [[ -f "$xmlfile" ]] || continue
134 RunXmlwfWF "$xmlfile" "$xmldir/"
135 UpdateStatus $?
136 done
137 rm -f outfile
138 done
139
140 cd "$TS/xmlconf/oasis"
141 mkdir -p "$OUTPUT"oasis
142 for xmlfile in *pass*.xml ; do
143 RunXmlwfWF "$xmlfile" "oasis/"
144 UpdateStatus $?
145 done
146 rm outfile
147
148 ##############################
149 # not well-formed test cases #
150 ##############################
151
152 cd "$TS/xmlconf"
153 for xmldir in ibm/not-wf/P* \
154 ibm/not-wf/p28a \
155 ibm/not-wf/misc \
156 xmltest/not-wf/ext-sa \
157 xmltest/not-wf/not-sa \
158 xmltest/not-wf/sa \
159 sun/not-wf ; do
160 cd "$TS/xmlconf/$xmldir"
161 for xmlfile in *.xml ; do
162 RunXmlwfNotWF "$xmlfile" "$xmldir/"
163 UpdateStatus $?
164 done
165 done
166
167 cd "$TS/xmlconf/oasis"
168 for xmlfile in *fail*.xml ; do
169 RunXmlwfNotWF "$xmlfile" "oasis/"
170 UpdateStatus $?
171 done
172
173 echo "Passed: $SUCCESS"
174 echo "Failed: $ERROR"
175