Blame test-driver

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