Blame test-driver

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