From 16f3d7677522d3cc9264d96a315cf64453adeeae Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Tue, 31 May 2016 08:23:20 -0700 Subject: [PATCH] tests: don't let any envvar setting perturb tests * testsuite/envvar-check: New file. Identical to the one from grep, but with the addition of sed-specific "COLS". * testsuite/Makefile.am (EXTRA_DIST): Add it here. (TESTS_ENVIRONMENT): New prologue, mostly copied from grep. --- testsuite/Makefile.am | 46 ++++++++++++++++++++++++++++++++---- testsuite/envvar-check | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+), 4 deletions(-) create mode 100644 testsuite/envvar-check diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am index fd4f19e..659fa38 100644 --- a/testsuite/Makefile.am +++ b/testsuite/Makefile.am @@ -51,11 +51,48 @@ SEDTESTS += \ # The rest are envvar settings that propagate build-related Makefile # variables to test scripts. TESTS_ENVIRONMENT = \ - export \ + tmp__=$${TMPDIR-/tmp}; \ + test -d "$$tmp__" && test -w "$$tmp__" || tmp__=.; \ + . $(srcdir)/envvar-check; \ + TMPDIR=$$tmp__; export TMPDIR; \ + \ + if test -n "$$BASH_VERSION" || (eval "export v=x") 2>/dev/null; then \ + export_with_values () { export "$$@"; }; \ + else \ + export_with_values () \ + { \ + sed_extract_var='s/=.*//'; \ + sed_quote_value="s/'/'\\\\''/g;s/=\\(.*\\)/='\\1'/";\ + for arg in "$$@"; do \ + var=`echo "$$arg" | sed "$$sed_extract_var"`; \ + arg=`echo "$$arg" | sed "$$sed_quote_value"`; \ + eval "$$arg"; \ + export "$$var"; \ + done; \ + }; \ + fi; \ + \ + export_with_values \ VERSION='$(VERSION)' \ - MAKE="$(MAKE)" \ - VERSION="$(VERSION)" \ - built_programs=sed \ + LOCALE_FR='$(LOCALE_FR)' \ + LOCALE_FR_UTF8='$(LOCALE_FR_UTF8)' \ + AWK=$(AWK) \ + LC_ALL=C \ + abs_top_builddir='$(abs_top_builddir)' \ + abs_top_srcdir='$(abs_top_srcdir)' \ + abs_srcdir='$(abs_srcdir)' \ + built_programs=sed; \ + srcdir='$(srcdir)' \ + top_srcdir='$(top_srcdir)' \ + CC='$(CC)' \ + SED_TEST_NAME=`echo $$tst|sed 's,^\./,,;s,/,-,g'` \ + MAKE=$(MAKE) \ + MALLOC_PERTURB_=$(MALLOC_PERTURB_) \ + PACKAGE_BUGREPORT='$(PACKAGE_BUGREPORT)' \ + PACKAGE_VERSION=$(PACKAGE_VERSION) \ + PERL='$(PERL)' \ + SHELL='$(SHELL)' \ + PATH='$(abs_top_builddir)/src$(PATH_SEPARATOR)'"$$PATH" \ $(LOCALCHARSET_TESTS_ENVIRONMENT) \ ; 9>&2 @@ -63,6 +100,7 @@ LOG_COMPILER = $(srcdir)/runtest EXTRA_DIST = \ $(T) init.sh init.cfg \ + envvar-check \ PCRE.tests BOOST.tests SPENCER.tests \ runtest Makefile.tests \ 0range.good 0range.inp 0range.sed \ diff --git a/testsuite/envvar-check b/testsuite/envvar-check new file mode 100644 index 0000000..ad672fa --- /dev/null +++ b/testsuite/envvar-check @@ -0,0 +1,64 @@ +# -*- sh -*- +# Check environment variables for sane values while testing. + +# Copyright (C) 2000-2016 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 . + +if (FOO=FOO; unset FOO) >/dev/null 2>&1; then + as_unset=unset +else + as_unset=false +fi + +envvar_check_fail=0 +vars=' + _POSIX2_VERSION + _STDBUF_E + _STDBUF_I + _STDBUF_O + BASH_ENV + BLOCKSIZE + BLOCK_SIZE + CDPATH + COLS + COLUMNS + DF_BLOCK_SIZE + DU_BLOCK_SIZE + ENV + LANGUAGE + LS_BLOCK_SIZE + LS_COLORS + OMP_NUM_THREADS + POSIXLY_CORRECT + QUOTING_STYLE + SIMPLE_BACKUP_SUFFIX + TABSIZE + TERM + COLORTERM + TIME_STYLE + TMPDIR + VERSION_CONTROL +' +for var in $vars +do + $as_unset $var + if eval test \"\${$var+set}\" = set; then + echo "$0: the $var environment variable is set --" \ + ' unset it and rerun this test' >&2 + envvar_check_fail=1 + fi +done + +test "$envvar_check_fail" = 1 && exit 1 -- 2.8.0-rc2