Blame test-driver

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