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