| 1 | #! /bin/sh |
| 2 | # test-driver - basic testsuite driver script. |
| 3 | |
| 4 | scriptversion=2025-06-18.21; # UTC |
| 5 | |
| 6 | # Copyright (C) 2011-2025 Free Software Foundation, Inc. |
| 7 | # |
| 8 | # This program is free software; you can redistribute it and/or modify |
| 9 | # it under the terms of the GNU General Public License as published by |
| 10 | # the Free Software Foundation; either version 2, or (at your option) |
| 11 | # any later version. |
| 12 | # |
| 13 | # This program is distributed in the hope that it will be useful, |
| 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | # GNU General Public License for more details. |
| 17 | # |
| 18 | # You should have received a copy of the GNU General Public License |
| 19 | # along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 20 | |
| 21 | # As a special exception to the GNU General Public License, if you |
| 22 | # distribute this file as part of a program that contains a |
| 23 | # configuration script generated by Autoconf, you may include it under |
| 24 | # the same distribution terms that you use for the rest of that program. |
| 25 | |
| 26 | # This file is maintained in Automake, please report |
| 27 | # bugs to <[email protected]> or send patches to |
| 28 | # <[email protected]>. |
| 29 | |
| 30 | # Make unconditional expansion of undefined variables an error. This |
| 31 | # helps a lot in preventing typo-related bugs. |
| 32 | set -u |
| 33 | |
| 34 | usage_error () |
| 35 | { |
| 36 | echo "$0: $*" >&2 |
| 37 | print_usage >&2 |
| 38 | exit 2 |
| 39 | } |
| 40 | |
| 41 | print_usage () |
| 42 | { |
| 43 | cat <<END |
| 44 | Usage: |
| 45 | test-driver --test-name NAME --log-file PATH --trs-file PATH |
| 46 | [--expect-failure {yes|no}] [--color-tests {yes|no}] |
| 47 | [--collect-skipped-logs {yes|no}] |
| 48 | [--enable-hard-errors {yes|no}] [--] |
| 49 | TEST-SCRIPT [TEST-SCRIPT-ARGUMENTS] |
| 50 | |
| 51 | The '--test-name', '--log-file' and '--trs-file' options are mandatory. |
| 52 | See the GNU Automake documentation for information. |
| 53 | |
| 54 | Report bugs to <[email protected]>. |
| 55 | GNU Automake home page: <https://www.gnu.org/software/automake/>. |
| 56 | General help using GNU software: <https://www.gnu.org/gethelp/>. |
| 57 | END |
| 58 | } |
| 59 | |
| 60 | test_name= # Used for reporting. |
| 61 | log_file= # Where to save the output of the test script. |
| 62 | trs_file= # Where to save the metadata of the test run. |
| 63 | expect_failure=no |
| 64 | color_tests=no |
| 65 | collect_skipped_logs=yes |
| 66 | enable_hard_errors=yes |
| 67 | while test $# -gt 0; do |
| 68 | case $1 in |
| 69 | --help) print_usage; exit $?;; |
| 70 | --version) echo "test-driver (GNU Automake) $scriptversion"; exit $?;; |
| 71 | --test-name) test_name=$2; shift;; |
| 72 | --log-file) log_file=$2; shift;; |
| 73 | --trs-file) trs_file=$2; shift;; |
| 74 | --color-tests) color_tests=$2; shift;; |
| 75 | --collect-skipped-logs) collect_skipped_logs=$2; shift;; |
| 76 | --expect-failure) expect_failure=$2; shift;; |
| 77 | --enable-hard-errors) enable_hard_errors=$2; shift;; |
| 78 | --) shift; break;; |
| 79 | -*) usage_error "invalid option: '$1'";; |
| 80 | *) break;; |
| 81 | esac |
| 82 | shift |
| 83 | done |
| 84 | |
| 85 | missing_opts= |
| 86 | test x"$test_name" = x && missing_opts="$missing_opts --test-name" |
| 87 | test x"$log_file" = x && missing_opts="$missing_opts --log-file" |
| 88 | test x"$trs_file" = x && missing_opts="$missing_opts --trs-file" |
| 89 | if test x"$missing_opts" != x; then |
| 90 | usage_error "the following mandatory options are missing:$missing_opts" |
| 91 | fi |
| 92 | |
| 93 | if test $# -eq 0; then |
| 94 | usage_error "missing argument" |
| 95 | fi |
| 96 | |
| 97 | if test $color_tests = yes; then |
| 98 | # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'. |
| 99 | red='[0;31m' # Red. |
| 100 | grn='[0;32m' # Green. |
| 101 | lgn='[1;32m' # Light green. |
| 102 | blu='[1;34m' # Blue. |
| 103 | mgn='[0;35m' # Magenta. |
| 104 | std='[m' # No color. |
| 105 | else |
| 106 | red= grn= lgn= blu= mgn= std= |
| 107 | fi |
| 108 | |
| 109 | do_exit='rm -f $log_file $trs_file; (exit $st); exit $st' |
| 110 | trap "st=129; $do_exit" 1 |
| 111 | trap "st=130; $do_exit" 2 |
| 112 | trap "st=141; $do_exit" 13 |
| 113 | trap "st=143; $do_exit" 15 |
| 114 | |
| 115 | # Test script is run here. We create the file first, then append to it, |
| 116 | # to ameliorate tests themselves also writing to the log file. Our tests |
| 117 | # don't, but others can (automake bug#35762). |
| 118 | : >"$log_file" |
| 119 | "$@" >>"$log_file" 2>&1 |
| 120 | estatus=$? |
| 121 | |
| 122 | if test $enable_hard_errors = no && test $estatus -eq 99; then |
| 123 | tweaked_estatus=1 |
| 124 | else |
| 125 | tweaked_estatus=$estatus |
| 126 | fi |
| 127 | |
| 128 | case $tweaked_estatus:$expect_failure in |
| 129 | 0:yes) col=$red res=XPASS recheck=yes gcopy=yes;; |
| 130 | 0:*) col=$grn res=PASS recheck=no gcopy=no;; |
| 131 | 77:*) col=$blu res=SKIP recheck=no gcopy=$collect_skipped_logs;; |
| 132 | 99:*) col=$mgn res=ERROR recheck=yes gcopy=yes;; |
| 133 | *:yes) col=$lgn res=XFAIL recheck=no gcopy=yes;; |
| 134 | *:*) col=$red res=FAIL recheck=yes gcopy=yes;; |
| 135 | esac |
| 136 | |
| 137 | # Report the test outcome and exit status in the logs, so that one can |
| 138 | # know whether the test passed or failed simply by looking at the '.log' |
| 139 | # file, without the need of also peaking into the corresponding '.trs' |
| 140 | # file (automake bug#11814). |
| 141 | echo "$res $test_name (exit status: $estatus)" >>"$log_file" |
| 142 | |
| 143 | # Report outcome to console. |
| 144 | echo "${col}${res}${std}: $test_name" |
| 145 | |
| 146 | # Register the test result, and other relevant metadata. |
| 147 | echo ":test-result: $res" > $trs_file |
| 148 | echo ":global-test-result: $res" >> $trs_file |
| 149 | echo ":recheck: $recheck" >> $trs_file |
| 150 | echo ":copy-in-global-log: $gcopy" >> $trs_file |
| 151 | |
| 152 | # Local Variables: |
| 153 | # mode: shell-script |
| 154 | # sh-indentation: 2 |
| 155 | # eval: (add-hook 'before-save-hook 'time-stamp nil t) |
| 156 | # time-stamp-start: "scriptversion=" |
| 157 | # time-stamp-format: "%Y-%02m-%02d.%02H" |
| 158 | # time-stamp-time-zone: "UTC0" |
| 159 | # time-stamp-end: "; # UTC" |
| 160 | # End: |