test-driver revision 765b7306
19a011757Smrg#! /bin/sh
29a011757Smrg# test-driver - basic testsuite driver script.
39a011757Smrg
46c3c2bceSmrgscriptversion=2018-03-07.03; # UTC
59a011757Smrg
6765b7306Smrg# Copyright (C) 2011-2021 Free Software Foundation, Inc.
79a011757Smrg#
89a011757Smrg# This program is free software; you can redistribute it and/or modify
99a011757Smrg# it under the terms of the GNU General Public License as published by
109a011757Smrg# the Free Software Foundation; either version 2, or (at your option)
119a011757Smrg# any later version.
129a011757Smrg#
139a011757Smrg# This program is distributed in the hope that it will be useful,
149a011757Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
159a011757Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
169a011757Smrg# GNU General Public License for more details.
179a011757Smrg#
189a011757Smrg# You should have received a copy of the GNU General Public License
196c3c2bceSmrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
209a011757Smrg
219a011757Smrg# As a special exception to the GNU General Public License, if you
229a011757Smrg# distribute this file as part of a program that contains a
239a011757Smrg# configuration script generated by Autoconf, you may include it under
249a011757Smrg# the same distribution terms that you use for the rest of that program.
259a011757Smrg
269a011757Smrg# This file is maintained in Automake, please report
279a011757Smrg# bugs to <bug-automake@gnu.org> or send patches to
289a011757Smrg# <automake-patches@gnu.org>.
299a011757Smrg
309a011757Smrg# Make unconditional expansion of undefined variables an error.  This
319a011757Smrg# helps a lot in preventing typo-related bugs.
329a011757Smrgset -u
339a011757Smrg
349a011757Smrgusage_error ()
359a011757Smrg{
369a011757Smrg  echo "$0: $*" >&2
379a011757Smrg  print_usage >&2
389a011757Smrg  exit 2
399a011757Smrg}
409a011757Smrg
419a011757Smrgprint_usage ()
429a011757Smrg{
439a011757Smrg  cat <<END
449a011757SmrgUsage:
450d22642bSmrg  test-driver --test-name NAME --log-file PATH --trs-file PATH
460d22642bSmrg              [--expect-failure {yes|no}] [--color-tests {yes|no}]
470d22642bSmrg              [--enable-hard-errors {yes|no}] [--]
4840c5344fSmrg              TEST-SCRIPT [TEST-SCRIPT-ARGUMENTS]
490d22642bSmrg
509a011757SmrgThe '--test-name', '--log-file' and '--trs-file' options are mandatory.
510d22642bSmrgSee the GNU Automake documentation for information.
529a011757SmrgEND
539a011757Smrg}
549a011757Smrg
559a011757Smrgtest_name= # Used for reporting.
569a011757Smrglog_file=  # Where to save the output of the test script.
579a011757Smrgtrs_file=  # Where to save the metadata of the test run.
589a011757Smrgexpect_failure=no
599a011757Smrgcolor_tests=no
609a011757Smrgenable_hard_errors=yes
619a011757Smrgwhile test $# -gt 0; do
629a011757Smrg  case $1 in
639a011757Smrg  --help) print_usage; exit $?;;
649a011757Smrg  --version) echo "test-driver $scriptversion"; exit $?;;
659a011757Smrg  --test-name) test_name=$2; shift;;
669a011757Smrg  --log-file) log_file=$2; shift;;
679a011757Smrg  --trs-file) trs_file=$2; shift;;
689a011757Smrg  --color-tests) color_tests=$2; shift;;
699a011757Smrg  --expect-failure) expect_failure=$2; shift;;
709a011757Smrg  --enable-hard-errors) enable_hard_errors=$2; shift;;
719a011757Smrg  --) shift; break;;
729a011757Smrg  -*) usage_error "invalid option: '$1'";;
7340c5344fSmrg   *) break;;
749a011757Smrg  esac
759a011757Smrg  shift
769a011757Smrgdone
779a011757Smrg
7840c5344fSmrgmissing_opts=
7940c5344fSmrgtest x"$test_name" = x && missing_opts="$missing_opts --test-name"
8040c5344fSmrgtest x"$log_file"  = x && missing_opts="$missing_opts --log-file"
8140c5344fSmrgtest x"$trs_file"  = x && missing_opts="$missing_opts --trs-file"
8240c5344fSmrgif test x"$missing_opts" != x; then
8340c5344fSmrg  usage_error "the following mandatory options are missing:$missing_opts"
8440c5344fSmrgfi
8540c5344fSmrg
8640c5344fSmrgif test $# -eq 0; then
8740c5344fSmrg  usage_error "missing argument"
8840c5344fSmrgfi
8940c5344fSmrg
909a011757Smrgif test $color_tests = yes; then
919a011757Smrg  # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'.
929a011757Smrg  red='[0;31m' # Red.
939a011757Smrg  grn='[0;32m' # Green.
949a011757Smrg  lgn='[1;32m' # Light green.
959a011757Smrg  blu='[1;34m' # Blue.
969a011757Smrg  mgn='[0;35m' # Magenta.
979a011757Smrg  std='[m'     # No color.
989a011757Smrgelse
999a011757Smrg  red= grn= lgn= blu= mgn= std=
1009a011757Smrgfi
1019a011757Smrg
1029a011757Smrgdo_exit='rm -f $log_file $trs_file; (exit $st); exit $st'
1039a011757Smrgtrap "st=129; $do_exit" 1
1049a011757Smrgtrap "st=130; $do_exit" 2
1059a011757Smrgtrap "st=141; $do_exit" 13
1069a011757Smrgtrap "st=143; $do_exit" 15
1079a011757Smrg
108765b7306Smrg# Test script is run here. We create the file first, then append to it,
109765b7306Smrg# to ameliorate tests themselves also writing to the log file. Our tests
110765b7306Smrg# don't, but others can (automake bug#35762).
111765b7306Smrg: >"$log_file"
112765b7306Smrg"$@" >>"$log_file" 2>&1
1139a011757Smrgestatus=$?
11440c5344fSmrg
1159a011757Smrgif test $enable_hard_errors = no && test $estatus -eq 99; then
11640c5344fSmrg  tweaked_estatus=1
11740c5344fSmrgelse
11840c5344fSmrg  tweaked_estatus=$estatus
1199a011757Smrgfi
1209a011757Smrg
12140c5344fSmrgcase $tweaked_estatus:$expect_failure in
1229a011757Smrg  0:yes) col=$red res=XPASS recheck=yes gcopy=yes;;
1239a011757Smrg  0:*)   col=$grn res=PASS  recheck=no  gcopy=no;;
1249a011757Smrg  77:*)  col=$blu res=SKIP  recheck=no  gcopy=yes;;
1259a011757Smrg  99:*)  col=$mgn res=ERROR recheck=yes gcopy=yes;;
1269a011757Smrg  *:yes) col=$lgn res=XFAIL recheck=no  gcopy=yes;;
1279a011757Smrg  *:*)   col=$red res=FAIL  recheck=yes gcopy=yes;;
1289a011757Smrgesac
1299a011757Smrg
13040c5344fSmrg# Report the test outcome and exit status in the logs, so that one can
13140c5344fSmrg# know whether the test passed or failed simply by looking at the '.log'
13240c5344fSmrg# file, without the need of also peaking into the corresponding '.trs'
13340c5344fSmrg# file (automake bug#11814).
134765b7306Smrgecho "$res $test_name (exit status: $estatus)" >>"$log_file"
13540c5344fSmrg
1369a011757Smrg# Report outcome to console.
1379a011757Smrgecho "${col}${res}${std}: $test_name"
1389a011757Smrg
1399a011757Smrg# Register the test result, and other relevant metadata.
1409a011757Smrgecho ":test-result: $res" > $trs_file
1419a011757Smrgecho ":global-test-result: $res" >> $trs_file
1429a011757Smrgecho ":recheck: $recheck" >> $trs_file
1439a011757Smrgecho ":copy-in-global-log: $gcopy" >> $trs_file
1449a011757Smrg
1459a011757Smrg# Local Variables:
1469a011757Smrg# mode: shell-script
1479a011757Smrg# sh-indentation: 2
1486c3c2bceSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
1499a011757Smrg# time-stamp-start: "scriptversion="
1509a011757Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
1516c3c2bceSmrg# time-stamp-time-zone: "UTC0"
1529a011757Smrg# time-stamp-end: "; # UTC"
1539a011757Smrg# End:
154