1290001Sglebius#! /bin/sh
2290001Sglebius# test-driver - basic testsuite driver script.
3290001Sglebius
4290001Sglebiusscriptversion=2013-07-13.22; # UTC
5290001Sglebius
6290001Sglebius# Copyright (C) 2011-2014 Free Software Foundation, Inc.
7290001Sglebius#
8290001Sglebius# This program is free software; you can redistribute it and/or modify
9290001Sglebius# it under the terms of the GNU General Public License as published by
10290001Sglebius# the Free Software Foundation; either version 2, or (at your option)
11290001Sglebius# any later version.
12290001Sglebius#
13290001Sglebius# This program is distributed in the hope that it will be useful,
14290001Sglebius# but WITHOUT ANY WARRANTY; without even the implied warranty of
15290001Sglebius# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16290001Sglebius# GNU General Public License for more details.
17290001Sglebius#
18290001Sglebius# You should have received a copy of the GNU General Public License
19290001Sglebius# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20290001Sglebius
21290001Sglebius# As a special exception to the GNU General Public License, if you
22290001Sglebius# distribute this file as part of a program that contains a
23290001Sglebius# configuration script generated by Autoconf, you may include it under
24290001Sglebius# the same distribution terms that you use for the rest of that program.
25290001Sglebius
26290001Sglebius# This file is maintained in Automake, please report
27290001Sglebius# bugs to <bug-automake@gnu.org> or send patches to
28290001Sglebius# <automake-patches@gnu.org>.
29290001Sglebius
30290001Sglebius# Make unconditional expansion of undefined variables an error.  This
31290001Sglebius# helps a lot in preventing typo-related bugs.
32290001Sglebiusset -u
33290001Sglebius
34290001Sglebiususage_error ()
35290001Sglebius{
36290001Sglebius  echo "$0: $*" >&2
37290001Sglebius  print_usage >&2
38290001Sglebius  exit 2
39290001Sglebius}
40290001Sglebius
41290001Sglebiusprint_usage ()
42290001Sglebius{
43290001Sglebius  cat <<END
44290001SglebiusUsage:
45290001Sglebius  test-driver --test-name=NAME --log-file=PATH --trs-file=PATH
46290001Sglebius              [--expect-failure={yes|no}] [--color-tests={yes|no}]
47290001Sglebius              [--enable-hard-errors={yes|no}] [--]
48290001Sglebius              TEST-SCRIPT [TEST-SCRIPT-ARGUMENTS]
49290001SglebiusThe '--test-name', '--log-file' and '--trs-file' options are mandatory.
50290001SglebiusEND
51290001Sglebius}
52290001Sglebius
53290001Sglebiustest_name= # Used for reporting.
54290001Sglebiuslog_file=  # Where to save the output of the test script.
55290001Sglebiustrs_file=  # Where to save the metadata of the test run.
56290001Sglebiusexpect_failure=no
57290001Sglebiuscolor_tests=no
58290001Sglebiusenable_hard_errors=yes
59290001Sglebiuswhile test $# -gt 0; do
60290001Sglebius  case $1 in
61290001Sglebius  --help) print_usage; exit $?;;
62290001Sglebius  --version) echo "test-driver $scriptversion"; exit $?;;
63290001Sglebius  --test-name) test_name=$2; shift;;
64290001Sglebius  --log-file) log_file=$2; shift;;
65290001Sglebius  --trs-file) trs_file=$2; shift;;
66290001Sglebius  --color-tests) color_tests=$2; shift;;
67290001Sglebius  --expect-failure) expect_failure=$2; shift;;
68290001Sglebius  --enable-hard-errors) enable_hard_errors=$2; shift;;
69290001Sglebius  --) shift; break;;
70290001Sglebius  -*) usage_error "invalid option: '$1'";;
71290001Sglebius   *) break;;
72290001Sglebius  esac
73290001Sglebius  shift
74290001Sglebiusdone
75290001Sglebius
76290001Sglebiusmissing_opts=
77290001Sglebiustest x"$test_name" = x && missing_opts="$missing_opts --test-name"
78290001Sglebiustest x"$log_file"  = x && missing_opts="$missing_opts --log-file"
79290001Sglebiustest x"$trs_file"  = x && missing_opts="$missing_opts --trs-file"
80290001Sglebiusif test x"$missing_opts" != x; then
81290001Sglebius  usage_error "the following mandatory options are missing:$missing_opts"
82290001Sglebiusfi
83290001Sglebius
84290001Sglebiusif test $# -eq 0; then
85290001Sglebius  usage_error "missing argument"
86290001Sglebiusfi
87290001Sglebius
88290001Sglebiusif test $color_tests = yes; then
89290001Sglebius  # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'.
90290001Sglebius  red='[0;31m' # Red.
91290001Sglebius  grn='[0;32m' # Green.
92290001Sglebius  lgn='[1;32m' # Light green.
93290001Sglebius  blu='[1;34m' # Blue.
94290001Sglebius  mgn='[0;35m' # Magenta.
95290001Sglebius  std='[m'     # No color.
96290001Sglebiuselse
97290001Sglebius  red= grn= lgn= blu= mgn= std=
98290001Sglebiusfi
99290001Sglebius
100290001Sglebiusdo_exit='rm -f $log_file $trs_file; (exit $st); exit $st'
101290001Sglebiustrap "st=129; $do_exit" 1
102290001Sglebiustrap "st=130; $do_exit" 2
103290001Sglebiustrap "st=141; $do_exit" 13
104290001Sglebiustrap "st=143; $do_exit" 15
105290001Sglebius
106290001Sglebius# Test script is run here.
107290001Sglebius"$@" >$log_file 2>&1
108290001Sglebiusestatus=$?
109290001Sglebius
110290001Sglebiusif test $enable_hard_errors = no && test $estatus -eq 99; then
111290001Sglebius  tweaked_estatus=1
112290001Sglebiuselse
113290001Sglebius  tweaked_estatus=$estatus
114290001Sglebiusfi
115290001Sglebius
116290001Sglebiuscase $tweaked_estatus:$expect_failure in
117290001Sglebius  0:yes) col=$red res=XPASS recheck=yes gcopy=yes;;
118290001Sglebius  0:*)   col=$grn res=PASS  recheck=no  gcopy=no;;
119290001Sglebius  77:*)  col=$blu res=SKIP  recheck=no  gcopy=yes;;
120290001Sglebius  99:*)  col=$mgn res=ERROR recheck=yes gcopy=yes;;
121290001Sglebius  *:yes) col=$lgn res=XFAIL recheck=no  gcopy=yes;;
122290001Sglebius  *:*)   col=$red res=FAIL  recheck=yes gcopy=yes;;
123290001Sglebiusesac
124290001Sglebius
125290001Sglebius# Report the test outcome and exit status in the logs, so that one can
126290001Sglebius# know whether the test passed or failed simply by looking at the '.log'
127290001Sglebius# file, without the need of also peaking into the corresponding '.trs'
128290001Sglebius# file (automake bug#11814).
129290001Sglebiusecho "$res $test_name (exit status: $estatus)" >>$log_file
130290001Sglebius
131290001Sglebius# Report outcome to console.
132290001Sglebiusecho "${col}${res}${std}: $test_name"
133290001Sglebius
134290001Sglebius# Register the test result, and other relevant metadata.
135290001Sglebiusecho ":test-result: $res" > $trs_file
136290001Sglebiusecho ":global-test-result: $res" >> $trs_file
137290001Sglebiusecho ":recheck: $recheck" >> $trs_file
138290001Sglebiusecho ":copy-in-global-log: $gcopy" >> $trs_file
139290001Sglebius
140290001Sglebius# Local Variables:
141290001Sglebius# mode: shell-script
142290001Sglebius# sh-indentation: 2
143290001Sglebius# eval: (add-hook 'write-file-hooks 'time-stamp)
144290001Sglebius# time-stamp-start: "scriptversion="
145290001Sglebius# time-stamp-format: "%:y-%02m-%02d.%02H"
146290001Sglebius# time-stamp-time-zone: "UTC"
147290001Sglebius# time-stamp-end: "; # UTC"
148290001Sglebius# End:
149