Blame test-driver

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