test-driver-custom-xfail-tests.sh 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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: "abstract" XFAIL_TESTS support.
  17. . test-init.sh
  18. cat >> configure.ac <<'END'
  19. AC_SUBST([nihil], [])
  20. AC_SUBST([ac_xfail_tests], ['x5.test x6$(test_suffix)'])
  21. AC_CONFIG_FILES([sub1/Makefile sub2/Makefile])
  22. AC_OUTPUT
  23. END
  24. cat > Makefile.am <<'END'
  25. SUBDIRS = . sub1 sub2
  26. TEST_LOG_DRIVER = $(srcdir)/td
  27. TESTS = pass.test xfail.test
  28. XFAIL_TESTS = xfail.test
  29. END
  30. mkdir sub1 sub2
  31. cat > sub1/Makefile.am <<END
  32. empty =
  33. TEST_LOG_DRIVER = \$(top_srcdir)/td
  34. # XFAIL_TESTS should gracefully handle TAB characters, and multiple
  35. # whitespaces.
  36. XFAIL_TESTS =\$(empty)${tab}x1.test x2.test${tab}x3.test${tab}\
  37. x4.test ${tab} x5.test x6.test${tab}\$(empty)
  38. TESTS = pass.test x1.test x2.test x3.test x4.test x5.test x6.test
  39. END
  40. cat > sub2/Makefile.am <<'END'
  41. AUTOMAKE_OPTIONS = -Wno-portability-recursive
  42. TEST_LOG_DRIVER = $(srcdir)/../td
  43. # XFAIL_TESTS should gracefully AC_SUBST @substitution@ and
  44. # make variables indirections.
  45. an_xfail_test = x1.test
  46. test_suffix = .test
  47. v0 = x3.test
  48. v1 = v
  49. v2 = 0
  50. XFAIL_TESTS = $(an_xfail_test) x2.test @nihil@ x3${test_suffix}
  51. XFAIL_TESTS += $($(v1)$(v2)) x4.test @ac_xfail_tests@
  52. TESTS = pass.test x1.test x2.test x3.test x4.test x5.test x6.test
  53. END
  54. cat > pass.test <<'END'
  55. #!/bin/sh
  56. exit 0
  57. END
  58. cat > xfail.test <<'END'
  59. #!/bin/sh
  60. exit 1
  61. END
  62. chmod a+x pass.test xfail.test
  63. cp pass.test sub1/pass.test
  64. cp pass.test sub2/pass.test
  65. for i in 1 2 3 4 5 6; do
  66. cp xfail.test sub1/x$i.test
  67. cp xfail.test sub2/x$i.test
  68. done
  69. cat > td <<'END'
  70. #! /bin/sh
  71. set -e; set -u
  72. test_name=INVALID
  73. log_file=/dev/null
  74. trs_file=/dev/null
  75. expect_failure=no
  76. while test $# -gt 0; do
  77. case $1 in
  78. --test-name) test_name=$2; shift;;
  79. --expect-failure) expect_failure=$2; shift;;
  80. --log-file) log_file=$2; shift;;
  81. --trs-file) trs_file=$2; shift;;
  82. # Ignored.
  83. --color-tests) shift;;
  84. --enable-hard-errors) shift;;
  85. # Explicitly terminate option list.
  86. --) shift; break;;
  87. # Shouldn't happen
  88. *) echo "$0: invalid option/argument: '$1'" >&2; exit 2;;
  89. esac
  90. shift
  91. done
  92. st=0
  93. "$@" || st=$?
  94. case $st,$expect_failure in
  95. 0,no)
  96. echo "PASS: $test_name" | tee "$log_file"
  97. echo ":test-result: PASS" > "$trs_file"
  98. ;;
  99. 1,no)
  100. echo "FAIL: $test_name" | tee "$log_file"
  101. echo ":test-result: FAIL" > "$trs_file"
  102. ;;
  103. 0,yes)
  104. echo "XPASS: $test_name" | tee "$log_file"
  105. echo ":test-result: XPASS" > "$trs_file"
  106. ;;
  107. 1,yes)
  108. echo "XFAIL: $test_name" | tee "$log_file"
  109. echo ":test-result: XFAIL" > "$trs_file"
  110. ;;
  111. *)
  112. echo "INTERNAL ERROR" >&2
  113. exit 99
  114. ;;
  115. esac
  116. END
  117. chmod a+x td
  118. $ACLOCAL
  119. $AUTOCONF
  120. $AUTOMAKE
  121. ./configure
  122. run_make -O check
  123. test $(grep -c '^PASS:' stdout) -eq 3
  124. test $(grep -c '^XFAIL:' stdout) -eq 13
  125. for dir in sub1 sub2; do
  126. cd $dir
  127. cp pass.test x1.test
  128. cp x2.test pass.test
  129. run_make -O -e FAIL check
  130. test "$(cat pass.trs)" = ":test-result: FAIL"
  131. test "$(cat x1.trs)" = ":test-result: XPASS"
  132. test "$(cat x2.trs)" = ":test-result: XFAIL"
  133. grep '^FAIL: pass\.test$' stdout
  134. grep '^XPASS: x1\.test$' stdout
  135. grep '^XFAIL: x2\.test$' stdout
  136. count_test_results total=7 pass=0 xpass=1 fail=1 xfail=5 skip=0 error=0
  137. cd ..
  138. done
  139. :