tests: make GIT_TEST_FAIL_PREREQS a boolean

Change the GIT_TEST_FAIL_PREREQS variable from being "non-empty?" to being a more standard boolean variable. I recently added the variable in dfe1a17df9 ("tests: add a special setup where prerequisites fail", 2019-05-13), having to add another "non-empty?" special-case is what prompted me to write the "git env--helper" utility being used here. Converting this one is a bit tricky since we use it so early and frequently in the guts of the test code itself, so let's set a GIT_TEST_FAIL_PREREQS_INTERNAL which can be tested with the old "test -n" for the purposes of the shell code, and change the user-exposed and documented GIT_TEST_FAIL_PREREQS variable to a boolean. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Jun 21, 2019 at 12:18 UTC c740039921528198efa21f9cf6ccb849e74164c4
4 files changed +27 -12
t/README
+1 -1
@@ -334,7 +334,7 @@ that cannot be easily covered by a few specific test cases. These
334 could be enabled by running the test suite with correct GIT_TEST_
335 environment set.
336
337 -GIT_TEST_FAIL_PREREQS<non-empty?> fails all prerequisites. This is
337 +GIT_TEST_FAIL_PREREQS=<boolean> fails all prerequisites. This is
338 useful for discovering issues with the tests where say a later test
339 implicitly depends on an optional earlier test.
340
t/t0000-basic.sh
+5 -5
@@ -726,7 +726,7 @@ donthaveit=yes
726 test_expect_success DONTHAVEIT 'unmet prerequisite causes test to be skipped' '
727 donthaveit=no
728 '
729 -if test -z "$GIT_TEST_FAIL_PREREQS" -a $haveit$donthaveit != yesyes
729 +if test -z "$GIT_TEST_FAIL_PREREQS_INTERNAL" -a $haveit$donthaveit != yesyes
730 then
731 say "bug in test framework: prerequisite tags do not work reliably"
732 exit 1
@@ -747,7 +747,7 @@ donthaveiteither=yes
747 test_expect_success DONTHAVEIT,HAVEIT 'unmet prerequisites causes test to be skipped' '
748 donthaveiteither=no
749 '
750 -if test -z "$GIT_TEST_FAIL_PREREQS" -a $haveit$donthaveit$donthaveiteither != yesyesyes
750 +if test -z "$GIT_TEST_FAIL_PREREQS_INTERNAL" -a $haveit$donthaveit$donthaveiteither != yesyesyes
751 then
752 say "bug in test framework: multiple prerequisite tags do not work reliably"
753 exit 1
@@ -763,7 +763,7 @@ test_expect_success !LAZY_TRUE 'missing lazy prereqs skip tests' '
763 donthavetrue=no
764 '
765
766 -if test -z "$GIT_TEST_FAIL_PREREQS" -a "$havetrue$donthavetrue" != yesyes
766 +if test -z "$GIT_TEST_FAIL_PREREQS_INTERNAL" -a "$havetrue$donthavetrue" != yesyes
767 then
768 say 'bug in test framework: lazy prerequisites do not work'
769 exit 1
@@ -779,7 +779,7 @@ test_expect_success LAZY_FALSE 'missing negative lazy prereqs will skip' '
779 havefalse=no
780 '
781
782 -if test -z "$GIT_TEST_FAIL_PREREQS" -a "$nothavefalse$havefalse" != yesyes
782 +if test -z "$GIT_TEST_FAIL_PREREQS_INTERNAL" -a "$nothavefalse$havefalse" != yesyes
783 then
784 say 'bug in test framework: negative lazy prerequisites do not work'
785 exit 1
@@ -790,7 +790,7 @@ test_expect_success 'tests clean up after themselves' '
790 test_when_finished clean=yes
791 '
792
793 -if test -z "$GIT_TEST_FAIL_PREREQS" -a $clean != yes
793 +if test -z "$GIT_TEST_FAIL_PREREQS_INTERNAL" -a $clean != yes
794 then
795 say "bug in test framework: basic cleanup command does not work reliably"
796 exit 1
t/test-lib-functions.sh
+2 -2
@@ -309,7 +309,7 @@ test_unset_prereq () {
309 }
310
311 test_set_prereq () {
312 - if test -n "$GIT_TEST_FAIL_PREREQS"
312 + if test -n "$GIT_TEST_FAIL_PREREQS_INTERNAL"
313 then
314 case "$1" in
315 # The "!" case is handled below with
@@ -1043,7 +1043,7 @@ perl () {
1043 # The error/skip message should be given by $2.
1044 #
1045 test_skip_or_die () {
1046 - if ! git env--helper --mode-bool --variable=$1 --default=0 --exit-code --quiet
1046 + if ! git env--helper --type=bool --default=false --exit-code $1
1047 then
1048 skip_all=$2
1049 test_done
t/test-lib.sh
+19 -4
@@ -1389,6 +1389,25 @@ yes () {
1389 done
1390 }
1391
1392 +# The GIT_TEST_FAIL_PREREQS code hooks into test_set_prereq(), and
1393 +# thus needs to be set up really early, and set an internal variable
1394 +# for convenience so the hot test_set_prereq() codepath doesn't need
1395 +# to call "git env--helper". Only do that work if needed by seeing if
1396 +# GIT_TEST_FAIL_PREREQS is set at all.
1397 +GIT_TEST_FAIL_PREREQS_INTERNAL=
1398 +if test -n "$GIT_TEST_FAIL_PREREQS"
1399 +then
1400 + if git env--helper --type=bool --default=0 --exit-code GIT_TEST_FAIL_PREREQS
1401 + then
1402 + GIT_TEST_FAIL_PREREQS_INTERNAL=true
1403 + test_set_prereq FAIL_PREREQS
1404 + fi
1405 +else
1406 + test_lazy_prereq FAIL_PREREQS '
1407 + git env--helper --type=bool --default=0 --exit-code GIT_TEST_FAIL_PREREQS
1408 + '
1409 +fi
1410 +
1411 # Fix some commands on Windows
1412 uname_s=$(uname -s)
1413 case $uname_s in
@@ -1605,7 +1624,3 @@ test_lazy_prereq SHA1 '
1624 test_lazy_prereq REBASE_P '
1625 test -z "$GIT_TEST_SKIP_REBASE_P"
1626 '
1608 -
1609 -test_lazy_prereq FAIL_PREREQS '
1610 - test -n "$GIT_TEST_FAIL_PREREQS"
1611 -'