1313a12fdSmrg#! /bin/sh 2313a12fdSmrg# test-driver - basic testsuite driver script. 3313a12fdSmrg 4ae545d91Smrgscriptversion=2024-06-19.01; # UTC 5313a12fdSmrg 6ae545d91Smrg# Copyright (C) 2011-2024 Free Software Foundation, Inc. 7313a12fdSmrg# 8313a12fdSmrg# This program is free software; you can redistribute it and/or modify 9313a12fdSmrg# it under the terms of the GNU General Public License as published by 10313a12fdSmrg# the Free Software Foundation; either version 2, or (at your option) 11313a12fdSmrg# any later version. 12313a12fdSmrg# 13313a12fdSmrg# This program is distributed in the hope that it will be useful, 14313a12fdSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 15313a12fdSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16313a12fdSmrg# GNU General Public License for more details. 17313a12fdSmrg# 18313a12fdSmrg# You should have received a copy of the GNU General Public License 1995b7a5c8Smrg# along with this program. If not, see <https://www.gnu.org/licenses/>. 20313a12fdSmrg 21313a12fdSmrg# As a special exception to the GNU General Public License, if you 22313a12fdSmrg# distribute this file as part of a program that contains a 23313a12fdSmrg# configuration script generated by Autoconf, you may include it under 24313a12fdSmrg# the same distribution terms that you use for the rest of that program. 25313a12fdSmrg 26313a12fdSmrg# This file is maintained in Automake, please report 27313a12fdSmrg# bugs to <bug-automake@gnu.org> or send patches to 28313a12fdSmrg# <automake-patches@gnu.org>. 29313a12fdSmrg 30313a12fdSmrg# Make unconditional expansion of undefined variables an error. This 31313a12fdSmrg# helps a lot in preventing typo-related bugs. 32313a12fdSmrgset -u 33313a12fdSmrg 34313a12fdSmrgusage_error () 35313a12fdSmrg{ 36313a12fdSmrg echo "$0: $*" >&2 37313a12fdSmrg print_usage >&2 38313a12fdSmrg exit 2 39313a12fdSmrg} 40313a12fdSmrg 41313a12fdSmrgprint_usage () 42313a12fdSmrg{ 43313a12fdSmrg cat <<END 44313a12fdSmrgUsage: 4595b7a5c8Smrg test-driver --test-name NAME --log-file PATH --trs-file PATH 4695b7a5c8Smrg [--expect-failure {yes|no}] [--color-tests {yes|no}] 47ae545d91Smrg [--collect-skipped-logs {yes|no}] 4895b7a5c8Smrg [--enable-hard-errors {yes|no}] [--] 497cea3689Smrg TEST-SCRIPT [TEST-SCRIPT-ARGUMENTS] 5095b7a5c8Smrg 51313a12fdSmrgThe '--test-name', '--log-file' and '--trs-file' options are mandatory. 5295b7a5c8SmrgSee the GNU Automake documentation for information. 53ae545d91Smrg 54ae545d91SmrgReport bugs to <bug-automake@gnu.org>. 55ae545d91SmrgGNU Automake home page: <https://www.gnu.org/software/automake/>. 56ae545d91SmrgGeneral help using GNU software: <https://www.gnu.org/gethelp/>. 57313a12fdSmrgEND 58313a12fdSmrg} 59313a12fdSmrg 60313a12fdSmrgtest_name= # Used for reporting. 61313a12fdSmrglog_file= # Where to save the output of the test script. 62313a12fdSmrgtrs_file= # Where to save the metadata of the test run. 63313a12fdSmrgexpect_failure=no 64313a12fdSmrgcolor_tests=no 65ae545d91Smrgcollect_skipped_logs=yes 66313a12fdSmrgenable_hard_errors=yes 67313a12fdSmrgwhile test $# -gt 0; do 68313a12fdSmrg case $1 in 69313a12fdSmrg --help) print_usage; exit $?;; 70ae545d91Smrg --version) echo "test-driver (GNU Automake) $scriptversion"; exit $?;; 71313a12fdSmrg --test-name) test_name=$2; shift;; 72313a12fdSmrg --log-file) log_file=$2; shift;; 73313a12fdSmrg --trs-file) trs_file=$2; shift;; 74313a12fdSmrg --color-tests) color_tests=$2; shift;; 75ae545d91Smrg --collect-skipped-logs) collect_skipped_logs=$2; shift;; 76313a12fdSmrg --expect-failure) expect_failure=$2; shift;; 77313a12fdSmrg --enable-hard-errors) enable_hard_errors=$2; shift;; 78313a12fdSmrg --) shift; break;; 79313a12fdSmrg -*) usage_error "invalid option: '$1'";; 807cea3689Smrg *) break;; 81313a12fdSmrg esac 82313a12fdSmrg shift 83313a12fdSmrgdone 84313a12fdSmrg 857cea3689Smrgmissing_opts= 867cea3689Smrgtest x"$test_name" = x && missing_opts="$missing_opts --test-name" 877cea3689Smrgtest x"$log_file" = x && missing_opts="$missing_opts --log-file" 887cea3689Smrgtest x"$trs_file" = x && missing_opts="$missing_opts --trs-file" 897cea3689Smrgif test x"$missing_opts" != x; then 907cea3689Smrg usage_error "the following mandatory options are missing:$missing_opts" 917cea3689Smrgfi 927cea3689Smrg 937cea3689Smrgif test $# -eq 0; then 947cea3689Smrg usage_error "missing argument" 957cea3689Smrgfi 967cea3689Smrg 97313a12fdSmrgif test $color_tests = yes; then 98313a12fdSmrg # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'. 99313a12fdSmrg red='[0;31m' # Red. 100313a12fdSmrg grn='[0;32m' # Green. 101313a12fdSmrg lgn='[1;32m' # Light green. 102313a12fdSmrg blu='[1;34m' # Blue. 103313a12fdSmrg mgn='[0;35m' # Magenta. 104313a12fdSmrg std='[m' # No color. 105313a12fdSmrgelse 106313a12fdSmrg red= grn= lgn= blu= mgn= std= 107313a12fdSmrgfi 108313a12fdSmrg 109313a12fdSmrgdo_exit='rm -f $log_file $trs_file; (exit $st); exit $st' 110313a12fdSmrgtrap "st=129; $do_exit" 1 111313a12fdSmrgtrap "st=130; $do_exit" 2 112313a12fdSmrgtrap "st=141; $do_exit" 13 113313a12fdSmrgtrap "st=143; $do_exit" 15 114313a12fdSmrg 11595b7a5c8Smrg# Test script is run here. We create the file first, then append to it, 11695b7a5c8Smrg# to ameliorate tests themselves also writing to the log file. Our tests 11795b7a5c8Smrg# don't, but others can (automake bug#35762). 11895b7a5c8Smrg: >"$log_file" 11995b7a5c8Smrg"$@" >>"$log_file" 2>&1 120313a12fdSmrgestatus=$? 1217cea3689Smrg 122313a12fdSmrgif test $enable_hard_errors = no && test $estatus -eq 99; then 1237cea3689Smrg tweaked_estatus=1 1247cea3689Smrgelse 1257cea3689Smrg tweaked_estatus=$estatus 126313a12fdSmrgfi 127313a12fdSmrg 1287cea3689Smrgcase $tweaked_estatus:$expect_failure in 129313a12fdSmrg 0:yes) col=$red res=XPASS recheck=yes gcopy=yes;; 130313a12fdSmrg 0:*) col=$grn res=PASS recheck=no gcopy=no;; 131ae545d91Smrg 77:*) col=$blu res=SKIP recheck=no gcopy=$collect_skipped_logs;; 132313a12fdSmrg 99:*) col=$mgn res=ERROR recheck=yes gcopy=yes;; 133313a12fdSmrg *:yes) col=$lgn res=XFAIL recheck=no gcopy=yes;; 134313a12fdSmrg *:*) col=$red res=FAIL recheck=yes gcopy=yes;; 135313a12fdSmrgesac 136313a12fdSmrg 1377cea3689Smrg# Report the test outcome and exit status in the logs, so that one can 1387cea3689Smrg# know whether the test passed or failed simply by looking at the '.log' 1397cea3689Smrg# file, without the need of also peaking into the corresponding '.trs' 1407cea3689Smrg# file (automake bug#11814). 14195b7a5c8Smrgecho "$res $test_name (exit status: $estatus)" >>"$log_file" 1427cea3689Smrg 143313a12fdSmrg# Report outcome to console. 144313a12fdSmrgecho "${col}${res}${std}: $test_name" 145313a12fdSmrg 146313a12fdSmrg# Register the test result, and other relevant metadata. 147313a12fdSmrgecho ":test-result: $res" > $trs_file 148313a12fdSmrgecho ":global-test-result: $res" >> $trs_file 149313a12fdSmrgecho ":recheck: $recheck" >> $trs_file 150313a12fdSmrgecho ":copy-in-global-log: $gcopy" >> $trs_file 151313a12fdSmrg 152313a12fdSmrg# Local Variables: 153313a12fdSmrg# mode: shell-script 154313a12fdSmrg# sh-indentation: 2 15595b7a5c8Smrg# eval: (add-hook 'before-save-hook 'time-stamp) 156313a12fdSmrg# time-stamp-start: "scriptversion=" 157313a12fdSmrg# time-stamp-format: "%:y-%02m-%02d.%02H" 15895b7a5c8Smrg# time-stamp-time-zone: "UTC0" 159313a12fdSmrg# time-stamp-end: "; # UTC" 160313a12fdSmrg# End: 161