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.
This commit is contained in:
Jim Meyering committed 2016-06-01 08:21:05 -07:00
1 parent 156e099817
commit b250bd43ef
2 files changed
+106 -4

No files matched your search

+42 -4
View File
@@ -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 \
+64
View File
@@ -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 <http://www.gnu.org/licenses/>.
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