Blame test-driver

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