19a011757Smrg#! /bin/sh 29a011757Smrg# test-driver - basic testsuite driver script. 39a011757Smrg 4f6d57fdeSmrgscriptversion=2024-06-19.01; # UTC 59a011757Smrg 6f6d57fdeSmrg# Copyright (C) 2011-2024 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}] 47f6d57fdeSmrg [--collect-skipped-logs {yes|no}] 480d22642bSmrg [--enable-hard-errors {yes|no}] [--] 4940c5344fSmrg TEST-SCRIPT [TEST-SCRIPT-ARGUMENTS] 500d22642bSmrg 519a011757SmrgThe '--test-name', '--log-file' and '--trs-file' options are mandatory. 520d22642bSmrgSee the GNU Automake documentation for information. 53f6d57fdeSmrg 54f6d57fdeSmrgReport bugs to <bug-automake@gnu.org>. 55f6d57fdeSmrgGNU Automake home page: <https://www.gnu.org/software/automake/>. 56f6d57fdeSmrgGeneral help using GNU software: <https://www.gnu.org/gethelp/>. 579a011757SmrgEND 589a011757Smrg} 599a011757Smrg 609a011757Smrgtest_name= # Used for reporting. 619a011757Smrglog_file= # Where to save the output of the test script. 629a011757Smrgtrs_file= # Where to save the metadata of the test run. 639a011757Smrgexpect_failure=no 649a011757Smrgcolor_tests=no 65f6d57fdeSmrgcollect_skipped_logs=yes 669a011757Smrgenable_hard_errors=yes 679a011757Smrgwhile test $# -gt 0; do 689a011757Smrg case $1 in 699a011757Smrg --help) print_usage; exit $?;; 70f6d57fdeSmrg --version) echo "test-driver (GNU Automake) $scriptversion"; exit $?;; 719a011757Smrg --test-name) test_name=$2; shift;; 729a011757Smrg --log-file) log_file=$2; shift;; 739a011757Smrg --trs-file) trs_file=$2; shift;; 749a011757Smrg --color-tests) color_tests=$2; shift;; 75f6d57fdeSmrg --collect-skipped-logs) collect_skipped_logs=$2; shift;; 769a011757Smrg --expect-failure) expect_failure=$2; shift;; 779a011757Smrg --enable-hard-errors) enable_hard_errors=$2; shift;; 789a011757Smrg --) shift; break;; 799a011757Smrg -*) usage_error "invalid option: '$1'";; 8040c5344fSmrg *) break;; 819a011757Smrg esac 829a011757Smrg shift 839a011757Smrgdone 849a011757Smrg 8540c5344fSmrgmissing_opts= 8640c5344fSmrgtest x"$test_name" = x && missing_opts="$missing_opts --test-name" 8740c5344fSmrgtest x"$log_file" = x && missing_opts="$missing_opts --log-file" 8840c5344fSmrgtest x"$trs_file" = x && missing_opts="$missing_opts --trs-file" 8940c5344fSmrgif test x"$missing_opts" != x; then 9040c5344fSmrg usage_error "the following mandatory options are missing:$missing_opts" 9140c5344fSmrgfi 9240c5344fSmrg 9340c5344fSmrgif test $# -eq 0; then 9440c5344fSmrg usage_error "missing argument" 9540c5344fSmrgfi 9640c5344fSmrg 979a011757Smrgif test $color_tests = yes; then 989a011757Smrg # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'. 999a011757Smrg red='[0;31m' # Red. 1009a011757Smrg grn='[0;32m' # Green. 1019a011757Smrg lgn='[1;32m' # Light green. 1029a011757Smrg blu='[1;34m' # Blue. 1039a011757Smrg mgn='[0;35m' # Magenta. 1049a011757Smrg std='[m' # No color. 1059a011757Smrgelse 1069a011757Smrg red= grn= lgn= blu= mgn= std= 1079a011757Smrgfi 1089a011757Smrg 1099a011757Smrgdo_exit='rm -f $log_file $trs_file; (exit $st); exit $st' 1109a011757Smrgtrap "st=129; $do_exit" 1 1119a011757Smrgtrap "st=130; $do_exit" 2 1129a011757Smrgtrap "st=141; $do_exit" 13 1139a011757Smrgtrap "st=143; $do_exit" 15 1149a011757Smrg 115765b7306Smrg# Test script is run here. We create the file first, then append to it, 116765b7306Smrg# to ameliorate tests themselves also writing to the log file. Our tests 117765b7306Smrg# don't, but others can (automake bug#35762). 118765b7306Smrg: >"$log_file" 119765b7306Smrg"$@" >>"$log_file" 2>&1 1209a011757Smrgestatus=$? 12140c5344fSmrg 1229a011757Smrgif test $enable_hard_errors = no && test $estatus -eq 99; then 12340c5344fSmrg tweaked_estatus=1 12440c5344fSmrgelse 12540c5344fSmrg tweaked_estatus=$estatus 1269a011757Smrgfi 1279a011757Smrg 12840c5344fSmrgcase $tweaked_estatus:$expect_failure in 1299a011757Smrg 0:yes) col=$red res=XPASS recheck=yes gcopy=yes;; 1309a011757Smrg 0:*) col=$grn res=PASS recheck=no gcopy=no;; 131f6d57fdeSmrg 77:*) col=$blu res=SKIP recheck=no gcopy=$collect_skipped_logs;; 1329a011757Smrg 99:*) col=$mgn res=ERROR recheck=yes gcopy=yes;; 1339a011757Smrg *:yes) col=$lgn res=XFAIL recheck=no gcopy=yes;; 1349a011757Smrg *:*) col=$red res=FAIL recheck=yes gcopy=yes;; 1359a011757Smrgesac 1369a011757Smrg 13740c5344fSmrg# Report the test outcome and exit status in the logs, so that one can 13840c5344fSmrg# know whether the test passed or failed simply by looking at the '.log' 13940c5344fSmrg# file, without the need of also peaking into the corresponding '.trs' 14040c5344fSmrg# file (automake bug#11814). 141765b7306Smrgecho "$res $test_name (exit status: $estatus)" >>"$log_file" 14240c5344fSmrg 1439a011757Smrg# Report outcome to console. 1449a011757Smrgecho "${col}${res}${std}: $test_name" 1459a011757Smrg 1469a011757Smrg# Register the test result, and other relevant metadata. 1479a011757Smrgecho ":test-result: $res" > $trs_file 1489a011757Smrgecho ":global-test-result: $res" >> $trs_file 1499a011757Smrgecho ":recheck: $recheck" >> $trs_file 1509a011757Smrgecho ":copy-in-global-log: $gcopy" >> $trs_file 1519a011757Smrg 1529a011757Smrg# Local Variables: 1539a011757Smrg# mode: shell-script 1549a011757Smrg# sh-indentation: 2 1556c3c2bceSmrg# eval: (add-hook 'before-save-hook 'time-stamp) 1569a011757Smrg# time-stamp-start: "scriptversion=" 1579a011757Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 1586c3c2bceSmrg# time-stamp-time-zone: "UTC0" 1599a011757Smrg# time-stamp-end: "; # UTC" 1609a011757Smrg# End: 161