tap-diagnostic.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. # - diagnostic messages (TAP lines with leading "#")
  18. # - flags '--comments' and '--no-comments' of the TAP test driver
  19. . test-init.sh
  20. . tap-setup.sh
  21. metacharacters=\''"\$!&()[]<>#;^?*'
  22. cat > all.test <<END
  23. 1..4
  24. # Hi! I'm a comment.
  25. # Tests begin.
  26. ok 1
  27. not ok 2 - foo # TODO
  28. ok 3 - bar # SKIP
  29. # Tests end.
  30. ok - zardoz
  31. # Shell metacharacters here: $metacharacters
  32. .# Leading characters before "#", not a TAP diagnostic line.
  33. x # Leading characters before "#", not a TAP diagnostic line.
  34. # Leading whitespace before "#", not a TAP diagnostic line.
  35. ${tab}# Leading whitespace before "#", not a TAP diagnostic line.
  36. ${tab} # Leading whitespace before "#", not a TAP diagnostic line.
  37. END
  38. cat > exp <<END
  39. # all.test: Hi! I'm a comment.
  40. # all.test: Tests begin.
  41. PASS: all.test 1
  42. XFAIL: all.test 2 - foo # TODO
  43. SKIP: all.test 3 - bar # SKIP
  44. # all.test: Tests end.
  45. PASS: all.test 4 - zardoz
  46. # all.test: Shell metacharacters here: $metacharacters
  47. END
  48. run_make -O check
  49. $EGREP -i "#.*all\\.test|a comment|(Tests|Shell) " stdout && exit 1
  50. count_test_results total=4 pass=2 fail=0 xpass=0 xfail=1 skip=1 error=0
  51. echo 'AM_TEST_LOG_DRIVER_FLAGS = --comments' >> Makefile
  52. run_make -O check
  53. $FGREP ' all.test' stdout > got
  54. cat exp
  55. cat got
  56. diff exp got
  57. count_test_results total=4 pass=2 fail=0 xpass=0 xfail=1 skip=1 error=0
  58. run_make -O TEST_LOG_DRIVER_FLAGS="--no-comments" check
  59. $EGREP -i "#.*all\\.test|a comment|(Tests|Shell) " stdout && exit 1
  60. count_test_results total=4 pass=2 fail=0 xpass=0 xfail=1 skip=1 error=0
  61. # The "#"-prepended lines here shouldn't be parsed as test results.
  62. cat > all.test <<END
  63. 1..1
  64. ok
  65. # ok
  66. #ok
  67. # not ok
  68. #not ok
  69. # Bail out!
  70. #Bail out!
  71. # SKIP
  72. #SKIP
  73. # TODO
  74. #TODO
  75. END
  76. run_make -O check
  77. count_test_results total=1 pass=1 fail=0 xpass=0 xfail=0 skip=0 error=0
  78. # Diagnostic without leading whitespace, or with extra leading whitespace,
  79. # is ok. Be laxer in the grepping checks, to allow for whitespace
  80. # normalization by the TAP driver.
  81. ws="[ $tab]"
  82. ws0p="${ws}*"
  83. ws1p="${ws}${ws0p}"
  84. cat > all.test <<END
  85. 1..1
  86. ok 1
  87. #foo
  88. #bar${tab}
  89. # zardoz ${tab}
  90. # ${tab} ${tab}${tab}foo bar${tab}baz ${tab}
  91. END
  92. run_make -O check
  93. count_test_results total=1 pass=1 fail=0 xpass=0 xfail=0 skip=0 error=0
  94. grep "^# all.test:${ws0p}foo$" stdout
  95. grep "^# all.test:${ws0p}bar${ws0p}$" stdout
  96. grep "^# all.test:${ws1p}zardoz${ws0p}$" stdout
  97. grep "^# all.test:${ws1p}foo bar${tab}baz${ws0p}$" stdout
  98. test $(grep -c '^# all\.test:' stdout) -eq 4
  99. :