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