Blame test-driver

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