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