test-metadata-global-log.sh 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. # Custom test drivers and parallel test harness: check the documented
  17. # semantics for deciding when the content of a test log file should be
  18. # copied in the global test-suite.log file. Currently, this is done
  19. # with the use of the reStructuredText field ':copy-in-global-log:' in
  20. # the associated '.trs' files.
  21. . test-init.sh
  22. cat >> configure.ac << 'END'
  23. AC_OUTPUT
  24. END
  25. cat > Makefile.am << 'END'
  26. TEST_LOG_DRIVER = ./passthrough-driver
  27. TEST_LOG_COMPILER = $(SHELL) -e
  28. END
  29. cat > passthrough-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 "$test_name: RUN"
  44. "$@" >$log_file 2>&1 5>$trs_file
  45. END
  46. chmod a+x passthrough-driver
  47. # The ':test-result:' and ':recheck:' fields and the first line of the
  48. # log file should be be irrelevant for the decision of whether a test
  49. # output is to be copied in the 'test-suite.log'.
  50. cat > no-1.test <<END
  51. echo :test-result: SKIP >&5
  52. echo :copy-in-global-log: no >&5
  53. echo :test-result: FAIL >&5
  54. echo :test-result: XPASS >&5
  55. echo not seen 1
  56. END
  57. # In the last line, with leading and trailing whitespace in the value.
  58. cat > no-2.test <<END
  59. echo ":test-result: FAIL" >&5
  60. echo "not seen 2"
  61. echo ":recheck: yes" >&5
  62. echo ":copy-in-global-log:$tab $tab no $tab" >&5
  63. END
  64. for RES in XPASS FAIL XFAIL SKIP ERROR UNKNOWN; do
  65. unindent > $RES.test <<END
  66. echo :test-result: $RES >&5
  67. echo :copy-in-global-log: no >&5
  68. echo not seen $RES
  69. END
  70. done
  71. # In the first line, with no whitespace.
  72. cat > no-3.test <<END
  73. echo :copy-in-global-log:no >&5
  74. echo ":test-result: FAIL" >&5
  75. echo "not seen 3"
  76. END
  77. # Leading whitespace before the field.
  78. cat > no-4.test <<END
  79. echo ":test-result: FAIL" >&5
  80. echo " $tab $tab$tab :copy-in-global-log: no" >&5
  81. echo "not seen 4"
  82. END
  83. cat > yes-1.test <<END
  84. echo :test-result: PASS >&5
  85. echo :copy-in-global-log: yes >&5
  86. echo seen yes 1
  87. END
  88. # A lacking ':copy-in-global-log:' implies that the content of
  89. # the log file should be copied.
  90. cat > yes-2.test <<END
  91. echo :test-result: PASS >&5
  92. echo seen yes 2
  93. END
  94. # Three corner cases.
  95. cat > corn-1.test <<END
  96. echo seen corn 1
  97. echo ':copy-in-global-log:' >&5
  98. END
  99. cat > corn-2.test <<END
  100. echo seen corn 2
  101. echo '$tab $tab$tab' >&5
  102. END
  103. cat > corn-3.test <<'END'
  104. echo seen corn 31
  105. echo ':copy-in-global-log:#@%!' >&5
  106. echo seen corn 32
  107. END
  108. echo TESTS = *.test >> Makefile.am
  109. $ACLOCAL
  110. $AUTOCONF
  111. $AUTOMAKE
  112. ./configure
  113. # We don't care about the exit status of "make check" here, that
  114. # should be checked in other tests.
  115. $MAKE check || :
  116. cat test-suite.log
  117. grep '^seen yes 1$' test-suite.log
  118. grep '^seen yes 2$' test-suite.log
  119. grep '^seen corn 1$' test-suite.log
  120. grep '^seen corn 2$' test-suite.log
  121. grep '^seen corn 31$' test-suite.log
  122. grep '^seen corn 32$' test-suite.log
  123. $FGREP 'not seen' test-suite.log && exit 1
  124. :