Blame test-driver

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