test-driver revision 6fc018e4
1c9710b42Smrg#! /bin/sh
26fc018e4Smrg# test-driver - basic testsuite driver script.
3c9710b42Smrg
4c9710b42Smrgscriptversion=2012-06-27.10; # UTC
5c9710b42Smrg
66fc018e4Smrg# Copyright (C) 2011-2013 Free Software Foundation, Inc.
7c9710b42Smrg#
8c9710b42Smrg# This program is free software; you can redistribute it and/or modify
9c9710b42Smrg# it under the terms of the GNU General Public License as published by
10c9710b42Smrg# the Free Software Foundation; either version 2, or (at your option)
11c9710b42Smrg# any later version.
12c9710b42Smrg#
13c9710b42Smrg# This program is distributed in the hope that it will be useful,
14c9710b42Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
15c9710b42Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16c9710b42Smrg# GNU General Public License for more details.
17c9710b42Smrg#
18c9710b42Smrg# You should have received a copy of the GNU General Public License
19c9710b42Smrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20c9710b42Smrg
21c9710b42Smrg# As a special exception to the GNU General Public License, if you
22c9710b42Smrg# distribute this file as part of a program that contains a
23c9710b42Smrg# configuration script generated by Autoconf, you may include it under
24c9710b42Smrg# the same distribution terms that you use for the rest of that program.
25c9710b42Smrg
26c9710b42Smrg# This file is maintained in Automake, please report
27c9710b42Smrg# bugs to <bug-automake@gnu.org> or send patches to
28c9710b42Smrg# <automake-patches@gnu.org>.
29c9710b42Smrg
30c9710b42Smrg# Make unconditional expansion of undefined variables an error.  This
31c9710b42Smrg# helps a lot in preventing typo-related bugs.
32c9710b42Smrgset -u
33c9710b42Smrg
34c9710b42Smrgusage_error ()
35c9710b42Smrg{
36c9710b42Smrg  echo "$0: $*" >&2
37c9710b42Smrg  print_usage >&2
38c9710b42Smrg  exit 2
39c9710b42Smrg}
40c9710b42Smrg
41c9710b42Smrgprint_usage ()
42c9710b42Smrg{
43c9710b42Smrg  cat <<END
44c9710b42SmrgUsage:
45c9710b42Smrg  test-driver --test-name=NAME --log-file=PATH --trs-file=PATH
46c9710b42Smrg              [--expect-failure={yes|no}] [--color-tests={yes|no}]
47c9710b42Smrg              [--enable-hard-errors={yes|no}] [--] TEST-SCRIPT
48c9710b42SmrgThe '--test-name', '--log-file' and '--trs-file' options are mandatory.
49c9710b42SmrgEND
50c9710b42Smrg}
51c9710b42Smrg
52c9710b42Smrg# TODO: better error handling in option parsing (in particular, ensure
53c9710b42Smrg# TODO: $log_file, $trs_file and $test_name are defined).
54c9710b42Smrgtest_name= # Used for reporting.
55c9710b42Smrglog_file=  # Where to save the output of the test script.
56c9710b42Smrgtrs_file=  # Where to save the metadata of the test run.
57c9710b42Smrgexpect_failure=no
58c9710b42Smrgcolor_tests=no
59c9710b42Smrgenable_hard_errors=yes
60c9710b42Smrgwhile test $# -gt 0; do
61c9710b42Smrg  case $1 in
62c9710b42Smrg  --help) print_usage; exit $?;;
63c9710b42Smrg  --version) echo "test-driver $scriptversion"; exit $?;;
64c9710b42Smrg  --test-name) test_name=$2; shift;;
65c9710b42Smrg  --log-file) log_file=$2; shift;;
66c9710b42Smrg  --trs-file) trs_file=$2; shift;;
67c9710b42Smrg  --color-tests) color_tests=$2; shift;;
68c9710b42Smrg  --expect-failure) expect_failure=$2; shift;;
69c9710b42Smrg  --enable-hard-errors) enable_hard_errors=$2; shift;;
70c9710b42Smrg  --) shift; break;;
71c9710b42Smrg  -*) usage_error "invalid option: '$1'";;
72c9710b42Smrg  esac
73c9710b42Smrg  shift
74c9710b42Smrgdone
75c9710b42Smrg
76c9710b42Smrgif test $color_tests = yes; then
77c9710b42Smrg  # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'.
78c9710b42Smrg  red='[0;31m' # Red.
79c9710b42Smrg  grn='[0;32m' # Green.
80c9710b42Smrg  lgn='[1;32m' # Light green.
81c9710b42Smrg  blu='[1;34m' # Blue.
82c9710b42Smrg  mgn='[0;35m' # Magenta.
83c9710b42Smrg  std='[m'     # No color.
84c9710b42Smrgelse
85c9710b42Smrg  red= grn= lgn= blu= mgn= std=
86c9710b42Smrgfi
87c9710b42Smrg
88c9710b42Smrgdo_exit='rm -f $log_file $trs_file; (exit $st); exit $st'
89c9710b42Smrgtrap "st=129; $do_exit" 1
90c9710b42Smrgtrap "st=130; $do_exit" 2
91c9710b42Smrgtrap "st=141; $do_exit" 13
92c9710b42Smrgtrap "st=143; $do_exit" 15
93c9710b42Smrg
94c9710b42Smrg# Test script is run here.
95c9710b42Smrg"$@" >$log_file 2>&1
96c9710b42Smrgestatus=$?
97c9710b42Smrgif test $enable_hard_errors = no && test $estatus -eq 99; then
98c9710b42Smrg  estatus=1
99c9710b42Smrgfi
100c9710b42Smrg
101c9710b42Smrgcase $estatus:$expect_failure in
102c9710b42Smrg  0:yes) col=$red res=XPASS recheck=yes gcopy=yes;;
103c9710b42Smrg  0:*)   col=$grn res=PASS  recheck=no  gcopy=no;;
104c9710b42Smrg  77:*)  col=$blu res=SKIP  recheck=no  gcopy=yes;;
105c9710b42Smrg  99:*)  col=$mgn res=ERROR recheck=yes gcopy=yes;;
106c9710b42Smrg  *:yes) col=$lgn res=XFAIL recheck=no  gcopy=yes;;
107c9710b42Smrg  *:*)   col=$red res=FAIL  recheck=yes gcopy=yes;;
108c9710b42Smrgesac
109c9710b42Smrg
110c9710b42Smrg# Report outcome to console.
111c9710b42Smrgecho "${col}${res}${std}: $test_name"
112c9710b42Smrg
113c9710b42Smrg# Register the test result, and other relevant metadata.
114c9710b42Smrgecho ":test-result: $res" > $trs_file
115c9710b42Smrgecho ":global-test-result: $res" >> $trs_file
116c9710b42Smrgecho ":recheck: $recheck" >> $trs_file
117c9710b42Smrgecho ":copy-in-global-log: $gcopy" >> $trs_file
118c9710b42Smrg
119c9710b42Smrg# Local Variables:
120c9710b42Smrg# mode: shell-script
121c9710b42Smrg# sh-indentation: 2
122c9710b42Smrg# eval: (add-hook 'write-file-hooks 'time-stamp)
123c9710b42Smrg# time-stamp-start: "scriptversion="
124c9710b42Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
125c9710b42Smrg# time-stamp-time-zone: "UTC"
126c9710b42Smrg# time-stamp-end: "; # UTC"
127c9710b42Smrg# End:
128