test-driver revision 54b5899c
1e23ec014Smrg#! /bin/sh
235c4bbdfSmrg# test-driver - basic testsuite driver script.
335c4bbdfSmrg
454b5899cSmrgscriptversion=2024-06-19.01; # UTC
535c4bbdfSmrg
654b5899cSmrg# Copyright (C) 2011-2024 Free Software Foundation, Inc.
735c4bbdfSmrg#
835c4bbdfSmrg# This program is free software; you can redistribute it and/or modify
935c4bbdfSmrg# it under the terms of the GNU General Public License as published by
1035c4bbdfSmrg# the Free Software Foundation; either version 2, or (at your option)
1135c4bbdfSmrg# any later version.
1235c4bbdfSmrg#
1335c4bbdfSmrg# This program is distributed in the hope that it will be useful,
1435c4bbdfSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
1535c4bbdfSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1635c4bbdfSmrg# GNU General Public License for more details.
1735c4bbdfSmrg#
1835c4bbdfSmrg# You should have received a copy of the GNU General Public License
19e23ec014Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
2035c4bbdfSmrg
2135c4bbdfSmrg# As a special exception to the GNU General Public License, if you
2235c4bbdfSmrg# distribute this file as part of a program that contains a
2335c4bbdfSmrg# configuration script generated by Autoconf, you may include it under
2435c4bbdfSmrg# the same distribution terms that you use for the rest of that program.
2535c4bbdfSmrg
2635c4bbdfSmrg# This file is maintained in Automake, please report
2735c4bbdfSmrg# bugs to <bug-automake@gnu.org> or send patches to
2835c4bbdfSmrg# <automake-patches@gnu.org>.
2935c4bbdfSmrg
3035c4bbdfSmrg# Make unconditional expansion of undefined variables an error.  This
3135c4bbdfSmrg# helps a lot in preventing typo-related bugs.
3235c4bbdfSmrgset -u
3335c4bbdfSmrg
3435c4bbdfSmrgusage_error ()
3535c4bbdfSmrg{
3635c4bbdfSmrg  echo "$0: $*" >&2
3735c4bbdfSmrg  print_usage >&2
3835c4bbdfSmrg  exit 2
3935c4bbdfSmrg}
4035c4bbdfSmrg
4135c4bbdfSmrgprint_usage ()
4235c4bbdfSmrg{
4335c4bbdfSmrg  cat <<END
4435c4bbdfSmrgUsage:
45dc61d50dSmrg  test-driver --test-name NAME --log-file PATH --trs-file PATH
46dc61d50dSmrg              [--expect-failure {yes|no}] [--color-tests {yes|no}]
4754b5899cSmrg              [--collect-skipped-logs {yes|no}]
48dc61d50dSmrg              [--enable-hard-errors {yes|no}] [--]
4935c4bbdfSmrg              TEST-SCRIPT [TEST-SCRIPT-ARGUMENTS]
50dc61d50dSmrg
5135c4bbdfSmrgThe '--test-name', '--log-file' and '--trs-file' options are mandatory.
52dc61d50dSmrgSee the GNU Automake documentation for information.
5354b5899cSmrg
5454b5899cSmrgReport bugs to <bug-automake@gnu.org>.
5554b5899cSmrgGNU Automake home page: <https://www.gnu.org/software/automake/>.
5654b5899cSmrgGeneral help using GNU software: <https://www.gnu.org/gethelp/>.
5735c4bbdfSmrgEND
5835c4bbdfSmrg}
5935c4bbdfSmrg
6035c4bbdfSmrgtest_name= # Used for reporting.
6135c4bbdfSmrglog_file=  # Where to save the output of the test script.
6235c4bbdfSmrgtrs_file=  # Where to save the metadata of the test run.
6335c4bbdfSmrgexpect_failure=no
6435c4bbdfSmrgcolor_tests=no
6554b5899cSmrgcollect_skipped_logs=yes
6635c4bbdfSmrgenable_hard_errors=yes
6735c4bbdfSmrgwhile test $# -gt 0; do
6835c4bbdfSmrg  case $1 in
6935c4bbdfSmrg  --help) print_usage; exit $?;;
7054b5899cSmrg  --version) echo "test-driver (GNU Automake) $scriptversion"; exit $?;;
7135c4bbdfSmrg  --test-name) test_name=$2; shift;;
7235c4bbdfSmrg  --log-file) log_file=$2; shift;;
7335c4bbdfSmrg  --trs-file) trs_file=$2; shift;;
7435c4bbdfSmrg  --color-tests) color_tests=$2; shift;;
7554b5899cSmrg  --collect-skipped-logs) collect_skipped_logs=$2; shift;;
7635c4bbdfSmrg  --expect-failure) expect_failure=$2; shift;;
7735c4bbdfSmrg  --enable-hard-errors) enable_hard_errors=$2; shift;;
7835c4bbdfSmrg  --) shift; break;;
7935c4bbdfSmrg  -*) usage_error "invalid option: '$1'";;
8035c4bbdfSmrg   *) break;;
8135c4bbdfSmrg  esac
8235c4bbdfSmrg  shift
8335c4bbdfSmrgdone
8435c4bbdfSmrg
8535c4bbdfSmrgmissing_opts=
8635c4bbdfSmrgtest x"$test_name" = x && missing_opts="$missing_opts --test-name"
8735c4bbdfSmrgtest x"$log_file"  = x && missing_opts="$missing_opts --log-file"
8835c4bbdfSmrgtest x"$trs_file"  = x && missing_opts="$missing_opts --trs-file"
8935c4bbdfSmrgif test x"$missing_opts" != x; then
9035c4bbdfSmrg  usage_error "the following mandatory options are missing:$missing_opts"
9135c4bbdfSmrgfi
9235c4bbdfSmrg
9335c4bbdfSmrgif test $# -eq 0; then
9435c4bbdfSmrg  usage_error "missing argument"
9535c4bbdfSmrgfi
9635c4bbdfSmrg
9735c4bbdfSmrgif test $color_tests = yes; then
9835c4bbdfSmrg  # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'.
9935c4bbdfSmrg  red='[0;31m' # Red.
10035c4bbdfSmrg  grn='[0;32m' # Green.
10135c4bbdfSmrg  lgn='[1;32m' # Light green.
10235c4bbdfSmrg  blu='[1;34m' # Blue.
10335c4bbdfSmrg  mgn='[0;35m' # Magenta.
10435c4bbdfSmrg  std='[m'     # No color.
10535c4bbdfSmrgelse
10635c4bbdfSmrg  red= grn= lgn= blu= mgn= std=
10735c4bbdfSmrgfi
10835c4bbdfSmrg
10935c4bbdfSmrgdo_exit='rm -f $log_file $trs_file; (exit $st); exit $st'
11035c4bbdfSmrgtrap "st=129; $do_exit" 1
11135c4bbdfSmrgtrap "st=130; $do_exit" 2
11235c4bbdfSmrgtrap "st=141; $do_exit" 13
11335c4bbdfSmrgtrap "st=143; $do_exit" 15
11435c4bbdfSmrg
115c82838c1Smrg# Test script is run here. We create the file first, then append to it,
116c82838c1Smrg# to ameliorate tests themselves also writing to the log file. Our tests
117c82838c1Smrg# don't, but others can (automake bug#35762).
118c82838c1Smrg: >"$log_file"
119c82838c1Smrg"$@" >>"$log_file" 2>&1
12035c4bbdfSmrgestatus=$?
12135c4bbdfSmrg
12235c4bbdfSmrgif test $enable_hard_errors = no && test $estatus -eq 99; then
12335c4bbdfSmrg  tweaked_estatus=1
12435c4bbdfSmrgelse
12535c4bbdfSmrg  tweaked_estatus=$estatus
12635c4bbdfSmrgfi
12735c4bbdfSmrg
12835c4bbdfSmrgcase $tweaked_estatus:$expect_failure in
12935c4bbdfSmrg  0:yes) col=$red res=XPASS recheck=yes gcopy=yes;;
13035c4bbdfSmrg  0:*)   col=$grn res=PASS  recheck=no  gcopy=no;;
13154b5899cSmrg  77:*)  col=$blu res=SKIP  recheck=no  gcopy=$collect_skipped_logs;;
13235c4bbdfSmrg  99:*)  col=$mgn res=ERROR recheck=yes gcopy=yes;;
13335c4bbdfSmrg  *:yes) col=$lgn res=XFAIL recheck=no  gcopy=yes;;
13435c4bbdfSmrg  *:*)   col=$red res=FAIL  recheck=yes gcopy=yes;;
13535c4bbdfSmrgesac
13635c4bbdfSmrg
13735c4bbdfSmrg# Report the test outcome and exit status in the logs, so that one can
13835c4bbdfSmrg# know whether the test passed or failed simply by looking at the '.log'
13935c4bbdfSmrg# file, without the need of also peaking into the corresponding '.trs'
14035c4bbdfSmrg# file (automake bug#11814).
141c82838c1Smrgecho "$res $test_name (exit status: $estatus)" >>"$log_file"
14235c4bbdfSmrg
14335c4bbdfSmrg# Report outcome to console.
14435c4bbdfSmrgecho "${col}${res}${std}: $test_name"
14535c4bbdfSmrg
14635c4bbdfSmrg# Register the test result, and other relevant metadata.
14735c4bbdfSmrgecho ":test-result: $res" > $trs_file
14835c4bbdfSmrgecho ":global-test-result: $res" >> $trs_file
14935c4bbdfSmrgecho ":recheck: $recheck" >> $trs_file
15035c4bbdfSmrgecho ":copy-in-global-log: $gcopy" >> $trs_file
15135c4bbdfSmrg
15235c4bbdfSmrg# Local Variables:
15335c4bbdfSmrg# mode: shell-script
15435c4bbdfSmrg# sh-indentation: 2
155e23ec014Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
15635c4bbdfSmrg# time-stamp-start: "scriptversion="
15735c4bbdfSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
1581b5d61b8Smrg# time-stamp-time-zone: "UTC0"
15935c4bbdfSmrg# time-stamp-end: "; # UTC"
16035c4bbdfSmrg# End:
161