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