Blame buildutil/tap-driver.sh

rpm-build c487f7
#! /bin/sh
rpm-build c487f7
# Copyright (C) 2011-2013 Free Software Foundation, Inc.
rpm-build c487f7
#
rpm-build c487f7
# This program is free software; you can redistribute it and/or modify
rpm-build c487f7
# it under the terms of the GNU General Public License as published by
rpm-build c487f7
# the Free Software Foundation; either version 2, or (at your option)
rpm-build c487f7
# any later version.
rpm-build c487f7
#
rpm-build c487f7
# This program is distributed in the hope that it will be useful,
rpm-build c487f7
# but WITHOUT ANY WARRANTY; without even the implied warranty of
rpm-build c487f7
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
rpm-build c487f7
# GNU General Public License for more details.
rpm-build c487f7
#
rpm-build c487f7
# You should have received a copy of the GNU General Public License
rpm-build c487f7
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
rpm-build c487f7
rpm-build c487f7
# As a special exception to the GNU General Public License, if you
rpm-build c487f7
# distribute this file as part of a program that contains a
rpm-build c487f7
# configuration script generated by Autoconf, you may include it under
rpm-build c487f7
# the same distribution terms that you use for the rest of that program.
rpm-build c487f7
rpm-build c487f7
# This file is maintained in Automake, please report
rpm-build c487f7
# bugs to <bug-automake@gnu.org> or send patches to
rpm-build c487f7
# <automake-patches@gnu.org>.
rpm-build c487f7
rpm-build c487f7
scriptversion=2011-12-27.17; # UTC
rpm-build c487f7
rpm-build c487f7
# Make unconditional expansion of undefined variables an error.  This
rpm-build c487f7
# helps a lot in preventing typo-related bugs.
rpm-build c487f7
set -u
rpm-build c487f7
rpm-build c487f7
me=tap-driver.sh
rpm-build c487f7
rpm-build c487f7
fatal ()
rpm-build c487f7
{
rpm-build c487f7
  echo "$me: fatal: $*" >&2
rpm-build c487f7
  exit 1
rpm-build c487f7
}
rpm-build c487f7
rpm-build c487f7
usage_error ()
rpm-build c487f7
{
rpm-build c487f7
  echo "$me: $*" >&2
rpm-build c487f7
  print_usage >&2
rpm-build c487f7
  exit 2
rpm-build c487f7
}
rpm-build c487f7
rpm-build c487f7
print_usage ()
rpm-build c487f7
{
rpm-build c487f7
  cat <
rpm-build c487f7
Usage:
rpm-build c487f7
  tap-driver.sh --test-name=NAME --log-file=PATH --trs-file=PATH
rpm-build c487f7
                [--expect-failure={yes|no}] [--color-tests={yes|no}]
rpm-build c487f7
                [--enable-hard-errors={yes|no}] [--ignore-exit]
rpm-build c487f7
                [--diagnostic-string=STRING] [--merge|--no-merge]
rpm-build c487f7
                [--comments|--no-comments] [--] TEST-COMMAND
rpm-build c487f7
The \`--test-name', \`--log-file' and \`--trs-file' options are mandatory.
rpm-build c487f7
END
rpm-build c487f7
}
rpm-build c487f7
rpm-build c487f7
# TODO: better error handling in option parsing (in particular, ensure
rpm-build c487f7
# TODO: $log_file, $trs_file and $test_name are defined).
rpm-build c487f7
test_name= # Used for reporting.
rpm-build c487f7
log_file=  # Where to save the result and output of the test script.
rpm-build c487f7
trs_file=  # Where to save the metadata of the test run.
rpm-build c487f7
expect_failure=0
rpm-build c487f7
color_tests=0
rpm-build c487f7
merge=0
rpm-build c487f7
ignore_exit=0
rpm-build c487f7
comments=0
rpm-build c487f7
diag_string='#'
rpm-build c487f7
while test $# -gt 0; do
rpm-build c487f7
  case $1 in
rpm-build c487f7
  --help) print_usage; exit $?;;
rpm-build c487f7
  --version) echo "$me $scriptversion"; exit $?;;
rpm-build c487f7
  --test-name) test_name=$2; shift;;
rpm-build c487f7
  --log-file) log_file=$2; shift;;
rpm-build c487f7
  --trs-file) trs_file=$2; shift;;
rpm-build c487f7
  --color-tests) color_tests=$2; shift;;
rpm-build c487f7
  --expect-failure) expect_failure=$2; shift;;
rpm-build c487f7
  --enable-hard-errors) shift;; # No-op.
rpm-build c487f7
  --merge) merge=1;;
rpm-build c487f7
  --no-merge) merge=0;;
rpm-build c487f7
  --ignore-exit) ignore_exit=1;;
rpm-build c487f7
  --comments) comments=1;;
rpm-build c487f7
  --no-comments) comments=0;;
rpm-build c487f7
  --diagnostic-string) diag_string=$2; shift;;
rpm-build c487f7
  --) shift; break;;
rpm-build c487f7
  -*) usage_error "invalid option: '$1'";;
rpm-build c487f7
  esac
rpm-build c487f7
  shift
rpm-build c487f7
done
rpm-build c487f7
rpm-build c487f7
test $# -gt 0 || usage_error "missing test command"
rpm-build c487f7
rpm-build c487f7
case $expect_failure in
rpm-build c487f7
  yes) expect_failure=1;;
rpm-build c487f7
    *) expect_failure=0;;
rpm-build c487f7
esac
rpm-build c487f7
rpm-build c487f7
if test $color_tests = yes; then
rpm-build c487f7
  init_colors='
rpm-build c487f7
    color_map["red"]="?[0;31m" # Red.
rpm-build c487f7
    color_map["grn"]="?[0;32m" # Green.
rpm-build c487f7
    color_map["lgn"]="?[1;32m" # Light green.
rpm-build c487f7
    color_map["blu"]="?[1;34m" # Blue.
rpm-build c487f7
    color_map["mgn"]="?[0;35m" # Magenta.
rpm-build c487f7
    color_map["std"]="?[m"     # No color.
rpm-build c487f7
    color_for_result["ERROR"] = "mgn"
rpm-build c487f7
    color_for_result["PASS"]  = "grn"
rpm-build c487f7
    color_for_result["XPASS"] = "red"
rpm-build c487f7
    color_for_result["FAIL"]  = "red"
rpm-build c487f7
    color_for_result["XFAIL"] = "lgn"
rpm-build c487f7
    color_for_result["SKIP"]  = "blu"'
rpm-build c487f7
else
rpm-build c487f7
  init_colors=''
rpm-build c487f7
fi
rpm-build c487f7
rpm-build c487f7
# :; is there to work around a bug in bash 3.2 (and earlier) which
rpm-build c487f7
# does not always set '$?' properly on redirection failure.
rpm-build c487f7
# See the Autoconf manual for more details.
rpm-build c487f7
:;{
rpm-build c487f7
  (
rpm-build c487f7
    # Ignore common signals (in this subshell only!), to avoid potential
rpm-build c487f7
    # problems with Korn shells.  Some Korn shells are known to propagate
rpm-build c487f7
    # to themselves signals that have killed a child process they were
rpm-build c487f7
    # waiting for; this is done at least for SIGINT (and usually only for
rpm-build c487f7
    # it, in truth).  Without the `trap' below, such a behaviour could
rpm-build c487f7
    # cause a premature exit in the current subshell, e.g., in case the
rpm-build c487f7
    # test command it runs gets terminated by a SIGINT.  Thus, the awk
rpm-build c487f7
    # script we are piping into would never seen the exit status it
rpm-build c487f7
    # expects on its last input line (which is displayed below by the
rpm-build c487f7
    # last `echo $?' statement), and would thus die reporting an internal
rpm-build c487f7
    # error.
rpm-build c487f7
    # For more information, see the Autoconf manual and the threads:
rpm-build c487f7
    # <http://lists.gnu.org/archive/html/bug-autoconf/2011-09/msg00004.html>
rpm-build c487f7
    # <http://mail.opensolaris.org/pipermail/ksh93-integration-discuss/2009-February/004121.html>
rpm-build c487f7
    trap : 1 3 2 13 15
rpm-build c487f7
    if test $merge -gt 0; then
rpm-build c487f7
      exec 2>&1
rpm-build c487f7
    else
rpm-build c487f7
      exec 2>&3
rpm-build c487f7
    fi
rpm-build c487f7
    "$@"
rpm-build c487f7
    echo $?
rpm-build c487f7
  ) | LC_ALL=C ${AM_TAP_AWK-awk} \
rpm-build c487f7
        -v me="$me" \
rpm-build c487f7
        -v test_script_name="$test_name" \
rpm-build c487f7
        -v log_file="$log_file" \
rpm-build c487f7
        -v trs_file="$trs_file" \
rpm-build c487f7
        -v expect_failure="$expect_failure" \
rpm-build c487f7
        -v merge="$merge" \
rpm-build c487f7
        -v ignore_exit="$ignore_exit" \
rpm-build c487f7
        -v comments="$comments" \
rpm-build c487f7
        -v diag_string="$diag_string" \
rpm-build c487f7
'
rpm-build c487f7
# FIXME: the usages of "cat >&3" below could be optimized when using
rpm-build c487f7
# FIXME: GNU awk, and/on on systems that supports /dev/fd/.
rpm-build c487f7
rpm-build c487f7
# Implementation note: in what follows, `result_obj` will be an
rpm-build c487f7
# associative array that (partly) simulates a TAP result object
rpm-build c487f7
# from the `TAP::Parser` perl module.
rpm-build c487f7
rpm-build c487f7
## ----------- ##
rpm-build c487f7
##  FUNCTIONS  ##
rpm-build c487f7
## ----------- ##
rpm-build c487f7
rpm-build c487f7
function fatal(msg)
rpm-build c487f7
{
rpm-build c487f7
  print me ": " msg | "cat >&2"
rpm-build c487f7
  exit 1
rpm-build c487f7
}
rpm-build c487f7
rpm-build c487f7
function abort(where)
rpm-build c487f7
{
rpm-build c487f7
  fatal("internal error " where)
rpm-build c487f7
}
rpm-build c487f7
rpm-build c487f7
# Convert a boolean to a "yes"/"no" string.
rpm-build c487f7
function yn(bool)
rpm-build c487f7
{
rpm-build c487f7
  return bool ? "yes" : "no";
rpm-build c487f7
}
rpm-build c487f7
rpm-build c487f7
function add_test_result(result)
rpm-build c487f7
{
rpm-build c487f7
  if (!test_results_index)
rpm-build c487f7
    test_results_index = 0
rpm-build c487f7
  test_results_list[test_results_index] = result
rpm-build c487f7
  test_results_index += 1
rpm-build c487f7
  test_results_seen[result] = 1;
rpm-build c487f7
}
rpm-build c487f7
rpm-build c487f7
# Whether the test script should be re-run by "make recheck".
rpm-build c487f7
function must_recheck()
rpm-build c487f7
{
rpm-build c487f7
  for (k in test_results_seen)
rpm-build c487f7
    if (k != "XFAIL" && k != "PASS" && k != "SKIP")
rpm-build c487f7
      return 1
rpm-build c487f7
  return 0
rpm-build c487f7
}
rpm-build c487f7
rpm-build c487f7
# Whether the content of the log file associated to this test should
rpm-build c487f7
# be copied into the "global" test-suite.log.
rpm-build c487f7
function copy_in_global_log()
rpm-build c487f7
{
rpm-build c487f7
  for (k in test_results_seen)
rpm-build c487f7
    if (k != "PASS")
rpm-build c487f7
      return 1
rpm-build c487f7
  return 0
rpm-build c487f7
}
rpm-build c487f7
rpm-build c487f7
# FIXME: this can certainly be improved ...
rpm-build c487f7
function get_global_test_result()
rpm-build c487f7
{
rpm-build c487f7
    if ("ERROR" in test_results_seen)
rpm-build c487f7
      return "ERROR"
rpm-build c487f7
    if ("FAIL" in test_results_seen || "XPASS" in test_results_seen)
rpm-build c487f7
      return "FAIL"
rpm-build c487f7
    all_skipped = 1
rpm-build c487f7
    for (k in test_results_seen)
rpm-build c487f7
      if (k != "SKIP")
rpm-build c487f7
        all_skipped = 0
rpm-build c487f7
    if (all_skipped)
rpm-build c487f7
      return "SKIP"
rpm-build c487f7
    return "PASS";
rpm-build c487f7
}
rpm-build c487f7
rpm-build c487f7
function stringify_result_obj(result_obj)
rpm-build c487f7
{
rpm-build c487f7
  if (result_obj["is_unplanned"] || result_obj["number"] != testno)
rpm-build c487f7
    return "ERROR"
rpm-build c487f7
rpm-build c487f7
  if (plan_seen == LATE_PLAN)
rpm-build c487f7
    return "ERROR"
rpm-build c487f7
rpm-build c487f7
  if (result_obj["directive"] == "TODO")
rpm-build c487f7
    return result_obj["is_ok"] ? "XPASS" : "XFAIL"
rpm-build c487f7
rpm-build c487f7
  if (result_obj["directive"] == "SKIP")
rpm-build c487f7
    return result_obj["is_ok"] ? "SKIP" : COOKED_FAIL;
rpm-build c487f7
rpm-build c487f7
  if (length(result_obj["directive"]))
rpm-build c487f7
      abort("in function stringify_result_obj()")
rpm-build c487f7
rpm-build c487f7
  return result_obj["is_ok"] ? COOKED_PASS : COOKED_FAIL
rpm-build c487f7
}
rpm-build c487f7
rpm-build c487f7
function decorate_result(result)
rpm-build c487f7
{
rpm-build c487f7
  color_name = color_for_result[result]
rpm-build c487f7
  if (color_name)
rpm-build c487f7
    return color_map[color_name] "" result "" color_map["std"]
rpm-build c487f7
  # If we are not using colorized output, or if we do not know how
rpm-build c487f7
  # to colorize the given result, we should return it unchanged.
rpm-build c487f7
  return result
rpm-build c487f7
}
rpm-build c487f7
rpm-build c487f7
function report(result, details)
rpm-build c487f7
{
rpm-build c487f7
  if (result ~ /^(X?(PASS|FAIL)|SKIP|ERROR)/)
rpm-build c487f7
    {
rpm-build c487f7
      msg = ": " test_script_name
rpm-build c487f7
      add_test_result(result)
rpm-build c487f7
    }
rpm-build c487f7
  else if (result == "#")
rpm-build c487f7
    {
rpm-build c487f7
      msg = " " test_script_name ":"
rpm-build c487f7
    }
rpm-build c487f7
  else
rpm-build c487f7
    {
rpm-build c487f7
      abort("in function report()")
rpm-build c487f7
    }
rpm-build c487f7
  if (length(details))
rpm-build c487f7
    msg = msg " " details
rpm-build c487f7
  # Output on console might be colorized.
rpm-build c487f7
  print decorate_result(result) msg
rpm-build c487f7
  # Log the result in the log file too, to help debugging (this is
rpm-build c487f7
  # especially true when said result is a TAP error or "Bail out!").
rpm-build c487f7
  print result msg | "cat >&3;;
rpm-build c487f7
}
rpm-build c487f7
rpm-build c487f7
function testsuite_error(error_message)
rpm-build c487f7
{
rpm-build c487f7
  report("ERROR", "- " error_message)
rpm-build c487f7
}
rpm-build c487f7
rpm-build c487f7
function handle_tap_result()
rpm-build c487f7
{
rpm-build c487f7
  details = result_obj["number"];
rpm-build c487f7
  if (length(result_obj["description"]))
rpm-build c487f7
    details = details " " result_obj["description"]
rpm-build c487f7
rpm-build c487f7
  if (plan_seen == LATE_PLAN)
rpm-build c487f7
    {
rpm-build c487f7
      details = details " # AFTER LATE PLAN";
rpm-build c487f7
    }
rpm-build c487f7
  else if (result_obj["is_unplanned"])
rpm-build c487f7
    {
rpm-build c487f7
       details = details " # UNPLANNED";
rpm-build c487f7
    }
rpm-build c487f7
  else if (result_obj["number"] != testno)
rpm-build c487f7
    {
rpm-build c487f7
       details = sprintf("%s # OUT-OF-ORDER (expecting %d)",
rpm-build c487f7
                         details, testno);
rpm-build c487f7
    }
rpm-build c487f7
  else if (result_obj["directive"])
rpm-build c487f7
    {
rpm-build c487f7
      details = details " # " result_obj["directive"];
rpm-build c487f7
      if (length(result_obj["explanation"]))
rpm-build c487f7
        details = details " " result_obj["explanation"]
rpm-build c487f7
    }
rpm-build c487f7
rpm-build c487f7
  report(stringify_result_obj(result_obj), details)
rpm-build c487f7
}
rpm-build c487f7
rpm-build c487f7
# `skip_reason` should be empty whenever planned > 0.
rpm-build c487f7
function handle_tap_plan(planned, skip_reason)
rpm-build c487f7
{
rpm-build c487f7
  planned += 0 # Avoid getting confused if, say, `planned` is "00"
rpm-build c487f7
  if (length(skip_reason) && planned > 0)
rpm-build c487f7
    abort("in function handle_tap_plan()")
rpm-build c487f7
  if (plan_seen)
rpm-build c487f7
    {
rpm-build c487f7
      # Error, only one plan per stream is acceptable.
rpm-build c487f7
      testsuite_error("multiple test plans")
rpm-build c487f7
      return;
rpm-build c487f7
    }
rpm-build c487f7
  planned_tests = planned
rpm-build c487f7
  # The TAP plan can come before or after *all* the TAP results; we speak
rpm-build c487f7
  # respectively of an "early" or a "late" plan.  If we see the plan line
rpm-build c487f7
  # after at least one TAP result has been seen, assume we have a late
rpm-build c487f7
  # plan; in this case, any further test result seen after the plan will
rpm-build c487f7
  # be flagged as an error.
rpm-build c487f7
  plan_seen = (testno >= 1 ? LATE_PLAN : EARLY_PLAN)
rpm-build c487f7
  # If testno > 0, we have an error ("too many tests run") that will be
rpm-build c487f7
  # automatically dealt with later, so do not worry about it here.  If
rpm-build c487f7
  # $plan_seen is true, we have an error due to a repeated plan, and that
rpm-build c487f7
  # has already been dealt with above.  Otherwise, we have a valid "plan
rpm-build c487f7
  # with SKIP" specification, and should report it as a particular kind
rpm-build c487f7
  # of SKIP result.
rpm-build c487f7
  if (planned == 0 && testno == 0)
rpm-build c487f7
    {
rpm-build c487f7
      if (length(skip_reason))
rpm-build c487f7
        skip_reason = "- "  skip_reason;
rpm-build c487f7
      report("SKIP", skip_reason);
rpm-build c487f7
    }
rpm-build c487f7
}
rpm-build c487f7
rpm-build c487f7
function extract_tap_comment(line)
rpm-build c487f7
{
rpm-build c487f7
  if (index(line, diag_string) == 1)
rpm-build c487f7
    {
rpm-build c487f7
      # Strip leading `diag_string` from `line`.
rpm-build c487f7
      line = substr(line, length(diag_string) + 1)
rpm-build c487f7
      # And strip any leading and trailing whitespace left.
rpm-build c487f7
      sub("^[ \t]*", "", line)
rpm-build c487f7
      sub("[ \t]*$", "", line)
rpm-build c487f7
      # Return what is left (if any).
rpm-build c487f7
      return line;
rpm-build c487f7
    }
rpm-build c487f7
  return "";
rpm-build c487f7
}
rpm-build c487f7
rpm-build c487f7
# When this function is called, we know that line is a TAP result line,
rpm-build c487f7
# so that it matches the (perl) RE "^(not )?ok\b".
rpm-build c487f7
function setup_result_obj(line)
rpm-build c487f7
{
rpm-build c487f7
  # Get the result, and remove it from the line.
rpm-build c487f7
  result_obj["is_ok"] = (substr(line, 1, 2) == "ok" ? 1 : 0)
rpm-build c487f7
  sub("^(not )?ok[ \t]*", "", line)
rpm-build c487f7
rpm-build c487f7
  # If the result has an explicit number, get it and strip it; otherwise,
rpm-build c487f7
  # automatically assing the next progressive number to it.
rpm-build c487f7
  if (line ~ /^[0-9]+$/ || line ~ /^[0-9]+[^a-zA-Z0-9_]/)
rpm-build c487f7
    {
rpm-build c487f7
      match(line, "^[0-9]+")
rpm-build c487f7
      # The final `+ 0` is to normalize numbers with leading zeros.
rpm-build c487f7
      result_obj["number"] = substr(line, 1, RLENGTH) + 0
rpm-build c487f7
      line = substr(line, RLENGTH + 1)
rpm-build c487f7
    }
rpm-build c487f7
  else
rpm-build c487f7
    {
rpm-build c487f7
      result_obj["number"] = testno
rpm-build c487f7
    }
rpm-build c487f7
rpm-build c487f7
  if (plan_seen == LATE_PLAN)
rpm-build c487f7
    # No further test results are acceptable after a "late" TAP plan
rpm-build c487f7
    # has been seen.
rpm-build c487f7
    result_obj["is_unplanned"] = 1
rpm-build c487f7
  else if (plan_seen && testno > planned_tests)
rpm-build c487f7
    result_obj["is_unplanned"] = 1
rpm-build c487f7
  else
rpm-build c487f7
    result_obj["is_unplanned"] = 0
rpm-build c487f7
rpm-build c487f7
  # Strip trailing and leading whitespace.
rpm-build c487f7
  sub("^[ \t]*", "", line)
rpm-build c487f7
  sub("[ \t]*$", "", line)
rpm-build c487f7
rpm-build c487f7
  # This will have to be corrected if we have a "TODO"/"SKIP" directive.
rpm-build c487f7
  result_obj["description"] = line
rpm-build c487f7
  result_obj["directive"] = ""
rpm-build c487f7
  result_obj["explanation"] = ""
rpm-build c487f7
rpm-build c487f7
  if (index(line, "#") == 0)
rpm-build c487f7
    return # No possible directive, nothing more to do.
rpm-build c487f7
rpm-build c487f7
  # Directives are case-insensitive.
rpm-build c487f7
  rx = "[ \t]*#[ \t]*([tT][oO][dD][oO]|[sS][kK][iI][pP])[ \t]*"
rpm-build c487f7
rpm-build c487f7
  # See whether we have the directive, and if yes, where.
rpm-build c487f7
  pos = match(line, rx "$")
rpm-build c487f7
  if (!pos)
rpm-build c487f7
    pos = match(line, rx "[^a-zA-Z0-9_]")
rpm-build c487f7
rpm-build c487f7
  # If there was no TAP directive, we have nothing more to do.
rpm-build c487f7
  if (!pos)
rpm-build c487f7
    return
rpm-build c487f7
rpm-build c487f7
  # Let`s now see if the TAP directive has been escaped.  For example:
rpm-build c487f7
  #  escaped:     ok \# SKIP
rpm-build c487f7
  #  not escaped: ok \\# SKIP
rpm-build c487f7
  #  escaped:     ok \\\\\# SKIP
rpm-build c487f7
  #  not escaped: ok \ # SKIP
rpm-build c487f7
  if (substr(line, pos, 1) == "#")
rpm-build c487f7
    {
rpm-build c487f7
      bslash_count = 0
rpm-build c487f7
      for (i = pos; i > 1 && substr(line, i - 1, 1) == "\\"; i--)
rpm-build c487f7
        bslash_count += 1
rpm-build c487f7
      if (bslash_count % 2)
rpm-build c487f7
        return # Directive was escaped.
rpm-build c487f7
    }
rpm-build c487f7
rpm-build c487f7
  # Strip the directive and its explanation (if any) from the test
rpm-build c487f7
  # description.
rpm-build c487f7
  result_obj["description"] = substr(line, 1, pos - 1)
rpm-build c487f7
  # Now remove the test description from the line, that has been dealt
rpm-build c487f7
  # with already.
rpm-build c487f7
  line = substr(line, pos)
rpm-build c487f7
  # Strip the directive, and save its value (normalized to upper case).
rpm-build c487f7
  sub("^[ \t]*#[ \t]*", "", line)
rpm-build c487f7
  result_obj["directive"] = toupper(substr(line, 1, 4))
rpm-build c487f7
  line = substr(line, 5)
rpm-build c487f7
  # Now get the explanation for the directive (if any), with leading
rpm-build c487f7
  # and trailing whitespace removed.
rpm-build c487f7
  sub("^[ \t]*", "", line)
rpm-build c487f7
  sub("[ \t]*$", "", line)
rpm-build c487f7
  result_obj["explanation"] = line
rpm-build c487f7
}
rpm-build c487f7
rpm-build c487f7
function get_test_exit_message(status)
rpm-build c487f7
{
rpm-build c487f7
  if (status == 0)
rpm-build c487f7
    return ""
rpm-build c487f7
  if (status !~ /^[1-9][0-9]*$/)
rpm-build c487f7
    abort("getting exit status")
rpm-build c487f7
  if (status < 127)
rpm-build c487f7
    exit_details = ""
rpm-build c487f7
  else if (status == 127)
rpm-build c487f7
    exit_details = " (command not found?)"
rpm-build c487f7
  else if (status >= 128 && status <= 255)
rpm-build c487f7
    exit_details = sprintf(" (terminated by signal %d?)", status - 128)
rpm-build c487f7
  else if (status > 256 && status <= 384)
rpm-build c487f7
    # We used to report an "abnormal termination" here, but some Korn
rpm-build c487f7
    # shells, when a child process die due to signal number n, can leave
rpm-build c487f7
    # in $? an exit status of 256+n instead of the more standard 128+n.
rpm-build c487f7
    # Apparently, both behaviours are allowed by POSIX (2008), so be
rpm-build c487f7
    # prepared to handle them both.  See also Austing Group report ID
rpm-build c487f7
    # 0000051 <http://www.austingroupbugs.net/view.php?id=51>
rpm-build c487f7
    exit_details = sprintf(" (terminated by signal %d?)", status - 256)
rpm-build c487f7
  else
rpm-build c487f7
    # Never seen in practice.
rpm-build c487f7
    exit_details = " (abnormal termination)"
rpm-build c487f7
  return sprintf("exited with status %d%s", status, exit_details)
rpm-build c487f7
}
rpm-build c487f7
rpm-build c487f7
function write_test_results()
rpm-build c487f7
{
rpm-build c487f7
  print ":global-test-result: " get_global_test_result() > trs_file
rpm-build c487f7
  print ":recheck: "  yn(must_recheck()) > trs_file
rpm-build c487f7
  print ":copy-in-global-log: " yn(copy_in_global_log()) > trs_file
rpm-build c487f7
  for (i = 0; i < test_results_index; i += 1)
rpm-build c487f7
    print ":test-result: " test_results_list[i] > trs_file
rpm-build c487f7
  close(trs_file);
rpm-build c487f7
}
rpm-build c487f7
rpm-build c487f7
BEGIN {
rpm-build c487f7
rpm-build c487f7
## ------- ##
rpm-build c487f7
##  SETUP  ##
rpm-build c487f7
## ------- ##
rpm-build c487f7
rpm-build c487f7
'"$init_colors"'
rpm-build c487f7
rpm-build c487f7
# Properly initialized once the TAP plan is seen.
rpm-build c487f7
planned_tests = 0
rpm-build c487f7
rpm-build c487f7
COOKED_PASS = expect_failure ? "XPASS": "PASS";
rpm-build c487f7
COOKED_FAIL = expect_failure ? "XFAIL": "FAIL";
rpm-build c487f7
rpm-build c487f7
# Enumeration-like constants to remember which kind of plan (if any)
rpm-build c487f7
# has been seen.  It is important that NO_PLAN evaluates "false" as
rpm-build c487f7
# a boolean.
rpm-build c487f7
NO_PLAN = 0
rpm-build c487f7
EARLY_PLAN = 1
rpm-build c487f7
LATE_PLAN = 2
rpm-build c487f7
rpm-build c487f7
testno = 0     # Number of test results seen so far.
rpm-build c487f7
bailed_out = 0 # Whether a "Bail out!" directive has been seen.
rpm-build c487f7
rpm-build c487f7
# Whether the TAP plan has been seen or not, and if yes, which kind
rpm-build c487f7
# it is ("early" is seen before any test result, "late" otherwise).
rpm-build c487f7
plan_seen = NO_PLAN
rpm-build c487f7
rpm-build c487f7
## --------- ##
rpm-build c487f7
##  PARSING  ##
rpm-build c487f7
## --------- ##
rpm-build c487f7
rpm-build c487f7
is_first_read = 1
rpm-build c487f7
rpm-build c487f7
while (1)
rpm-build c487f7
  {
rpm-build c487f7
    # Involutions required so that we are able to read the exit status
rpm-build c487f7
    # from the last input line.
rpm-build c487f7
    st = getline
rpm-build c487f7
    if (st < 0) # I/O error.
rpm-build c487f7
      fatal("I/O error while reading from input stream")
rpm-build c487f7
    else if (st == 0) # End-of-input
rpm-build c487f7
      {
rpm-build c487f7
        if (is_first_read)
rpm-build c487f7
          abort("in input loop: only one input line")
rpm-build c487f7
        break
rpm-build c487f7
      }
rpm-build c487f7
    if (is_first_read)
rpm-build c487f7
      {
rpm-build c487f7
        is_first_read = 0
rpm-build c487f7
        nextline = $0
rpm-build c487f7
        continue
rpm-build c487f7
      }
rpm-build c487f7
    else
rpm-build c487f7
      {
rpm-build c487f7
        curline = nextline
rpm-build c487f7
        nextline = $0
rpm-build c487f7
        $0 = curline
rpm-build c487f7
      }
rpm-build c487f7
    # Copy any input line verbatim into the log file.
rpm-build c487f7
    print | "cat >&3"
rpm-build c487f7
    # Parsing of TAP input should stop after a "Bail out!" directive.
rpm-build c487f7
    if (bailed_out)
rpm-build c487f7
      continue
rpm-build c487f7
rpm-build c487f7
    # TAP test result.
rpm-build c487f7
    if ($0 ~ /^(not )?ok$/ || $0 ~ /^(not )?ok[^a-zA-Z0-9_]/)
rpm-build c487f7
      {
rpm-build c487f7
        testno += 1
rpm-build c487f7
        setup_result_obj($0)
rpm-build c487f7
        handle_tap_result()
rpm-build c487f7
      }
rpm-build c487f7
    # TAP plan (normal or "SKIP" without explanation).
rpm-build c487f7
    else if ($0 ~ /^1\.\.[0-9]+[ \t]*$/)
rpm-build c487f7
      {
rpm-build c487f7
        # The next two lines will put the number of planned tests in $0.
rpm-build c487f7
        sub("^1\\.\\.", "")
rpm-build c487f7
        sub("[^0-9]*$", "")
rpm-build c487f7
        handle_tap_plan($0, "")
rpm-build c487f7
        continue
rpm-build c487f7
      }
rpm-build c487f7
    # TAP "SKIP" plan, with an explanation.
rpm-build c487f7
    else if ($0 ~ /^1\.\.0+[ \t]*#/)
rpm-build c487f7
      {
rpm-build c487f7
        # The next lines will put the skip explanation in $0, stripping
rpm-build c487f7
        # any leading and trailing whitespace.  This is a little more
rpm-build c487f7
        # tricky in truth, since we want to also strip a potential leading
rpm-build c487f7
        # "SKIP" string from the message.
rpm-build c487f7
        sub("^[^#]*#[ \t]*(SKIP[: \t][ \t]*)?", "")
rpm-build c487f7
        sub("[ \t]*$", "");
rpm-build c487f7
        handle_tap_plan(0, $0)
rpm-build c487f7
      }
rpm-build c487f7
    # "Bail out!" magic.
rpm-build c487f7
    # Older versions of prove and TAP::Harness (e.g., 3.17) did not
rpm-build c487f7
    # recognize a "Bail out!" directive when preceded by leading
rpm-build c487f7
    # whitespace, but more modern versions (e.g., 3.23) do.  So we
rpm-build c487f7
    # emulate the latter, "more modern" behaviour.
rpm-build c487f7
    else if ($0 ~ /^[ \t]*Bail out!/)
rpm-build c487f7
      {
rpm-build c487f7
        bailed_out = 1
rpm-build c487f7
        # Get the bailout message (if any), with leading and trailing
rpm-build c487f7
        # whitespace stripped.  The message remains stored in `$0`.
rpm-build c487f7
        sub("^[ \t]*Bail out![ \t]*", "");
rpm-build c487f7
        sub("[ \t]*$", "");
rpm-build c487f7
        # Format the error message for the
rpm-build c487f7
        bailout_message = "Bail out!"
rpm-build c487f7
        if (length($0))
rpm-build c487f7
          bailout_message = bailout_message " " $0
rpm-build c487f7
        testsuite_error(bailout_message)
rpm-build c487f7
      }
rpm-build c487f7
    # Maybe we have too look for diagnostic comments too.
rpm-build c487f7
    else if (comments != 0)
rpm-build c487f7
      {
rpm-build c487f7
        comment = extract_tap_comment($0);
rpm-build c487f7
        if (length(comment))
rpm-build c487f7
          report("#", comment);
rpm-build c487f7
      }
rpm-build c487f7
  }
rpm-build c487f7
rpm-build c487f7
## -------- ##
rpm-build c487f7
##  FINISH  ##
rpm-build c487f7
## -------- ##
rpm-build c487f7
rpm-build c487f7
# A "Bail out!" directive should cause us to ignore any following TAP
rpm-build c487f7
# error, as well as a non-zero exit status from the TAP producer.
rpm-build c487f7
if (!bailed_out)
rpm-build c487f7
  {
rpm-build c487f7
    if (!plan_seen)
rpm-build c487f7
      {
rpm-build c487f7
        testsuite_error("missing test plan")
rpm-build c487f7
      }
rpm-build c487f7
    else if (planned_tests != testno)
rpm-build c487f7
      {
rpm-build c487f7
        bad_amount = testno > planned_tests ? "many" : "few"
rpm-build c487f7
        testsuite_error(sprintf("too %s tests run (expected %d, got %d)",
rpm-build c487f7
                                bad_amount, planned_tests, testno))
rpm-build c487f7
      }
rpm-build c487f7
    if (!ignore_exit)
rpm-build c487f7
      {
rpm-build c487f7
        # Fetch exit status from the last line.
rpm-build c487f7
        exit_message = get_test_exit_message(nextline)
rpm-build c487f7
        if (exit_message)
rpm-build c487f7
          testsuite_error(exit_message)
rpm-build c487f7
      }
rpm-build c487f7
  }
rpm-build c487f7
rpm-build c487f7
write_test_results()
rpm-build c487f7
rpm-build c487f7
exit 0
rpm-build c487f7
rpm-build c487f7
} # End of "BEGIN" block.
rpm-build c487f7
'
rpm-build c487f7
rpm-build c487f7
# TODO: document that we consume the file descriptor 3 :-(
rpm-build c487f7
} 3>"$log_file"
rpm-build c487f7
rpm-build c487f7
test $? -eq 0 || fatal "I/O or internal error"
rpm-build c487f7
rpm-build c487f7
# Local Variables:
rpm-build c487f7
# mode: shell-script
rpm-build c487f7
# sh-indentation: 2
rpm-build c487f7
# eval: (add-hook 'write-file-hooks 'time-stamp)
rpm-build c487f7
# time-stamp-start: "scriptversion="
rpm-build c487f7
# time-stamp-format: "%:y-%02m-%02d.%02H"
rpm-build c487f7
# time-stamp-time-zone: "UTC"
rpm-build c487f7
# time-stamp-end: "; # UTC"
rpm-build c487f7
# End: