Blame build-aux/test-driver

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