xref: /potrace-1.14/test-driver (revision 275def9c)
11f13f311SSkyrpex#! /bin/sh
21f13f311SSkyrpex# test-driver - basic testsuite driver script.
31f13f311SSkyrpex
41f13f311SSkyrpexscriptversion=2013-07-13.22; # UTC
51f13f311SSkyrpex
6*275def9cSCristian Pallarés# Copyright (C) 2011-2014 Free Software Foundation, Inc.
71f13f311SSkyrpex#
81f13f311SSkyrpex# This program is free software; you can redistribute it and/or modify
91f13f311SSkyrpex# it under the terms of the GNU General Public License as published by
101f13f311SSkyrpex# the Free Software Foundation; either version 2, or (at your option)
111f13f311SSkyrpex# any later version.
121f13f311SSkyrpex#
131f13f311SSkyrpex# This program is distributed in the hope that it will be useful,
141f13f311SSkyrpex# but WITHOUT ANY WARRANTY; without even the implied warranty of
151f13f311SSkyrpex# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
161f13f311SSkyrpex# GNU General Public License for more details.
171f13f311SSkyrpex#
181f13f311SSkyrpex# You should have received a copy of the GNU General Public License
191f13f311SSkyrpex# along with this program.  If not, see <http://www.gnu.org/licenses/>.
201f13f311SSkyrpex
211f13f311SSkyrpex# As a special exception to the GNU General Public License, if you
221f13f311SSkyrpex# distribute this file as part of a program that contains a
231f13f311SSkyrpex# configuration script generated by Autoconf, you may include it under
241f13f311SSkyrpex# the same distribution terms that you use for the rest of that program.
251f13f311SSkyrpex
261f13f311SSkyrpex# This file is maintained in Automake, please report
271f13f311SSkyrpex# bugs to <[email protected]> or send patches to
281f13f311SSkyrpex# <[email protected]>.
291f13f311SSkyrpex
301f13f311SSkyrpex# Make unconditional expansion of undefined variables an error.  This
311f13f311SSkyrpex# helps a lot in preventing typo-related bugs.
321f13f311SSkyrpexset -u
331f13f311SSkyrpex
341f13f311SSkyrpexusage_error ()
351f13f311SSkyrpex{
361f13f311SSkyrpex  echo "$0: $*" >&2
371f13f311SSkyrpex  print_usage >&2
381f13f311SSkyrpex  exit 2
391f13f311SSkyrpex}
401f13f311SSkyrpex
411f13f311SSkyrpexprint_usage ()
421f13f311SSkyrpex{
431f13f311SSkyrpex  cat <<END
441f13f311SSkyrpexUsage:
451f13f311SSkyrpex  test-driver --test-name=NAME --log-file=PATH --trs-file=PATH
461f13f311SSkyrpex              [--expect-failure={yes|no}] [--color-tests={yes|no}]
471f13f311SSkyrpex              [--enable-hard-errors={yes|no}] [--]
481f13f311SSkyrpex              TEST-SCRIPT [TEST-SCRIPT-ARGUMENTS]
491f13f311SSkyrpexThe '--test-name', '--log-file' and '--trs-file' options are mandatory.
501f13f311SSkyrpexEND
511f13f311SSkyrpex}
521f13f311SSkyrpex
531f13f311SSkyrpextest_name= # Used for reporting.
541f13f311SSkyrpexlog_file=  # Where to save the output of the test script.
551f13f311SSkyrpextrs_file=  # Where to save the metadata of the test run.
561f13f311SSkyrpexexpect_failure=no
571f13f311SSkyrpexcolor_tests=no
581f13f311SSkyrpexenable_hard_errors=yes
591f13f311SSkyrpexwhile test $# -gt 0; do
601f13f311SSkyrpex  case $1 in
611f13f311SSkyrpex  --help) print_usage; exit $?;;
621f13f311SSkyrpex  --version) echo "test-driver $scriptversion"; exit $?;;
631f13f311SSkyrpex  --test-name) test_name=$2; shift;;
641f13f311SSkyrpex  --log-file) log_file=$2; shift;;
651f13f311SSkyrpex  --trs-file) trs_file=$2; shift;;
661f13f311SSkyrpex  --color-tests) color_tests=$2; shift;;
671f13f311SSkyrpex  --expect-failure) expect_failure=$2; shift;;
681f13f311SSkyrpex  --enable-hard-errors) enable_hard_errors=$2; shift;;
691f13f311SSkyrpex  --) shift; break;;
701f13f311SSkyrpex  -*) usage_error "invalid option: '$1'";;
711f13f311SSkyrpex   *) break;;
721f13f311SSkyrpex  esac
731f13f311SSkyrpex  shift
741f13f311SSkyrpexdone
751f13f311SSkyrpex
761f13f311SSkyrpexmissing_opts=
771f13f311SSkyrpextest x"$test_name" = x && missing_opts="$missing_opts --test-name"
781f13f311SSkyrpextest x"$log_file"  = x && missing_opts="$missing_opts --log-file"
791f13f311SSkyrpextest x"$trs_file"  = x && missing_opts="$missing_opts --trs-file"
801f13f311SSkyrpexif test x"$missing_opts" != x; then
811f13f311SSkyrpex  usage_error "the following mandatory options are missing:$missing_opts"
821f13f311SSkyrpexfi
831f13f311SSkyrpex
841f13f311SSkyrpexif test $# -eq 0; then
851f13f311SSkyrpex  usage_error "missing argument"
861f13f311SSkyrpexfi
871f13f311SSkyrpex
881f13f311SSkyrpexif test $color_tests = yes; then
891f13f311SSkyrpex  # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'.
901f13f311SSkyrpex  red='' # Red.
911f13f311SSkyrpex  grn='' # Green.
921f13f311SSkyrpex  lgn='' # Light green.
931f13f311SSkyrpex  blu='' # Blue.
941f13f311SSkyrpex  mgn='' # Magenta.
951f13f311SSkyrpex  std=''     # No color.
961f13f311SSkyrpexelse
971f13f311SSkyrpex  red= grn= lgn= blu= mgn= std=
981f13f311SSkyrpexfi
991f13f311SSkyrpex
1001f13f311SSkyrpexdo_exit='rm -f $log_file $trs_file; (exit $st); exit $st'
1011f13f311SSkyrpextrap "st=129; $do_exit" 1
1021f13f311SSkyrpextrap "st=130; $do_exit" 2
1031f13f311SSkyrpextrap "st=141; $do_exit" 13
1041f13f311SSkyrpextrap "st=143; $do_exit" 15
1051f13f311SSkyrpex
1061f13f311SSkyrpex# Test script is run here.
1071f13f311SSkyrpex"$@" >$log_file 2>&1
1081f13f311SSkyrpexestatus=$?
109*275def9cSCristian Pallarés
1101f13f311SSkyrpexif test $enable_hard_errors = no && test $estatus -eq 99; then
111*275def9cSCristian Pallarés  tweaked_estatus=1
112*275def9cSCristian Pallaréselse
113*275def9cSCristian Pallarés  tweaked_estatus=$estatus
1141f13f311SSkyrpexfi
1151f13f311SSkyrpex
116*275def9cSCristian Pallaréscase $tweaked_estatus:$expect_failure in
1171f13f311SSkyrpex  0:yes) col=$red res=XPASS recheck=yes gcopy=yes;;
1181f13f311SSkyrpex  0:*)   col=$grn res=PASS  recheck=no  gcopy=no;;
1191f13f311SSkyrpex  77:*)  col=$blu res=SKIP  recheck=no  gcopy=yes;;
1201f13f311SSkyrpex  99:*)  col=$mgn res=ERROR recheck=yes gcopy=yes;;
1211f13f311SSkyrpex  *:yes) col=$lgn res=XFAIL recheck=no  gcopy=yes;;
1221f13f311SSkyrpex  *:*)   col=$red res=FAIL  recheck=yes gcopy=yes;;
1231f13f311SSkyrpexesac
1241f13f311SSkyrpex
125*275def9cSCristian Pallarés# Report the test outcome and exit status in the logs, so that one can
126*275def9cSCristian Pallarés# know whether the test passed or failed simply by looking at the '.log'
127*275def9cSCristian Pallarés# file, without the need of also peaking into the corresponding '.trs'
128*275def9cSCristian Pallarés# file (automake bug#11814).
129*275def9cSCristian Pallarésecho "$res $test_name (exit status: $estatus)" >>$log_file
130*275def9cSCristian Pallarés
1311f13f311SSkyrpex# Report outcome to console.
1321f13f311SSkyrpexecho "${col}${res}${std}: $test_name"
1331f13f311SSkyrpex
1341f13f311SSkyrpex# Register the test result, and other relevant metadata.
1351f13f311SSkyrpexecho ":test-result: $res" > $trs_file
1361f13f311SSkyrpexecho ":global-test-result: $res" >> $trs_file
1371f13f311SSkyrpexecho ":recheck: $recheck" >> $trs_file
1381f13f311SSkyrpexecho ":copy-in-global-log: $gcopy" >> $trs_file
1391f13f311SSkyrpex
1401f13f311SSkyrpex# Local Variables:
1411f13f311SSkyrpex# mode: shell-script
1421f13f311SSkyrpex# sh-indentation: 2
1431f13f311SSkyrpex# eval: (add-hook 'write-file-hooks 'time-stamp)
1441f13f311SSkyrpex# time-stamp-start: "scriptversion="
1451f13f311SSkyrpex# time-stamp-format: "%:y-%02m-%02d.%02H"
1461f13f311SSkyrpex# time-stamp-time-zone: "UTC"
1471f13f311SSkyrpex# time-stamp-end: "; # UTC"
1481f13f311SSkyrpex# End:
149