xref: /netbsd-src/external/lgpl3/mpc/dist/build-aux/test-driver (revision 367b82799ab709709d3c3b541df56a2a14644d3e)
190a8ff21Smrg#!/bin/sh
290a8ff21Smrg# test-driver - basic testsuite driver script.
390a8ff21Smrg
490a8ff21Smrgscriptversion=2018-03-07.03; # UTC
590a8ff21Smrg
6*367b8279Smrg# Copyright (C) 2011-2021 Free Software Foundation, Inc.
790a8ff21Smrg#
890a8ff21Smrg# This program is free software; you can redistribute it and/or modify
990a8ff21Smrg# it under the terms of the GNU General Public License as published by
1090a8ff21Smrg# the Free Software Foundation; either version 2, or (at your option)
1190a8ff21Smrg# any later version.
1290a8ff21Smrg#
1390a8ff21Smrg# This program is distributed in the hope that it will be useful,
1490a8ff21Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
1590a8ff21Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1690a8ff21Smrg# GNU General Public License for more details.
1790a8ff21Smrg#
1890a8ff21Smrg# You should have received a copy of the GNU General Public License
1990a8ff21Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
2090a8ff21Smrg
2190a8ff21Smrg# As a special exception to the GNU General Public License, if you
2290a8ff21Smrg# distribute this file as part of a program that contains a
2390a8ff21Smrg# configuration script generated by Autoconf, you may include it under
2490a8ff21Smrg# the same distribution terms that you use for the rest of that program.
2590a8ff21Smrg
2690a8ff21Smrg# This file is maintained in Automake, please report
2790a8ff21Smrg# bugs to <bug-automake@gnu.org> or send patches to
2890a8ff21Smrg# <automake-patches@gnu.org>.
2990a8ff21Smrg
3090a8ff21Smrg# Make unconditional expansion of undefined variables an error.  This
3190a8ff21Smrg# helps a lot in preventing typo-related bugs.
3290a8ff21Smrgset -u
3390a8ff21Smrg
3490a8ff21Smrgusage_error ()
3590a8ff21Smrg{
3690a8ff21Smrg  echo "$0: $*" >&2
3790a8ff21Smrg  print_usage >&2
3890a8ff21Smrg  exit 2
3990a8ff21Smrg}
4090a8ff21Smrg
4190a8ff21Smrgprint_usage ()
4290a8ff21Smrg{
4390a8ff21Smrg  cat <<END
4490a8ff21SmrgUsage:
45*367b8279Smrg  test-driver --test-name NAME --log-file PATH --trs-file PATH
46*367b8279Smrg              [--expect-failure {yes|no}] [--color-tests {yes|no}]
47*367b8279Smrg              [--enable-hard-errors {yes|no}] [--]
4890a8ff21Smrg              TEST-SCRIPT [TEST-SCRIPT-ARGUMENTS]
49*367b8279Smrg
5090a8ff21SmrgThe '--test-name', '--log-file' and '--trs-file' options are mandatory.
51*367b8279SmrgSee the GNU Automake documentation for information.
5290a8ff21SmrgEND
5390a8ff21Smrg}
5490a8ff21Smrg
5590a8ff21Smrgtest_name= # Used for reporting.
5690a8ff21Smrglog_file=  # Where to save the output of the test script.
5790a8ff21Smrgtrs_file=  # Where to save the metadata of the test run.
5890a8ff21Smrgexpect_failure=no
5990a8ff21Smrgcolor_tests=no
6090a8ff21Smrgenable_hard_errors=yes
6190a8ff21Smrgwhile test $# -gt 0; do
6290a8ff21Smrg  case $1 in
6390a8ff21Smrg  --help) print_usage; exit $?;;
6490a8ff21Smrg  --version) echo "test-driver $scriptversion"; exit $?;;
6590a8ff21Smrg  --test-name) test_name=$2; shift;;
6690a8ff21Smrg  --log-file) log_file=$2; shift;;
6790a8ff21Smrg  --trs-file) trs_file=$2; shift;;
6890a8ff21Smrg  --color-tests) color_tests=$2; shift;;
6990a8ff21Smrg  --expect-failure) expect_failure=$2; shift;;
7090a8ff21Smrg  --enable-hard-errors) enable_hard_errors=$2; shift;;
7190a8ff21Smrg  --) shift; break;;
7290a8ff21Smrg  -*) usage_error "invalid option: '$1'";;
7390a8ff21Smrg   *) break;;
7490a8ff21Smrg  esac
7590a8ff21Smrg  shift
7690a8ff21Smrgdone
7790a8ff21Smrg
7890a8ff21Smrgmissing_opts=
7990a8ff21Smrgtest x"$test_name" = x && missing_opts="$missing_opts --test-name"
8090a8ff21Smrgtest x"$log_file"  = x && missing_opts="$missing_opts --log-file"
8190a8ff21Smrgtest x"$trs_file"  = x && missing_opts="$missing_opts --trs-file"
8290a8ff21Smrgif test x"$missing_opts" != x; then
8390a8ff21Smrg  usage_error "the following mandatory options are missing:$missing_opts"
8490a8ff21Smrgfi
8590a8ff21Smrg
8690a8ff21Smrgif test $# -eq 0; then
8790a8ff21Smrg  usage_error "missing argument"
8890a8ff21Smrgfi
8990a8ff21Smrg
9090a8ff21Smrgif test $color_tests = yes; then
9190a8ff21Smrg  # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'.
9290a8ff21Smrg  red='' # Red.
9390a8ff21Smrg  grn='' # Green.
9490a8ff21Smrg  lgn='' # Light green.
9590a8ff21Smrg  blu='' # Blue.
9690a8ff21Smrg  mgn='' # Magenta.
9790a8ff21Smrg  std=''     # No color.
9890a8ff21Smrgelse
9990a8ff21Smrg  red= grn= lgn= blu= mgn= std=
10090a8ff21Smrgfi
10190a8ff21Smrg
10290a8ff21Smrgdo_exit='rm -f $log_file $trs_file; (exit $st); exit $st'
10390a8ff21Smrgtrap "st=129; $do_exit" 1
10490a8ff21Smrgtrap "st=130; $do_exit" 2
10590a8ff21Smrgtrap "st=141; $do_exit" 13
10690a8ff21Smrgtrap "st=143; $do_exit" 15
10790a8ff21Smrg
108*367b8279Smrg# Test script is run here. We create the file first, then append to it,
109*367b8279Smrg# to ameliorate tests themselves also writing to the log file. Our tests
110*367b8279Smrg# don't, but others can (automake bug#35762).
111*367b8279Smrg: >"$log_file"
112*367b8279Smrg"$@" >>"$log_file" 2>&1
11390a8ff21Smrgestatus=$?
11490a8ff21Smrg
11590a8ff21Smrgif test $enable_hard_errors = no && test $estatus -eq 99; then
11690a8ff21Smrg  tweaked_estatus=1
11790a8ff21Smrgelse
11890a8ff21Smrg  tweaked_estatus=$estatus
11990a8ff21Smrgfi
12090a8ff21Smrg
12190a8ff21Smrgcase $tweaked_estatus:$expect_failure in
12290a8ff21Smrg  0:yes) col=$red res=XPASS recheck=yes gcopy=yes;;
12390a8ff21Smrg  0:*)   col=$grn res=PASS  recheck=no  gcopy=no;;
12490a8ff21Smrg  77:*)  col=$blu res=SKIP  recheck=no  gcopy=yes;;
12590a8ff21Smrg  99:*)  col=$mgn res=ERROR recheck=yes gcopy=yes;;
12690a8ff21Smrg  *:yes) col=$lgn res=XFAIL recheck=no  gcopy=yes;;
12790a8ff21Smrg  *:*)   col=$red res=FAIL  recheck=yes gcopy=yes;;
12890a8ff21Smrgesac
12990a8ff21Smrg
13090a8ff21Smrg# Report the test outcome and exit status in the logs, so that one can
13190a8ff21Smrg# know whether the test passed or failed simply by looking at the '.log'
13290a8ff21Smrg# file, without the need of also peaking into the corresponding '.trs'
13390a8ff21Smrg# file (automake bug#11814).
134*367b8279Smrgecho "$res $test_name (exit status: $estatus)" >>"$log_file"
13590a8ff21Smrg
13690a8ff21Smrg# Report outcome to console.
13790a8ff21Smrgecho "${col}${res}${std}: $test_name"
13890a8ff21Smrg
13990a8ff21Smrg# Register the test result, and other relevant metadata.
14090a8ff21Smrgecho ":test-result: $res" > $trs_file
14190a8ff21Smrgecho ":global-test-result: $res" >> $trs_file
14290a8ff21Smrgecho ":recheck: $recheck" >> $trs_file
14390a8ff21Smrgecho ":copy-in-global-log: $gcopy" >> $trs_file
14490a8ff21Smrg
14590a8ff21Smrg# Local Variables:
14690a8ff21Smrg# mode: shell-script
14790a8ff21Smrg# sh-indentation: 2
14890a8ff21Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
14990a8ff21Smrg# time-stamp-start: "scriptversion="
15090a8ff21Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
15190a8ff21Smrg# time-stamp-time-zone: "UTC0"
15290a8ff21Smrg# time-stamp-end: "; # UTC"
15390a8ff21Smrg# End:
154