xmltest.sh 3.5 KB

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