Blame test-driver

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