test-metadata-global-result.sh 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. #! /bin/sh
  2. # Copyright (C) 2011-2017 Free Software Foundation, Inc.
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2, or (at your option)
  7. # any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. # Parallel testsuite harness: check APIs for the registering the
  17. # "global test result" in '*.trs' files, as documented in the automake
  18. # manual.
  19. . test-init.sh
  20. cat >> configure.ac << 'END'
  21. AC_OUTPUT
  22. END
  23. cat > Makefile.am << 'END'
  24. TEST_EXTENSIONS = .test .x
  25. TEST_LOG_DRIVER = ./dummy-driver
  26. X_LOG_DRIVER = ./dummy-driver
  27. TESTS = foo.test zar-doz.test
  28. END
  29. cat > dummy-driver <<'END'
  30. #! /bin/sh
  31. set -e; set -u
  32. while test $# -gt 0; do
  33. case $1 in
  34. --log-file) log_file=$2; shift;;
  35. --trs-file) trs_file=$2; shift;;
  36. --test-name) test_name=$2; shift;;
  37. --expect-failure|--color-tests|--enable-hard-errors) shift;;
  38. --) shift; break;;
  39. *) echo "$0: invalid option/argument: '$1'" >&2; exit 2;;
  40. esac
  41. shift
  42. done
  43. echo logloglog > $log_file
  44. cp $1 $trs_file
  45. END
  46. chmod a+x dummy-driver
  47. # Do this in a subroutine to avoid quoting problem in the backticked
  48. # command substitution below.
  49. get_escaped_line()
  50. {
  51. sed -e 's,[$^/\\\.],\\&,g' -e 1q "$@"
  52. }
  53. have_result ()
  54. {
  55. cat > exp; echo >> exp; echo logloglog >> exp
  56. eline=$(get_escaped_line exp)
  57. sed -n -e "/^$eline$/,/^logloglog$/p" test-suite.log > got
  58. cat exp; cat got
  59. diff exp got
  60. }
  61. $ACLOCAL
  62. $AUTOCONF
  63. $AUTOMAKE
  64. ./configure
  65. : Basic checks.
  66. echo :global-test-result: PASS > foo.test
  67. echo :global-test-result: ERROR > zar-doz.x
  68. $MAKE check
  69. cat test-suite.log
  70. have_result <<END
  71. PASS: foo
  72. =========
  73. END
  74. have_result <<END
  75. ERROR: zar-doz
  76. ==============
  77. END
  78. : Try usage documented in the manual.
  79. echo :global-test-result: PASS/SKIP > foo.test
  80. echo :global-test-result: ALMOST PASSED > zar-doz.x
  81. $MAKE check
  82. cat test-suite.log
  83. have_result <<END
  84. PASS/SKIP: foo
  85. ==============
  86. END
  87. have_result <<END
  88. ALMOST PASSED: zar-doz
  89. ======================
  90. END
  91. : Fields ':test-result:' does not interfere with the global test result.
  92. cat > foo.test << 'END'
  93. :test-result: FAIL
  94. :global-test-result: PASS
  95. :test-result: ERROR
  96. END
  97. cat > zar-doz.x << 'END'
  98. :global-test-result: FAIL
  99. :test-result: SKIP
  100. :test-result: XFAIL
  101. END
  102. $MAKE check && exit 1
  103. cat test-suite.log
  104. have_result <<END
  105. PASS: foo
  106. =========
  107. END
  108. have_result <<END
  109. FAIL: zar-doz
  110. =============
  111. END
  112. : What happens when ':global-test-result:' is absent.
  113. cat > foo.test << 'END'
  114. :test-result: PASS
  115. :test-result: ERROR
  116. END
  117. : > zar-doz.x
  118. $MAKE check && exit 1
  119. cat test-suite.log
  120. have_result <<END
  121. RUN: foo
  122. ========
  123. END
  124. have_result <<END
  125. RUN: zar-doz
  126. ============
  127. END
  128. # Leading and trailing whitespace gets eaten/normalized.
  129. echo ":global-test-result:SKIP${tab} ${tab}${tab}" > foo.test
  130. echo ":global-test-result:${tab} ${tab}XFAIL ${tab} " > zar-doz.x
  131. $MAKE check
  132. cat test-suite.log
  133. have_result <<END
  134. SKIP: foo
  135. =========
  136. END
  137. have_result <<END
  138. XFAIL: zar-doz
  139. ==============
  140. END
  141. # Whitespaces before and after ':global-test-result:' are handled OK.
  142. echo " $tab:global-test-result:PASS" > foo.test
  143. echo "${tab}${tab}:global-test-result:${tab} ${tab}SKIP" > zar-doz.x
  144. $MAKE check
  145. cat test-suite.log
  146. have_result <<END
  147. PASS: foo
  148. =========
  149. END
  150. have_result <<END
  151. SKIP: zar-doz
  152. =============
  153. END
  154. :