Blame test-driver

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