xmltest.sh 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. MYDIR="`dirname \"$0\"`"
  19. cd "$MYDIR"
  20. MYDIR="`pwd`"
  21. XMLWF="${1:-`dirname \"$MYDIR\"`/xmlwf/xmlwf}"
  22. # XMLWF=/usr/local/bin/xmlwf
  23. TS="$MYDIR"
  24. # OUTPUT must terminate with the directory separator.
  25. OUTPUT="$TS/out/"
  26. # OUTPUT=/home/tmp/xml-testsuite-out/
  27. # Unicode-aware diff utility
  28. DIFF="$TS/udiffer.py"
  29. # RunXmlwfNotWF file reldir
  30. # reldir includes trailing slash
  31. RunXmlwfNotWF() {
  32. file="$1"
  33. reldir="$2"
  34. $XMLWF -p "$file" > outfile || return $?
  35. read outdata < outfile
  36. if test "$outdata" = "" ; then
  37. echo "Expected not well-formed: $reldir$file"
  38. return 1
  39. else
  40. return 0
  41. fi
  42. }
  43. # RunXmlwfWF file reldir
  44. # reldir includes trailing slash
  45. RunXmlwfWF() {
  46. file="$1"
  47. reldir="$2"
  48. $XMLWF -p -N -d "$OUTPUT$reldir" "$file" > outfile || return $?
  49. read outdata < outfile
  50. if test "$outdata" = "" ; then
  51. if [ -f "out/$file" ] ; then
  52. $DIFF "$OUTPUT$reldir$file" "out/$file" > outfile
  53. if [ -s outfile ] ; then
  54. cp outfile "$OUTPUT$reldir$file.diff"
  55. echo "Output differs: $reldir$file"
  56. return 1
  57. fi
  58. fi
  59. return 0
  60. else
  61. echo "In $reldir: $outdata"
  62. return 1
  63. fi
  64. }
  65. SUCCESS=0
  66. ERROR=0
  67. UpdateStatus() {
  68. if [ "$1" -eq 0 ] ; then
  69. SUCCESS=`expr $SUCCESS + 1`
  70. else
  71. ERROR=`expr $ERROR + 1`
  72. fi
  73. }
  74. ##########################
  75. # well-formed test cases #
  76. ##########################
  77. cd "$TS/xmlconf"
  78. for xmldir in ibm/valid/P* \
  79. ibm/invalid/P* \
  80. xmltest/valid/ext-sa \
  81. xmltest/valid/not-sa \
  82. xmltest/invalid \
  83. xmltest/invalid/not-sa \
  84. xmltest/valid/sa \
  85. sun/valid \
  86. sun/invalid ; do
  87. cd "$TS/xmlconf/$xmldir"
  88. mkdir -p "$OUTPUT$xmldir"
  89. for xmlfile in $(ls -1 *.xml | sort -d) ; do
  90. [[ -f "$xmlfile" ]] || continue
  91. RunXmlwfWF "$xmlfile" "$xmldir/"
  92. UpdateStatus $?
  93. done
  94. rm -f outfile
  95. done
  96. cd "$TS/xmlconf/oasis"
  97. mkdir -p "$OUTPUT"oasis
  98. for xmlfile in *pass*.xml ; do
  99. RunXmlwfWF "$xmlfile" "oasis/"
  100. UpdateStatus $?
  101. done
  102. rm outfile
  103. ##############################
  104. # not well-formed test cases #
  105. ##############################
  106. cd "$TS/xmlconf"
  107. for xmldir in ibm/not-wf/P* \
  108. ibm/not-wf/p28a \
  109. ibm/not-wf/misc \
  110. xmltest/not-wf/ext-sa \
  111. xmltest/not-wf/not-sa \
  112. xmltest/not-wf/sa \
  113. sun/not-wf ; do
  114. cd "$TS/xmlconf/$xmldir"
  115. for xmlfile in *.xml ; do
  116. RunXmlwfNotWF "$xmlfile" "$xmldir/"
  117. UpdateStatus $?
  118. done
  119. rm outfile
  120. done
  121. cd "$TS/xmlconf/oasis"
  122. for xmlfile in *fail*.xml ; do
  123. RunXmlwfNotWF "$xmlfile" "oasis/"
  124. UpdateStatus $?
  125. done
  126. rm outfile
  127. echo "Passed: $SUCCESS"
  128. echo "Failed: $ERROR"