xmltest.sh 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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="`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 *.xml ; do
  88. RunXmlwfWF "$xmlfile" "$xmldir/"
  89. UpdateStatus $?
  90. done
  91. rm -f outfile
  92. done
  93. cd "$TS/xmlconf/oasis"
  94. mkdir -p "$OUTPUT"oasis
  95. for xmlfile in *pass*.xml ; do
  96. RunXmlwfWF "$xmlfile" "oasis/"
  97. UpdateStatus $?
  98. done
  99. rm outfile
  100. ##############################
  101. # not well-formed test cases #
  102. ##############################
  103. cd "$TS/xmlconf"
  104. for xmldir in ibm/not-wf/P* \
  105. ibm/not-wf/p28a \
  106. ibm/not-wf/misc \
  107. xmltest/not-wf/ext-sa \
  108. xmltest/not-wf/not-sa \
  109. xmltest/not-wf/sa \
  110. sun/not-wf ; do
  111. cd "$TS/xmlconf/$xmldir"
  112. for xmlfile in *.xml ; do
  113. RunXmlwfNotWF "$xmlfile" "$xmldir/"
  114. UpdateStatus $?
  115. done
  116. rm outfile
  117. done
  118. cd "$TS/xmlconf/oasis"
  119. for xmlfile in *fail*.xml ; do
  120. RunXmlwfNotWF "$xmlfile" "oasis/"
  121. UpdateStatus $?
  122. done
  123. rm outfile
  124. echo "Passed: $SUCCESS"
  125. echo "Failed: $ERROR"