tap-unplanned.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. # TAP support:
  17. # - unplanned tests are properly reported as errors
  18. . test-init.sh
  19. . tap-setup.sh
  20. cat > all.test <<END
  21. 1..1
  22. ok 1
  23. ok 2
  24. END
  25. run_make -O -e FAIL check
  26. count_test_results total=3 pass=1 fail=0 xpass=0 xfail=0 skip=0 error=2
  27. grep '^ERROR: all\.test - too many tests run (expected 1, got 2)$' stdout
  28. grep '^ERROR: all\.test 2 # UNPLANNED$' stdout
  29. cat > all.test <<END
  30. 1..2
  31. ok 1
  32. ok 2
  33. ok 3
  34. END
  35. run_make -O -e FAIL check
  36. count_test_results total=4 pass=2 fail=0 xpass=0 xfail=0 skip=0 error=2
  37. grep '^ERROR: all\.test - too many tests run (expected 2, got 3)$' stdout
  38. grep '^ERROR: all\.test 3 # UNPLANNED$' stdout
  39. # Interaction with XFAIL_TESTS.
  40. cat > all.test <<END
  41. 1..2
  42. not ok 1
  43. ok 2 # SKIP
  44. ok 3
  45. not ok 4
  46. ok 5 # SKIP
  47. END
  48. run_make -O -e FAIL XFAIL_TESTS=all.test check
  49. count_test_results total=6 pass=0 fail=0 xpass=0 xfail=1 skip=1 error=4
  50. grep '^ERROR: all\.test - too many tests run (expected 2, got 5)$' stdout
  51. grep '^ERROR: all\.test 3 # UNPLANNED$' stdout
  52. grep '^ERROR: all\.test 4 # UNPLANNED$' stdout
  53. grep '^ERROR: all\.test 5 # UNPLANNED$' stdout
  54. cat > all.test <<END
  55. 1..1
  56. ok 1
  57. ok
  58. ok 3
  59. ok foo
  60. ok 5 - bar bar
  61. not ok
  62. not ok 7
  63. not ok foo
  64. not ok 9 - bar bar
  65. ok # TODO
  66. ok 11 # TODO
  67. ok foo # TODO
  68. ok 13 - bar bar # TODO
  69. not ok # TODO
  70. not ok 15 # TODO
  71. not ok foo # TODO
  72. not ok 17 - bar bar # TODO
  73. ok # SKIP
  74. ok 19 # SKIP
  75. ok foo # SKIP
  76. ok 21 - bar bar # SKIP
  77. END
  78. cat > t <<END
  79. 2
  80. 3
  81. 4 foo
  82. 5 - bar bar
  83. 6
  84. 7
  85. 8 foo
  86. 9 - bar bar
  87. 10
  88. 11
  89. 12 foo
  90. 13 - bar bar
  91. 14
  92. 15
  93. 16 foo
  94. 17 - bar bar
  95. 18
  96. 19
  97. 20 foo
  98. 21 - bar bar
  99. END
  100. run_make -O -e FAIL check
  101. count_test_results total=22 pass=1 fail=0 xpass=0 xfail=0 skip=0 error=21
  102. echo 'PASS: all.test 1' > exp
  103. sed -e '/^$/d' -e 's/.*/ERROR: all.test & # UNPLANNED/' t >> exp
  104. echo 'ERROR: all.test - too many tests run (expected 1, got 21)' >> exp
  105. $FGREP ': all.test' stdout > got
  106. cat exp
  107. cat got
  108. diff exp got
  109. # Note that, if the TAP input has a trailing plan, it is not possible
  110. # to flag unplanned tests as such, since we do not know they're unplanned
  111. # until the plan is reached; still, we should give at least an error
  112. # message about the unmatched number of tests once we've got the plan.
  113. for x in 'ok' 'ok 3' 'not ok' 'not ok # TODO' 'ok # TODO' 'ok # SKIP'; do
  114. unindent > all.test <<END
  115. ok 1
  116. ok 2 # SKIP
  117. $x
  118. 1..2
  119. END
  120. run_make -O -e FAIL check
  121. test $($FGREP -c ': all.test' stdout) -eq 4
  122. $EGREP '^PASS: all\.test 1($| )' stdout
  123. $EGREP '^SKIP: all\.test 2($| )' stdout
  124. $EGREP ': all\.test 3($| )' stdout
  125. grep '^ERROR: all\.test - too many tests run (expected 2, got 3)$' stdout
  126. done
  127. :