diff options
author | Jim Meyering <meyering@redhat.com> | 2012-01-28 19:01:54 +0100 |
---|---|---|
committer | Jim Meyering <meyering@redhat.com> | 2012-01-31 13:22:05 +0100 |
commit | 1b25cbe7586c06528e7431ff7cfbaf0db43e4840 (patch) | |
tree | f80031e8d7abdb1cab521b051422bd5d3a83716d | |
parent | c7f6c1e1594e0777f99543d5d575092cb491dd21 (diff) | |
download | idutils-1b25cbe7586c06528e7431ff7cfbaf0db43e4840.tar.gz idutils-1b25cbe7586c06528e7431ff7cfbaf0db43e4840.tar.bz2 idutils-1b25cbe7586c06528e7431ff7cfbaf0db43e4840.zip |
tests: adapt framework for upcoming automake-1.12
* testsuite/check.mk (LOG_COMPILER): Define.
(TESTS_ENVIRONMENT): Adapt to work with the upcoming automake-1.12;
use "; 9>&2" at end. Move shell-or-perl to ...
* testsuite/shell-or-perl: ... new helper script from coreutils.
* testsuite/CuSkip.pm: New file, from coreutils.
* testsuite/Makefile.am (EXTRA_DIST): Add CuSkip.pm and shell-or-perl.
-rw-r--r-- | testsuite/CuSkip.pm | 39 | ||||
-rw-r--r-- | testsuite/Makefile.am | 2 | ||||
-rw-r--r-- | testsuite/check.mk | 27 | ||||
-rw-r--r-- | testsuite/shell-or-perl | 121 |
4 files changed, 173 insertions, 16 deletions
diff --git a/testsuite/CuSkip.pm b/testsuite/CuSkip.pm new file mode 100644 index 0000000..0ae15ce --- /dev/null +++ b/testsuite/CuSkip.pm @@ -0,0 +1,39 @@ +package CuSkip; +# Skip a test: emit diag to log and to stderr, and exit 77 + +# Copyright (C) 2011-2012 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +use strict; +use warnings; + +our $ME = $0 || "<???>"; + +# Emit a diagnostic both to stderr and to $stderr_fileno_. +# FIXME: don't hard-code that value (9), since it's already defined in init.cfg. +sub skip ($) +{ + my ($msg) = @_; + my $stderr_fileno_ = 9; + warn $msg; + open FH, ">&$stderr_fileno_" + or warn "$ME: failed to dup stderr\n"; + print FH $msg; + close FH + or warn "$ME: failed to close FD $stderr_fileno_\n"; + exit 77; +} + +1; diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am index dfa3477..ae1c4e7 100644 --- a/testsuite/Makefile.am +++ b/testsuite/Makefile.am @@ -11,11 +11,13 @@ TESTS = \ EXTRA_DIST = \ $(TESTS) \ Coreutils.pm \ + CuSkip.pm \ CuTmpdir.pm \ check.mk \ envvar-check \ init.sh \ mkid-langopt \ + shell-or-perl \ single_file_token_bug.c DISTCLEANFILES = ID diff --git a/testsuite/check.mk b/testsuite/check.mk index 42aadc3..18226d7 100644 --- a/testsuite/check.mk +++ b/testsuite/check.mk @@ -19,6 +19,16 @@ built_programs = \ | MAKEFLAGS= $(MAKE) -s -C $(top_builddir)/src -f Makefile -f - spy \ | tr -s ' ' '\n' | sed -e 's,$(EXEEXT)$$,,' +## '$f' is set by the Automake-generated test harness to the path of the +## current test script stripped of VPATH components, and is used by the +## shell-or-perl script to determine the name of the temporary files to be +## used. Note that $f is a shell variable, not a make macro, so the use of +## '$$f' below is correct, and not a typo. +LOG_COMPILER = \ + $(SHELL) $(srcdir)/shell-or-perl \ + --test-name "$$f" --srcdir '$(srcdir)' \ + --shell '$(SHELL)' --perl '$(PERL)' -- + # Note that the first lines are statements. They ensure that environment # variables that can perturb tests are unset or set to expected values. # The rest are envvar settings that propagate build-related Makefile @@ -27,21 +37,6 @@ TESTS_ENVIRONMENT = \ tmp__=$$TMPDIR; test -d "$$tmp__" || tmp__=.; \ . $(srcdir)/envvar-check; \ TMPDIR=$$tmp__; export TMPDIR; \ - shell_or_perl_() { \ - if grep '^\#!/usr/bin/perl' "$$1" > /dev/null; then \ - if $(PERL) -e 'use warnings' > /dev/null 2>&1; then \ - grep '^\#!/usr/bin/perl -T' "$$1" > /dev/null && T_=T || T_=; \ - $(PERL) -w$$T_ -I$(srcdir) -MCoreutils \ - -M"CuTmpdir qw($$f)" -- "$$1"; \ - else \ - echo 1>&2 "$$f: configure did not find a usable version of Perl," \ - "so skipping this test"; \ - (exit 77); \ - fi; \ - else \ - $(SHELL) "$$1"; \ - fi; \ - }; \ export \ LOCALE_FR='$(LOCALE_FR)' \ LOCALE_FR_UTF8='$(LOCALE_FR_UTF8)' \ @@ -66,7 +61,7 @@ TESTS_ENVIRONMENT = \ REPLACE_GETCWD=$(REPLACE_GETCWD) \ PATH="$(abs_top_builddir)/src$(PATH_SEPARATOR)$(abs_top_srcdir)/src$(PATH_SEPARATOR)$$PATH" \ VERSION=$(VERSION) \ - ; shell_or_perl_ + ; 9>&2 TEST_LOGS = $(TESTS:=.log) diff --git a/testsuite/shell-or-perl b/testsuite/shell-or-perl new file mode 100644 index 0000000..58c80e3 --- /dev/null +++ b/testsuite/shell-or-perl @@ -0,0 +1,121 @@ +#! /bin/sh +# Run a test script of the coreutils test scripts, picking up the right +# interpreter (i.e., perl or the shell) and the right flags for it (e.g., +# perl '-T' flag for perl scripts that must run in tainted mode). +# +# Copyright (C) 2011-2012 Free Software Foundation, Inc. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +# ---------------------------------- # +# Readonly variables and functions # +# ---------------------------------- # + +# Help to avoid typo-related bugs. +set -u + +me=shell-or-perl + +fatal_ () +{ + echo "$me: $*" >&2 + # Exit with status '99' to inform the testsuite harness that an + # hard error occurred. + exit 99 +} + +print_help_ () +{ + cat <<EOH +Usage: $me [--help] [--srcdir DIR] [--shell SHELL-CMD] [--perl PERL-CMD] + [--test-name NAME-WITHOUT-VPATH] TEST-SCRIPT [ARGS..] +EOH +} + +# ---------------- # +# Option parsing # +# ---------------- # + +assign_optarg_to_var=' + test $# -gt 1 || fatal_ "option '\''$1'\'' requires an argument" + eval "$var=\$2" + shift' + +srcdir=${srcdir-.} +cu_PERL=${PERL-perl} +cu_SHELL=/bin/sh # Getting $SHELL from the environment is dangerous. +test_name= +while test $# -gt 0; do + var= + case $1 in + --help) print_help_; exit $?;; + --shell) var=cu_SHELL;; + --perl) var=cu_PERL;; + --srcdir) var=srcdir;; + --test-name) var=test_name;; + --) shift; break;; + -*) fatal_ "unknown option '$1'";; + *) break;; + esac + test -z "$var" || eval "$assign_optarg_to_var" + shift +done + +unset assign_optarg_to_var var + +case $# in + 0) fatal_ "missing argument";; + *) test_script=$1; shift;; +esac + +test -z "$test_name" && test_name=$test_script + +# --------------------- # +# Run the test script # +# --------------------- # + +test -f "$test_script" && test -r "$test_script" \ + || fatal_ "test script '$test_script' does not exist, or isn't readable" + +read shebang_line < "$test_script" \ + || fatal_ "cannot read from the test script '$test_script'" + +case $shebang_line in +'#!/usr/bin/perl'*) + # The test is a perl script. + if $cu_PERL -e 'use warnings' > /dev/null 2>&1; then + # Perl is available, see if we must run the test with taint + # mode on or not. + case $shebang_line in *\ -T*) T_=T;; *) T_=;; esac + # Now run it. + exec $cu_PERL -w$T_ -I"$srcdir" -MCoreutils -MCuSkip \ + -M"CuTmpdir qw($test_name)" \ + -- "$test_script" ${1+"$@"} + else + # Perl is not available, skip the test. + echo "$test_name: skip: no usable version of Perl found" + exit 77 + fi + ;; +*) + # Assume the test is a shell script. + exec $cu_SHELL "$test_script" ${1+"$@"} +esac + +# ------------- # +# Not reached # +# ------------- # + +fatal_ "dead code reached" |