trivial-test-driver 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. #
  17. # Test driver for a very simple test protocol used by the Automake
  18. # testsuite to check support for custom test drivers allowing for more
  19. # test results per test script.
  20. #
  21. # The exit status of the wrapped script is ignored. Lines in its stdout
  22. # and stderr beginning with 'PASS', 'FAIL', 'XFAIL', 'XPASS', 'SKIP' or
  23. # 'ERROR' count as a test case result with the obviously-corresponding
  24. # outcome. Every other line is ignored for what concerns the testsuite
  25. # outcome.
  26. #
  27. # This script is used at least by the 'driver-custom-multitest*.test'
  28. # tests.
  29. #
  30. # Help to avoid typo-related bugs.
  31. set -u
  32. ## Option parsing.
  33. test_name=INVALID.NAME
  34. log_file=BAD.LOG
  35. trs_file=BAD.TRS
  36. while test $# -gt 0; do
  37. case $1 in
  38. --test-name) test_name=$2; shift;;
  39. --log-file) log_file=$2; shift;;
  40. --trs-file) trs_file=$2; shift;;
  41. # Ignored.
  42. --expect-failure) shift;;
  43. --color-tests) shift;;
  44. --enable-hard-errors) shift;;
  45. # Explicitly terminate option list.
  46. --) shift; break;;
  47. # Shouldn't happen
  48. *) echo "$0: invalid option/argument: '$1'" >&2; exit 2;;
  49. esac
  50. shift
  51. done
  52. ## Log file header.
  53. {
  54. echo "RUN: $test_name"
  55. echo "RUN: $test_name" | sed 's/./=/g'
  56. echo
  57. } > $log_file
  58. ## Run the test script, get test cases results, display them on console.
  59. "$@" 2>&1 | tee -a $log_file | (
  60. i=0 st=0
  61. exec 5> $trs_file
  62. while read line; do
  63. result=
  64. case $line in
  65. PASS:*) result=PASS ;;
  66. FAIL:*) result=FAIL ;;
  67. XPASS:*) result=XPASS ;;
  68. XFAIL:*) result=XFAIL ;;
  69. SKIP:*) result=SKIP ;;
  70. ERROR:*) result=ERROR ;;
  71. esac
  72. if test -n "$result"; then
  73. case $result in FAIL|XPASS|ERROR) st=1;; esac
  74. # Output testcase result to console.
  75. echo "$result: $test_name"
  76. # Register testcase outcome for the log file.
  77. echo ":test-result: $line" >&5
  78. echo >&5
  79. fi
  80. done
  81. if test $st -eq 0; then
  82. recheck=no
  83. copy_in_global_log=no
  84. else
  85. recheck=yes
  86. copy_in_global_log=yes
  87. fi
  88. echo ":recheck: $recheck" >&5
  89. echo ":copy-in-global-log: $copy_in_global_log" >&5
  90. exec 5>&-
  91. ) | awk '{ print $0 ", testcase " NR }'
  92. ## And we're done.
  93. exit 0