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