Skip to content

Commit 7792d32

Browse files
pks-tgitster
authored andcommitted
t: refactor environment sanitization to not use Perl
Before executing tests we first sanitize the environment. Part of the sanitization is to unset a couple of environment variables that we know will change the behaviour of Git. This is done with a small Perl script, which has the consequence that having a Perl interpreter available is a strict requirement for running our unit tests. The logic itself isn't particularly involved: we simply unset every environment variable whose key starts with 'GIT_', but then explicitly allow a subset of these. Refactor the logic to instead use sed(1) so that it becomes possible to execute our tests without Perl. Based-on-patch-by: Johannes Schindelin <[email protected]> Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8afecde commit 7792d32

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

t/test-lib.sh

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -499,24 +499,20 @@ EDITOR=:
499499
# /usr/xpg4/bin/sh and /bin/ksh to bail out. So keep the unsets
500500
# deriving from the command substitution clustered with the other
501501
# ones.
502-
unset VISUAL EMAIL LANGUAGE $("$PERL_PATH" -e '
503-
my @env = keys %ENV;
504-
my $ok = join("|", qw(
505-
TRACE
506-
DEBUG
507-
TEST
508-
.*_TEST
509-
PROVE
510-
VALGRIND
511-
UNZIP
512-
PERF_
513-
CURL_VERBOSE
514-
TRACE_CURL
515-
BUILD_DIR
516-
));
517-
my @vars = grep(/^GIT_/ && !/^GIT_($ok)/o, @env);
518-
print join("\n", @vars);
519-
')
502+
unset VISUAL EMAIL LANGUAGE $(env | sed -n \
503+
-e '/^GIT_TRACE/d' \
504+
-e '/^GIT_DEBUG/d' \
505+
-e '/^GIT_TEST/d' \
506+
-e '/^GIT_.*_TEST/d' \
507+
-e '/^GIT_PROVE/d' \
508+
-e '/^GIT_VALGRIND/d' \
509+
-e '/^GIT_UNZIP/d' \
510+
-e '/^GIT_PERF_/d' \
511+
-e '/^GIT_CURL_VERBOSE/d' \
512+
-e '/^GIT_TRACE_CURL/d' \
513+
-e '/^GIT_BUILD_DIR/d' \
514+
-e 's/^\(GIT_[^=]*\)=.*/\1/p'
515+
)
520516
unset XDG_CACHE_HOME
521517
unset XDG_CONFIG_HOME
522518
unset GITPERLLIB

0 commit comments

Comments
 (0)