tests: move copy/pasted PERL + Test::More checks to a lib-perl.sh

Since the original "perl -MTest::More" prerequisite check was added in [1] it's been copy/pasted in [2], [3] and [4]. As we'll be changing these codepaths in a subsequent commit let's consolidate these. While we're at it let's move these to a lazy prereq, and make them conform to our usual coding style (e.g. "\nthen", not "; then"). 1. e46f9c8161a (t9700: skip when Test::More is not available, 2008-06-29) 2. 5e9637c6297 (i18n: add infrastructure for translating Git with gettext, 2011-11-18) 3. 8d314d7afec (send-email: reduce dependencies impact on parse_address_line, 2015-07-07) 4. f07eeed123b (git-credential-netrc: adapt to test framework for git, 2018-05-12) Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Jul 28, 2022 at 01:13 UTC 64f3f5a3f671e04150c900e447d8c858c25bad8f
4 files changed +25 -28
contrib/credential/netrc/t-git-credential-netrc.sh
+2 -9
@@ -3,16 +3,9 @@
3 cd ../../../t
4 test_description='git-credential-netrc'
5 . ./test-lib.sh
6 + . "$TEST_DIRECTORY"/lib-perl.sh
7
7 - if ! test_have_prereq PERL; then
8 - skip_all='skipping perl interface tests, perl not available'
9 - test_done
10 - fi
11 -
12 - perl -MTest::More -e 0 2>/dev/null || {
13 - skip_all="Perl Test::More unavailable, skipping test"
14 - test_done
15 - }
8 + skip_all_if_no_Test_More
9
10 # set up test repository
11
t/lib-perl.sh new
+19
@@ -0,0 +1,19 @@
1 +# Copyright (c) 2022 Ævar Arnfjörð Bjarmason
2 +
3 +test_lazy_prereq PERL_TEST_MORE '
4 + perl -MTest::More -e 0
5 +'
6 +
7 +skip_all_if_no_Test_More () {
8 + if ! test_have_prereq PERL
9 + then
10 + skip_all='skipping perl interface tests, perl not available'
11 + test_done
12 + fi
13 +
14 + if ! test_have_prereq PERL_TEST_MORE
15 + then
16 + skip_all="Perl Test::More unavailable, skipping test"
17 + test_done
18 + fi
19 +}
t/t0202-gettext-perl.sh
+2 -10
@@ -7,16 +7,8 @@ test_description='Perl gettext interface (Git::I18N)'
7
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./lib-gettext.sh
10 -
11 -if ! test_have_prereq PERL; then
12 - skip_all='skipping perl interface tests, perl not available'
13 - test_done
14 -fi
15 -
16 -perl -MTest::More -e 0 2>/dev/null || {
17 - skip_all="Perl Test::More unavailable, skipping test"
18 - test_done
19 -}
10 +. "$TEST_DIRECTORY"/lib-perl.sh
11 +skip_all_if_no_Test_More
12
13 # The external test will outputs its own plan
14 test_external_has_tap=1
t/t9700-perl-git.sh
+2 -9
@@ -5,16 +5,9 @@
5
6 test_description='perl interface (Git.pm)'
7 . ./test-lib.sh
8 +. "$TEST_DIRECTORY"/lib-perl.sh
9
9 -if ! test_have_prereq PERL; then
10 - skip_all='skipping perl interface tests, perl not available'
11 - test_done
12 -fi
13 -
14 -perl -MTest::More -e 0 2>/dev/null || {
15 - skip_all="Perl Test::More unavailable, skipping test"
16 - test_done
17 -}
10 +skip_all_if_no_Test_More
11
12 # set up test repository
13