1255365Sdes#! /bin/sh
2255365Sdes# test-driver - basic testsuite driver script.
3255365Sdes
4348980Sdesscriptversion=2016-01-11.22; # UTC
5255365Sdes
6348980Sdes# Copyright (C) 2011-2017 Free Software Foundation, Inc.
7255365Sdes#
8255365Sdes# This program is free software; you can redistribute it and/or modify
9255365Sdes# it under the terms of the GNU General Public License as published by
10255365Sdes# the Free Software Foundation; either version 2, or (at your option)
11255365Sdes# any later version.
12255365Sdes#
13255365Sdes# This program is distributed in the hope that it will be useful,
14255365Sdes# but WITHOUT ANY WARRANTY; without even the implied warranty of
15255365Sdes# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16255365Sdes# GNU General Public License for more details.
17255365Sdes#
18255365Sdes# You should have received a copy of the GNU General Public License
19255365Sdes# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20255365Sdes
21255365Sdes# As a special exception to the GNU General Public License, if you
22255365Sdes# distribute this file as part of a program that contains a
23255365Sdes# configuration script generated by Autoconf, you may include it under
24255365Sdes# the same distribution terms that you use for the rest of that program.
25255365Sdes
26255365Sdes# This file is maintained in Automake, please report
27255365Sdes# bugs to <bug-automake@gnu.org> or send patches to
28255365Sdes# <automake-patches@gnu.org>.
29255365Sdes
30255365Sdes# Make unconditional expansion of undefined variables an error.  This
31255365Sdes# helps a lot in preventing typo-related bugs.
32255365Sdesset -u
33255365Sdes
34255365Sdesusage_error ()
35255365Sdes{
36255365Sdes  echo "$0: $*" >&2
37255365Sdes  print_usage >&2
38255365Sdes  exit 2
39255365Sdes}
40255365Sdes
41255365Sdesprint_usage ()
42255365Sdes{
43255365Sdes  cat <<END
44255365SdesUsage:
45255365Sdes  test-driver --test-name=NAME --log-file=PATH --trs-file=PATH
46255365Sdes              [--expect-failure={yes|no}] [--color-tests={yes|no}]
47348980Sdes              [--enable-hard-errors={yes|no}] [--]
48348980Sdes              TEST-SCRIPT [TEST-SCRIPT-ARGUMENTS]
49255365SdesThe '--test-name', '--log-file' and '--trs-file' options are mandatory.
50255365SdesEND
51255365Sdes}
52255365Sdes
53255365Sdestest_name= # Used for reporting.
54255365Sdeslog_file=  # Where to save the output of the test script.
55255365Sdestrs_file=  # Where to save the metadata of the test run.
56255365Sdesexpect_failure=no
57255365Sdescolor_tests=no
58255365Sdesenable_hard_errors=yes
59255365Sdeswhile test $# -gt 0; do
60255365Sdes  case $1 in
61255365Sdes  --help) print_usage; exit $?;;
62255365Sdes  --version) echo "test-driver $scriptversion"; exit $?;;
63255365Sdes  --test-name) test_name=$2; shift;;
64255365Sdes  --log-file) log_file=$2; shift;;
65255365Sdes  --trs-file) trs_file=$2; shift;;
66255365Sdes  --color-tests) color_tests=$2; shift;;
67255365Sdes  --expect-failure) expect_failure=$2; shift;;
68255365Sdes  --enable-hard-errors) enable_hard_errors=$2; shift;;
69255365Sdes  --) shift; break;;
70255365Sdes  -*) usage_error "invalid option: '$1'";;
71348980Sdes   *) break;;
72255365Sdes  esac
73255365Sdes  shift
74255365Sdesdone
75255365Sdes
76348980Sdesmissing_opts=
77348980Sdestest x"$test_name" = x && missing_opts="$missing_opts --test-name"
78348980Sdestest x"$log_file"  = x && missing_opts="$missing_opts --log-file"
79348980Sdestest x"$trs_file"  = x && missing_opts="$missing_opts --trs-file"
80348980Sdesif test x"$missing_opts" != x; then
81348980Sdes  usage_error "the following mandatory options are missing:$missing_opts"
82348980Sdesfi
83348980Sdes
84348980Sdesif test $# -eq 0; then
85348980Sdes  usage_error "missing argument"
86348980Sdesfi
87348980Sdes
88255365Sdesif test $color_tests = yes; then
89255365Sdes  # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'.
90255365Sdes  red='[0;31m' # Red.
91255365Sdes  grn='[0;32m' # Green.
92255365Sdes  lgn='[1;32m' # Light green.
93255365Sdes  blu='[1;34m' # Blue.
94255365Sdes  mgn='[0;35m' # Magenta.
95255365Sdes  std='[m'     # No color.
96255365Sdeselse
97255365Sdes  red= grn= lgn= blu= mgn= std=
98255365Sdesfi
99255365Sdes
100255365Sdesdo_exit='rm -f $log_file $trs_file; (exit $st); exit $st'
101255365Sdestrap "st=129; $do_exit" 1
102255365Sdestrap "st=130; $do_exit" 2
103255365Sdestrap "st=141; $do_exit" 13
104255365Sdestrap "st=143; $do_exit" 15
105255365Sdes
106255365Sdes# Test script is run here.
107255365Sdes"$@" >$log_file 2>&1
108255365Sdesestatus=$?
109348980Sdes
110255365Sdesif test $enable_hard_errors = no && test $estatus -eq 99; then
111348980Sdes  tweaked_estatus=1
112348980Sdeselse
113348980Sdes  tweaked_estatus=$estatus
114255365Sdesfi
115255365Sdes
116348980Sdescase $tweaked_estatus:$expect_failure in
117255365Sdes  0:yes) col=$red res=XPASS recheck=yes gcopy=yes;;
118255365Sdes  0:*)   col=$grn res=PASS  recheck=no  gcopy=no;;
119255365Sdes  77:*)  col=$blu res=SKIP  recheck=no  gcopy=yes;;
120255365Sdes  99:*)  col=$mgn res=ERROR recheck=yes gcopy=yes;;
121255365Sdes  *:yes) col=$lgn res=XFAIL recheck=no  gcopy=yes;;
122255365Sdes  *:*)   col=$red res=FAIL  recheck=yes gcopy=yes;;
123255365Sdesesac
124255365Sdes
125348980Sdes# Report the test outcome and exit status in the logs, so that one can
126348980Sdes# know whether the test passed or failed simply by looking at the '.log'
127348980Sdes# file, without the need of also peaking into the corresponding '.trs'
128348980Sdes# file (automake bug#11814).
129348980Sdesecho "$res $test_name (exit status: $estatus)" >>$log_file
130348980Sdes
131255365Sdes# Report outcome to console.
132255365Sdesecho "${col}${res}${std}: $test_name"
133255365Sdes
134255365Sdes# Register the test result, and other relevant metadata.
135255365Sdesecho ":test-result: $res" > $trs_file
136255365Sdesecho ":global-test-result: $res" >> $trs_file
137255365Sdesecho ":recheck: $recheck" >> $trs_file
138255365Sdesecho ":copy-in-global-log: $gcopy" >> $trs_file
139255365Sdes
140255365Sdes# Local Variables:
141255365Sdes# mode: shell-script
142255365Sdes# sh-indentation: 2
143255365Sdes# eval: (add-hook 'write-file-hooks 'time-stamp)
144255365Sdes# time-stamp-start: "scriptversion="
145255365Sdes# time-stamp-format: "%:y-%02m-%02d.%02H"
146348980Sdes# time-stamp-time-zone: "UTC0"
147255365Sdes# time-stamp-end: "; # UTC"
148255365Sdes# End:
149