xmltest.sh 3.6 KB

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