Skip to content

Commit c740039

Browse files
avargitster
authored andcommitted
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 dfe1a17 ("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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3b072c5 commit c740039

File tree

4 files changed

+27
-12
lines changed

4 files changed

+27
-12
lines changed

t/README

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ that cannot be easily covered by a few specific test cases. These
334334
could be enabled by running the test suite with correct GIT_TEST_
335335
environment set.
336336

337-
GIT_TEST_FAIL_PREREQS<non-empty?> fails all prerequisites. This is
337+
GIT_TEST_FAIL_PREREQS=<boolean> fails all prerequisites. This is
338338
useful for discovering issues with the tests where say a later test
339339
implicitly depends on an optional earlier test.
340340

t/t0000-basic.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ donthaveit=yes
726726
test_expect_success DONTHAVEIT 'unmet prerequisite causes test to be skipped' '
727727
donthaveit=no
728728
'
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
730730
then
731731
say "bug in test framework: prerequisite tags do not work reliably"
732732
exit 1
@@ -747,7 +747,7 @@ donthaveiteither=yes
747747
test_expect_success DONTHAVEIT,HAVEIT 'unmet prerequisites causes test to be skipped' '
748748
donthaveiteither=no
749749
'
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
751751
then
752752
say "bug in test framework: multiple prerequisite tags do not work reliably"
753753
exit 1
@@ -763,7 +763,7 @@ test_expect_success !LAZY_TRUE 'missing lazy prereqs skip tests' '
763763
donthavetrue=no
764764
'
765765

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
767767
then
768768
say 'bug in test framework: lazy prerequisites do not work'
769769
exit 1
@@ -779,7 +779,7 @@ test_expect_success LAZY_FALSE 'missing negative lazy prereqs will skip' '
779779
havefalse=no
780780
'
781781

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
783783
then
784784
say 'bug in test framework: negative lazy prerequisites do not work'
785785
exit 1
@@ -790,7 +790,7 @@ test_expect_success 'tests clean up after themselves' '
790790
test_when_finished clean=yes
791791
'
792792

793-
if test -z "$GIT_TEST_FAIL_PREREQS" -a $clean != yes
793+
if test -z "$GIT_TEST_FAIL_PREREQS_INTERNAL" -a $clean != yes
794794
then
795795
say "bug in test framework: basic cleanup command does not work reliably"
796796
exit 1

t/test-lib-functions.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ test_unset_prereq () {
309309
}
310310

311311
test_set_prereq () {
312-
if test -n "$GIT_TEST_FAIL_PREREQS"
312+
if test -n "$GIT_TEST_FAIL_PREREQS_INTERNAL"
313313
then
314314
case "$1" in
315315
# The "!" case is handled below with
@@ -1043,7 +1043,7 @@ perl () {
10431043
# The error/skip message should be given by $2.
10441044
#
10451045
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
10471047
then
10481048
skip_all=$2
10491049
test_done

t/test-lib.sh

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,6 +1389,25 @@ yes () {
13891389
done
13901390
}
13911391

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+
13921411
# Fix some commands on Windows
13931412
uname_s=$(uname -s)
13941413
case $uname_s in
@@ -1605,7 +1624,3 @@ test_lazy_prereq SHA1 '
16051624
test_lazy_prereq REBASE_P '
16061625
test -z "$GIT_TEST_SKIP_REBASE_P"
16071626
'
1608-
1609-
test_lazy_prereq FAIL_PREREQS '
1610-
test -n "$GIT_TEST_FAIL_PREREQS"
1611-
'

0 commit comments

Comments
 (0)