17515ee80Smrg#! /bin/sh
27515ee80Smrg# test-driver - basic testsuite driver script.
37515ee80Smrg
4433d0511Smrgscriptversion=2018-03-07.03; # UTC
57515ee80Smrg
6433d0511Smrg# Copyright (C) 2011-2021 Free Software Foundation, Inc.
77515ee80Smrg#
87515ee80Smrg# This program is free software; you can redistribute it and/or modify
97515ee80Smrg# it under the terms of the GNU General Public License as published by
107515ee80Smrg# the Free Software Foundation; either version 2, or (at your option)
117515ee80Smrg# any later version.
127515ee80Smrg#
137515ee80Smrg# This program is distributed in the hope that it will be useful,
147515ee80Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
157515ee80Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
167515ee80Smrg# GNU General Public License for more details.
177515ee80Smrg#
187515ee80Smrg# You should have received a copy of the GNU General Public License
19433d0511Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
207515ee80Smrg
217515ee80Smrg# As a special exception to the GNU General Public License, if you
227515ee80Smrg# distribute this file as part of a program that contains a
237515ee80Smrg# configuration script generated by Autoconf, you may include it under
247515ee80Smrg# the same distribution terms that you use for the rest of that program.
257515ee80Smrg
267515ee80Smrg# This file is maintained in Automake, please report
277515ee80Smrg# bugs to <bug-automake@gnu.org> or send patches to
287515ee80Smrg# <automake-patches@gnu.org>.
297515ee80Smrg
307515ee80Smrg# Make unconditional expansion of undefined variables an error.  This
317515ee80Smrg# helps a lot in preventing typo-related bugs.
327515ee80Smrgset -u
337515ee80Smrg
347515ee80Smrgusage_error ()
357515ee80Smrg{
367515ee80Smrg  echo "$0: $*" >&2
377515ee80Smrg  print_usage >&2
387515ee80Smrg  exit 2
397515ee80Smrg}
407515ee80Smrg
417515ee80Smrgprint_usage ()
427515ee80Smrg{
437515ee80Smrg  cat <<END
447515ee80SmrgUsage:
45433d0511Smrg  test-driver --test-name NAME --log-file PATH --trs-file PATH
46433d0511Smrg              [--expect-failure {yes|no}] [--color-tests {yes|no}]
47433d0511Smrg              [--enable-hard-errors {yes|no}] [--]
487515ee80Smrg              TEST-SCRIPT [TEST-SCRIPT-ARGUMENTS]
49433d0511Smrg
507515ee80SmrgThe '--test-name', '--log-file' and '--trs-file' options are mandatory.
51433d0511SmrgSee the GNU Automake documentation for information.
527515ee80SmrgEND
537515ee80Smrg}
547515ee80Smrg
557515ee80Smrgtest_name= # Used for reporting.
567515ee80Smrglog_file=  # Where to save the output of the test script.
577515ee80Smrgtrs_file=  # Where to save the metadata of the test run.
587515ee80Smrgexpect_failure=no
597515ee80Smrgcolor_tests=no
607515ee80Smrgenable_hard_errors=yes
617515ee80Smrgwhile test $# -gt 0; do
627515ee80Smrg  case $1 in
637515ee80Smrg  --help) print_usage; exit $?;;
647515ee80Smrg  --version) echo "test-driver $scriptversion"; exit $?;;
657515ee80Smrg  --test-name) test_name=$2; shift;;
667515ee80Smrg  --log-file) log_file=$2; shift;;
677515ee80Smrg  --trs-file) trs_file=$2; shift;;
687515ee80Smrg  --color-tests) color_tests=$2; shift;;
697515ee80Smrg  --expect-failure) expect_failure=$2; shift;;
707515ee80Smrg  --enable-hard-errors) enable_hard_errors=$2; shift;;
717515ee80Smrg  --) shift; break;;
727515ee80Smrg  -*) usage_error "invalid option: '$1'";;
737515ee80Smrg   *) break;;
747515ee80Smrg  esac
757515ee80Smrg  shift
767515ee80Smrgdone
777515ee80Smrg
787515ee80Smrgmissing_opts=
797515ee80Smrgtest x"$test_name" = x && missing_opts="$missing_opts --test-name"
807515ee80Smrgtest x"$log_file"  = x && missing_opts="$missing_opts --log-file"
817515ee80Smrgtest x"$trs_file"  = x && missing_opts="$missing_opts --trs-file"
827515ee80Smrgif test x"$missing_opts" != x; then
837515ee80Smrg  usage_error "the following mandatory options are missing:$missing_opts"
847515ee80Smrgfi
857515ee80Smrg
867515ee80Smrgif test $# -eq 0; then
877515ee80Smrg  usage_error "missing argument"
887515ee80Smrgfi
897515ee80Smrg
907515ee80Smrgif test $color_tests = yes; then
917515ee80Smrg  # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'.
927515ee80Smrg  red='[0;31m' # Red.
937515ee80Smrg  grn='[0;32m' # Green.
947515ee80Smrg  lgn='[1;32m' # Light green.
957515ee80Smrg  blu='[1;34m' # Blue.
967515ee80Smrg  mgn='[0;35m' # Magenta.
977515ee80Smrg  std='[m'     # No color.
987515ee80Smrgelse
997515ee80Smrg  red= grn= lgn= blu= mgn= std=
1007515ee80Smrgfi
1017515ee80Smrg
1027515ee80Smrgdo_exit='rm -f $log_file $trs_file; (exit $st); exit $st'
1037515ee80Smrgtrap "st=129; $do_exit" 1
1047515ee80Smrgtrap "st=130; $do_exit" 2
1057515ee80Smrgtrap "st=141; $do_exit" 13
1067515ee80Smrgtrap "st=143; $do_exit" 15
1077515ee80Smrg
108433d0511Smrg# Test script is run here. We create the file first, then append to it,
109433d0511Smrg# to ameliorate tests themselves also writing to the log file. Our tests
110433d0511Smrg# don't, but others can (automake bug#35762).
111433d0511Smrg: >"$log_file"
112433d0511Smrg"$@" >>"$log_file" 2>&1
1137515ee80Smrgestatus=$?
1147515ee80Smrg
1157515ee80Smrgif test $enable_hard_errors = no && test $estatus -eq 99; then
1167515ee80Smrg  tweaked_estatus=1
1177515ee80Smrgelse
1187515ee80Smrg  tweaked_estatus=$estatus
1197515ee80Smrgfi
1207515ee80Smrg
1217515ee80Smrgcase $tweaked_estatus:$expect_failure in
1227515ee80Smrg  0:yes) col=$red res=XPASS recheck=yes gcopy=yes;;
1237515ee80Smrg  0:*)   col=$grn res=PASS  recheck=no  gcopy=no;;
1247515ee80Smrg  77:*)  col=$blu res=SKIP  recheck=no  gcopy=yes;;
1257515ee80Smrg  99:*)  col=$mgn res=ERROR recheck=yes gcopy=yes;;
1267515ee80Smrg  *:yes) col=$lgn res=XFAIL recheck=no  gcopy=yes;;
1277515ee80Smrg  *:*)   col=$red res=FAIL  recheck=yes gcopy=yes;;
1287515ee80Smrgesac
1297515ee80Smrg
1307515ee80Smrg# Report the test outcome and exit status in the logs, so that one can
1317515ee80Smrg# know whether the test passed or failed simply by looking at the '.log'
1327515ee80Smrg# file, without the need of also peaking into the corresponding '.trs'
1337515ee80Smrg# file (automake bug#11814).
134433d0511Smrgecho "$res $test_name (exit status: $estatus)" >>"$log_file"
1357515ee80Smrg
1367515ee80Smrg# Report outcome to console.
1377515ee80Smrgecho "${col}${res}${std}: $test_name"
1387515ee80Smrg
1397515ee80Smrg# Register the test result, and other relevant metadata.
1407515ee80Smrgecho ":test-result: $res" > $trs_file
1417515ee80Smrgecho ":global-test-result: $res" >> $trs_file
1427515ee80Smrgecho ":recheck: $recheck" >> $trs_file
1437515ee80Smrgecho ":copy-in-global-log: $gcopy" >> $trs_file
1447515ee80Smrg
1457515ee80Smrg# Local Variables:
1467515ee80Smrg# mode: shell-script
1477515ee80Smrg# sh-indentation: 2
148433d0511Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
1497515ee80Smrg# time-stamp-start: "scriptversion="
1507515ee80Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
151433d0511Smrg# time-stamp-time-zone: "UTC0"
1527515ee80Smrg# time-stamp-end: "; # UTC"
1537515ee80Smrg# End:
154