Blame test-driver

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