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