Blame build-aux/test-driver

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