xmltest.sh 5.2 KB

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