xref: /freebsd/contrib/expat/tests/xmltest.sh (revision 148a8da8)
1#! /usr/bin/env bash
2
3#   EXPAT TEST SCRIPT FOR W3C XML TEST SUITE
4
5# This script can be used to exercise Expat against the
6# w3c.org xml test suite, available from
7# http://www.w3.org/XML/Test/xmlts20020606.zip.
8
9# To run this script, first set XMLWF below so that xmlwf can be
10# found, then set the output directory with OUTPUT.
11
12# The script lists all test cases where Expat shows a discrepancy
13# from the expected result. Test cases where only the canonical
14# output differs are prefixed with "Output differs:", and a diff file
15# is generated in the appropriate subdirectory under $OUTPUT.
16
17# If there are output files provided, the script will use
18# output from xmlwf and compare the desired output against it.
19# However, one has to take into account that the canonical output
20# produced by xmlwf conforms to an older definition of canonical XML
21# and does not generate notation declarations.
22
23shopt -s nullglob
24
25MYDIR="`dirname \"$0\"`"
26cd "$MYDIR"
27MYDIR="`pwd`"
28XMLWF="${1:-`dirname \"$MYDIR\"`/xmlwf/xmlwf}"
29# XMLWF=/usr/local/bin/xmlwf
30TS="$MYDIR"
31# OUTPUT must terminate with the directory separator.
32OUTPUT="$TS/out/"
33# OUTPUT=/home/tmp/xml-testsuite-out/
34# Unicode-aware diff utility
35DIFF="$TS/udiffer.py"
36
37
38# RunXmlwfNotWF file reldir
39# reldir includes trailing slash
40RunXmlwfNotWF() {
41  file="$1"
42  reldir="$2"
43  $XMLWF -p "$file" > outfile || return $?
44  read outdata < outfile
45  if test "$outdata" = "" ; then
46      echo "Expected not well-formed: $reldir$file"
47      return 1
48  else
49      return 0
50  fi
51}
52
53# RunXmlwfWF file reldir
54# reldir includes trailing slash
55RunXmlwfWF() {
56  file="$1"
57  reldir="$2"
58  $XMLWF -p -N -d "$OUTPUT$reldir" "$file" > outfile || return $?
59  read outdata < outfile
60  if test "$outdata" = "" ; then
61      if [ -f "out/$file" ] ; then
62          $DIFF "$OUTPUT$reldir$file" "out/$file" > outfile
63          if [ -s outfile ] ; then
64              cp outfile "$OUTPUT$reldir$file.diff"
65              echo "Output differs: $reldir$file"
66              return 1
67          fi
68      fi
69      return 0
70  else
71      echo "In $reldir: $outdata"
72      return 1
73  fi
74}
75
76SUCCESS=0
77ERROR=0
78
79UpdateStatus() {
80  if [ "$1" -eq 0 ] ; then
81    SUCCESS=`expr $SUCCESS + 1`
82  else
83    ERROR=`expr $ERROR + 1`
84  fi
85}
86
87##########################
88# well-formed test cases #
89##########################
90
91cd "$TS/xmlconf"
92for xmldir in ibm/valid/P* \
93              ibm/invalid/P* \
94              xmltest/valid/ext-sa \
95              xmltest/valid/not-sa \
96              xmltest/invalid \
97              xmltest/invalid/not-sa \
98              xmltest/valid/sa \
99              sun/valid \
100              sun/invalid ; do
101  cd "$TS/xmlconf/$xmldir"
102  mkdir -p "$OUTPUT$xmldir"
103  for xmlfile in $(ls -1 *.xml | sort -d) ; do
104      [[ -f "$xmlfile" ]] || continue
105      RunXmlwfWF "$xmlfile" "$xmldir/"
106      UpdateStatus $?
107  done
108  rm -f outfile
109done
110
111cd "$TS/xmlconf/oasis"
112mkdir -p "$OUTPUT"oasis
113for xmlfile in *pass*.xml ; do
114    RunXmlwfWF "$xmlfile" "oasis/"
115    UpdateStatus $?
116done
117rm outfile
118
119##############################
120# not well-formed test cases #
121##############################
122
123cd "$TS/xmlconf"
124for xmldir in ibm/not-wf/P* \
125              ibm/not-wf/p28a \
126              ibm/not-wf/misc \
127              xmltest/not-wf/ext-sa \
128              xmltest/not-wf/not-sa \
129              xmltest/not-wf/sa \
130              sun/not-wf ; do
131  cd "$TS/xmlconf/$xmldir"
132  for xmlfile in *.xml ; do
133      RunXmlwfNotWF "$xmlfile" "$xmldir/"
134      UpdateStatus $?
135  done
136  rm outfile
137done
138
139cd "$TS/xmlconf/oasis"
140for xmlfile in *fail*.xml ; do
141    RunXmlwfNotWF "$xmlfile" "oasis/"
142    UpdateStatus $?
143done
144rm outfile
145
146echo "Passed: $SUCCESS"
147echo "Failed: $ERROR"
148