From f6033bee183f82004aee9410e3f4bedd8b5da23c Mon Sep 17 00:00:00 2001 From: Chris Lindee Date: Sat, 13 Oct 2018 13:03:02 -0500 Subject: [PATCH] Make MSWin32 Perl available to all tests Pull out the logic to find a MSWin32 build of Perl, so it can be used by all tests. Signed-off-by: Chris Lindee --- Makefile | 14 ++++++++++++++ t/t9701-perl-git-MSWin32.sh | 19 +++---------------- t/test-lib-functions.sh | 8 ++++++++ t/test-lib.sh | 10 +++++++++- 4 files changed, 34 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index 8b3868ed8b4cf5..de25b43a267bbb 100644 --- a/Makefile +++ b/Makefile @@ -2475,6 +2475,19 @@ LIB_PERL_GEN := $(patsubst perl/%.pm,perl/build/lib/%.pm,$(LIB_PERL)) LIB_CPAN := $(wildcard perl/FromCPAN/*.pm perl/FromCPAN/*/*.pm) LIB_CPAN_GEN := $(patsubst perl/%.pm,perl/build/lib/%.pm,$(LIB_CPAN)) +# Set MSWIN32_PERL_PATH=false to disable search +ifndef MSWIN32_PERL_PATH +MSWIN32_PERL_PATH = $(shell \ + for perl in $$(type -ap perl); do \ + if "$$perl" -e 'exit 1 if $$^O ne q{MSWin32}'; then \ + echo "$$perl"; \ + exit 0; \ + fi; \ + done \ +) +endif +MSWIN32_PERL_PATH_SQ = $(subst ','\'',$(MSWIN32_PERL_PATH)) + ifndef NO_PERL all:: $(LIB_PERL_GEN) ifndef NO_PERL_CPAN_FALLBACKS @@ -2573,6 +2586,7 @@ GIT-BUILD-OPTIONS: FORCE @echo PAGER_ENV=\''$(subst ','\'',$(subst ','\'',$(PAGER_ENV)))'\' >>$@+ @echo DC_SHA1=\''$(subst ','\'',$(subst ','\'',$(DC_SHA1)))'\' >>$@+ @echo X=\'$(X)\' >>$@+ + @echo MSWIN32_PERL_PATH=\''$(subst ','\'',$(MSWIN32_PERL_PATH_SQ))'\' >>$@+ ifdef TEST_OUTPUT_DIRECTORY @echo TEST_OUTPUT_DIRECTORY=\''$(subst ','\'',$(subst ','\'',$(TEST_OUTPUT_DIRECTORY)))'\' >>$@+ endif diff --git a/t/t9701-perl-git-MSWin32.sh b/t/t9701-perl-git-MSWin32.sh index 27dffa30cc5c1b..6ff96c4bd463a2 100755 --- a/t/t9701-perl-git-MSWin32.sh +++ b/t/t9701-perl-git-MSWin32.sh @@ -6,24 +6,12 @@ test_description='perl interface (Git.pm) on MSWin32' . ./test-lib.sh -find_MSWin32_perl() { - local perl - for perl in $(type -ap perl); do - if "$perl" -e 'exit 1 if $^O ne q{MSWin32}'; then - echo "$perl" - return 0 - fi - done - return 1 -} - -MSWin32_Perl="$(find_MSWin32_perl)" -if [ $? -ne 0 ]; then +if ! test_have_prereq MSWIN32_PERL; then skip_all='skipping perl on MSWin32 interface tests, MSWin32 perl not available' test_done fi -"$MSWin32_Perl" -MTest::More -e 0 2>/dev/null || { +mswin32_perl -MTest::More -e 0 2>/dev/null || { skip_all="MSWin32 Perl Test::More unavailable, skipping test" test_done } @@ -35,11 +23,10 @@ test_external_has_tap=1 perl_test_path="$TEST_DIRECTORY"/t9701/test.pl if test_have_prereq CYGWIN || test_have_prereq MINGW; then perl_test_path="$(cygpath -w "$perl_test_path")" - GITPERLLIB="$(cygpath -w -p "$GITPERLLIB")" fi test_external_without_stderr \ 'Windows command line (Perl API)' \ - "$MSWin32_Perl" "$perl_test_path" + mswin32_perl "$perl_test_path" test_done diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index 11b81276917db5..1a883e93bbafc0 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -933,6 +933,14 @@ perl () { command "$PERL_PATH" "$@" 2>&7 } 7>&2 2>&4 +mswin32_perl () { + local GITPERLLIB="$GITPERLLIB" + if test_have_prereq CYGWIN || test_have_prereq MINGW; then + GITPERLLIB="$(cygpath -w -p "$GITPERLLIB")" + fi + command "$MSWIN32_PERL_PATH" "$@" 2>&7 +} 7>&2 2>&4 + # Is the value one of the various ways to spell a boolean true/false? test_normalize_bool () { git -c magic.variable="$1" config --bool magic.variable 2>/dev/null diff --git a/t/test-lib.sh b/t/test-lib.sh index f2bd4e6fb86fd4..9eb3a9f72d5923 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -64,7 +64,7 @@ then exit 1 fi . "$GIT_BUILD_DIR"/GIT-BUILD-OPTIONS -export PERL_PATH SHELL_PATH +export MSWIN32_PERL_PATH PERL_PATH SHELL_PATH ################################################################ # It appears that people try to run tests without building... @@ -1268,3 +1268,11 @@ test_lazy_prereq CURL ' test_lazy_prereq SHA1 ' test $(git hash-object /dev/null) = e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 ' + +# Some tests require a native Win32 Perl interpreter, such as Strawberry Perl +# or ActiveState Perl, which is not distributed with Git for Windows. These +# tests only run if an appropriate Perl is specified (via MSWIN32_PERL_PATH). +test_lazy_prereq MSWIN32_PERL ' + test -n "$MSWIN32_PERL_PATH" && + $MSWIN32_PERL_PATH -e "exit 1 if \$^O ne q{MSWin32}" +'