Blame test-driver

Packit 874993
#! /bin/sh
Packit 874993
# test-driver - basic testsuite driver script.
Packit 874993
Packit Service 688f9c
scriptversion=2018-03-07.03; # UTC
Packit 874993
Packit Service 688f9c
# Copyright (C) 2011-2018 Free Software Foundation, Inc.
Packit 874993
#
Packit 874993
# This program is free software; you can redistribute it and/or modify
Packit 874993
# it under the terms of the GNU General Public License as published by
Packit 874993
# the Free Software Foundation; either version 2, or (at your option)
Packit 874993
# any later version.
Packit 874993
#
Packit 874993
# This program is distributed in the hope that it will be useful,
Packit 874993
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 874993
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 874993
# GNU General Public License for more details.
Packit 874993
#
Packit 874993
# You should have received a copy of the GNU General Public License
Packit Service 688f9c
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
Packit 874993
Packit 874993
# As a special exception to the GNU General Public License, if you
Packit 874993
# distribute this file as part of a program that contains a
Packit 874993
# configuration script generated by Autoconf, you may include it under
Packit 874993
# the same distribution terms that you use for the rest of that program.
Packit 874993
Packit 874993
# This file is maintained in Automake, please report
Packit 874993
# bugs to <bug-automake@gnu.org> or send patches to
Packit 874993
# <automake-patches@gnu.org>.
Packit 874993
Packit 874993
# Make unconditional expansion of undefined variables an error.  This
Packit 874993
# helps a lot in preventing typo-related bugs.
Packit 874993
set -u
Packit 874993
Packit 874993
usage_error ()
Packit 874993
{
Packit 874993
  echo "$0: $*" >&2
Packit 874993
  print_usage >&2
Packit 874993
  exit 2
Packit 874993
}
Packit 874993
Packit 874993
print_usage ()
Packit 874993
{
Packit 874993
  cat <
Packit 874993
Usage:
Packit 874993
  test-driver --test-name=NAME --log-file=PATH --trs-file=PATH
Packit 874993
              [--expect-failure={yes|no}] [--color-tests={yes|no}]
Packit 874993
              [--enable-hard-errors={yes|no}] [--]
Packit 874993
              TEST-SCRIPT [TEST-SCRIPT-ARGUMENTS]
Packit 874993
The '--test-name', '--log-file' and '--trs-file' options are mandatory.
Packit 874993
END
Packit 874993
}
Packit 874993
Packit 874993
test_name= # Used for reporting.
Packit 874993
log_file=  # Where to save the output of the test script.
Packit 874993
trs_file=  # Where to save the metadata of the test run.
Packit 874993
expect_failure=no
Packit 874993
color_tests=no
Packit 874993
enable_hard_errors=yes
Packit 874993
while test $# -gt 0; do
Packit 874993
  case $1 in
Packit 874993
  --help) print_usage; exit $?;;
Packit 874993
  --version) echo "test-driver $scriptversion"; exit $?;;
Packit 874993
  --test-name) test_name=$2; shift;;
Packit 874993
  --log-file) log_file=$2; shift;;
Packit 874993
  --trs-file) trs_file=$2; shift;;
Packit 874993
  --color-tests) color_tests=$2; shift;;
Packit 874993
  --expect-failure) expect_failure=$2; shift;;
Packit 874993
  --enable-hard-errors) enable_hard_errors=$2; shift;;
Packit 874993
  --) shift; break;;
Packit 874993
  -*) usage_error "invalid option: '$1'";;
Packit 874993
   *) break;;
Packit 874993
  esac
Packit 874993
  shift
Packit 874993
done
Packit 874993
Packit 874993
missing_opts=
Packit 874993
test x"$test_name" = x && missing_opts="$missing_opts --test-name"
Packit 874993
test x"$log_file"  = x && missing_opts="$missing_opts --log-file"
Packit 874993
test x"$trs_file"  = x && missing_opts="$missing_opts --trs-file"
Packit 874993
if test x"$missing_opts" != x; then
Packit 874993
  usage_error "the following mandatory options are missing:$missing_opts"
Packit 874993
fi
Packit 874993
Packit 874993
if test $# -eq 0; then
Packit 874993
  usage_error "missing argument"
Packit 874993
fi
Packit 874993
Packit 874993
if test $color_tests = yes; then
Packit 874993
  # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'.
Packit 874993
  red='?[0;31m' # Red.
Packit 874993
  grn='?[0;32m' # Green.
Packit 874993
  lgn='?[1;32m' # Light green.
Packit 874993
  blu='?[1;34m' # Blue.
Packit 874993
  mgn='?[0;35m' # Magenta.
Packit 874993
  std='?[m'     # No color.
Packit 874993
else
Packit 874993
  red= grn= lgn= blu= mgn= std=
Packit 874993
fi
Packit 874993
Packit 874993
do_exit='rm -f $log_file $trs_file; (exit $st); exit $st'
Packit 874993
trap "st=129; $do_exit" 1
Packit 874993
trap "st=130; $do_exit" 2
Packit 874993
trap "st=141; $do_exit" 13
Packit 874993
trap "st=143; $do_exit" 15
Packit 874993
Packit 874993
# Test script is run here.
Packit 874993
"$@" >$log_file 2>&1
Packit 874993
estatus=$?
Packit Service 688f9c
Packit 874993
if test $enable_hard_errors = no && test $estatus -eq 99; then
Packit Service 688f9c
  tweaked_estatus=1
Packit Service 688f9c
else
Packit Service 688f9c
  tweaked_estatus=$estatus
Packit 874993
fi
Packit 874993
Packit Service 688f9c
case $tweaked_estatus:$expect_failure in
Packit 874993
  0:yes) col=$red res=XPASS recheck=yes gcopy=yes;;
Packit 874993
  0:*)   col=$grn res=PASS  recheck=no  gcopy=no;;
Packit 874993
  77:*)  col=$blu res=SKIP  recheck=no  gcopy=yes;;
Packit 874993
  99:*)  col=$mgn res=ERROR recheck=yes gcopy=yes;;
Packit 874993
  *:yes) col=$lgn res=XFAIL recheck=no  gcopy=yes;;
Packit 874993
  *:*)   col=$red res=FAIL  recheck=yes gcopy=yes;;
Packit 874993
esac
Packit 874993
Packit Service 688f9c
# Report the test outcome and exit status in the logs, so that one can
Packit Service 688f9c
# know whether the test passed or failed simply by looking at the '.log'
Packit Service 688f9c
# file, without the need of also peaking into the corresponding '.trs'
Packit Service 688f9c
# file (automake bug#11814).
Packit Service 688f9c
echo "$res $test_name (exit status: $estatus)" >>$log_file
Packit Service 688f9c
Packit 874993
# Report outcome to console.
Packit 874993
echo "${col}${res}${std}: $test_name"
Packit 874993
Packit 874993
# Register the test result, and other relevant metadata.
Packit 874993
echo ":test-result: $res" > $trs_file
Packit 874993
echo ":global-test-result: $res" >> $trs_file
Packit 874993
echo ":recheck: $recheck" >> $trs_file
Packit 874993
echo ":copy-in-global-log: $gcopy" >> $trs_file
Packit 874993
Packit 874993
# Local Variables:
Packit 874993
# mode: shell-script
Packit 874993
# sh-indentation: 2
Packit Service 688f9c
# eval: (add-hook 'before-save-hook 'time-stamp)
Packit 874993
# time-stamp-start: "scriptversion="
Packit 874993
# time-stamp-format: "%:y-%02m-%02d.%02H"
Packit Service 688f9c
# time-stamp-time-zone: "UTC0"
Packit 874993
# time-stamp-end: "; # UTC"
Packit 874993
# End: