xmltest.sh 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. <[email protected]>
  30. # Copyright (c) 2002 Karl Waclawek <[email protected]>
  31. # Copyright (c) 2008-2019 Sebastian Pipping <[email protected]>
  32. # Copyright (c) 2017 Rhodri James <[email protected]>
  33. # Copyright (c) 2025 Hanno Böck <[email protected]>
  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. shopt -s nullglob
  55. # Note: OUTPUT must terminate with the directory separator.
  56. OUTPUT="$PWD/tests/out/"
  57. TS="$PWD/tests/"
  58. MYDIR="`dirname \"$0\"`"
  59. cd "$MYDIR"
  60. MYDIR="`pwd`"
  61. XMLWF="${1:-`dirname \"$MYDIR\"`/xmlwf/xmlwf}"
  62. # Unicode-aware diff utility
  63. DIFF="${MYDIR}/udiffer.py"
  64. # RunXmlwfNotWF file reldir
  65. # reldir includes trailing slash
  66. RunXmlwfNotWF() {
  67. file="$1"
  68. reldir="$2"
  69. if $XMLWF -p "$file" > /dev/null; then
  70. echo "Expected not well-formed: $reldir$file"
  71. return 1
  72. else
  73. return 0
  74. fi
  75. }
  76. # RunXmlwfWF file reldir
  77. # reldir includes trailing slash
  78. RunXmlwfWF() {
  79. file="$1"
  80. reldir="$2"
  81. $XMLWF -p -N -d "$OUTPUT$reldir" "$file" > outfile || return $?
  82. read outdata < outfile
  83. if test "$outdata" = "" ; then
  84. if [ -f "out/$file" ] ; then
  85. $DIFF "$OUTPUT$reldir$file" "out/$file" > outfile
  86. if [ -s outfile ] ; then
  87. cp outfile "$OUTPUT$reldir$file.diff"
  88. echo "Output differs: $reldir$file"
  89. return 1
  90. fi
  91. fi
  92. return 0
  93. else
  94. echo "In $reldir: $outdata"
  95. return 1
  96. fi
  97. }
  98. SUCCESS=0
  99. ERROR=0
  100. UpdateStatus() {
  101. if [ "$1" -eq 0 ] ; then
  102. SUCCESS=`expr $SUCCESS + 1`
  103. else
  104. ERROR=`expr $ERROR + 1`
  105. fi
  106. }
  107. ##########################
  108. # well-formed test cases #
  109. ##########################
  110. cd "$TS/xmlconf"
  111. for xmldir in ibm/valid/P* \
  112. ibm/invalid/P* \
  113. xmltest/valid/ext-sa \
  114. xmltest/valid/not-sa \
  115. xmltest/invalid \
  116. xmltest/invalid/not-sa \
  117. xmltest/valid/sa \
  118. sun/valid \
  119. sun/invalid ; do
  120. cd "$TS/xmlconf/$xmldir"
  121. mkdir -p "$OUTPUT$xmldir"
  122. for xmlfile in $(ls -1 *.xml | sort -d) ; do
  123. [[ -f "$xmlfile" ]] || continue
  124. RunXmlwfWF "$xmlfile" "$xmldir/"
  125. UpdateStatus $?
  126. done
  127. rm -f outfile
  128. done
  129. cd "$TS/xmlconf/oasis"
  130. mkdir -p "$OUTPUT"oasis
  131. for xmlfile in *pass*.xml ; do
  132. RunXmlwfWF "$xmlfile" "oasis/"
  133. UpdateStatus $?
  134. done
  135. rm outfile
  136. ##############################
  137. # not well-formed test cases #
  138. ##############################
  139. cd "$TS/xmlconf"
  140. for xmldir in ibm/not-wf/P* \
  141. ibm/not-wf/p28a \
  142. ibm/not-wf/misc \
  143. xmltest/not-wf/ext-sa \
  144. xmltest/not-wf/not-sa \
  145. xmltest/not-wf/sa \
  146. sun/not-wf ; do
  147. cd "$TS/xmlconf/$xmldir"
  148. for xmlfile in *.xml ; do
  149. RunXmlwfNotWF "$xmlfile" "$xmldir/"
  150. UpdateStatus $?
  151. done
  152. done
  153. cd "$TS/xmlconf/oasis"
  154. for xmlfile in *fail*.xml ; do
  155. RunXmlwfNotWF "$xmlfile" "oasis/"
  156. UpdateStatus $?
  157. done
  158. echo "Passed: $SUCCESS"
  159. echo "Failed: $ERROR"