Skip to content

Commit 89d1b57

Browse files
committed
Merge branch 'ab/fail-prereqs-in-test'
Developer support to emulate unsatisfied prerequisites in tests to ensure that the remainer of the tests still succeeds when tests with prerequisites are skipped. * ab/fail-prereqs-in-test: tests: add a special setup where prerequisites fail
2 parents 000bce0 + dfe1a17 commit 89d1b57

7 files changed

+43
-10
lines changed

t/README

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,15 @@ 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
338+
useful for discovering issues with the tests where say a later test
339+
implicitly depends on an optional earlier test.
340+
341+
There's a "FAIL_PREREQS" prerequisite that can be used to test for
342+
whether this mode is active, and e.g. skip some tests that are hard to
343+
refactor to deal with it. The "SYMLINKS" prerequisite is currently
344+
excluded as so much relies on it, but this might change in the future.
345+
337346
GIT_TEST_GETTEXT_POISON=<non-empty?> turns all strings marked for
338347
translation into gibberish if non-empty (think "test -n"). Used for
339348
spotting those tests that need to be marked with a C_LOCALE_OUTPUT

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 $haveit$donthaveit != yesyes
729+
if test -z "$GIT_TEST_FAIL_PREREQS" -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 $haveit$donthaveit$donthaveiteither != yesyesyes
750+
if test -z "$GIT_TEST_FAIL_PREREQS" -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 "$havetrue$donthavetrue" != yesyes
766+
if test -z "$GIT_TEST_FAIL_PREREQS" -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 "$nothavefalse$havefalse" != yesyes
782+
if test -z "$GIT_TEST_FAIL_PREREQS" -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 $clean != yes
793+
if test -z "$GIT_TEST_FAIL_PREREQS" -a $clean != yes
794794
then
795795
say "bug in test framework: basic cleanup command does not work reliably"
796796
exit 1

t/t4202-log.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ test_expect_success 'log with grep.patternType configuration and command line' '
352352
test_cmp expect actual
353353
'
354354

355-
test_expect_success 'log with various grep.patternType configurations & command-lines' '
355+
test_expect_success !FAIL_PREREQS 'log with various grep.patternType configurations & command-lines' '
356356
git init pattern-type &&
357357
(
358358
cd pattern-type &&

t/t7405-submodule-merge.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ test_expect_failure 'directory/submodule conflict; keep submodule clean' '
417417
)
418418
'
419419

420-
test_expect_failure 'directory/submodule conflict; should not treat submodule files as untracked or in the way' '
420+
test_expect_failure !FAIL_PREREQS 'directory/submodule conflict; should not treat submodule files as untracked or in the way' '
421421
test_when_finished "git -C directory-submodule/path reset --hard" &&
422422
test_when_finished "git -C directory-submodule reset --hard" &&
423423
(

t/t7810-grep.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ do
412412
test_cmp expected actual
413413
'
414414

415-
test_expect_success !PCRE "grep $L with grep.patterntype=perl errors without PCRE" '
415+
test_expect_success !FAIL_PREREQS,!PCRE "grep $L with grep.patterntype=perl errors without PCRE" '
416416
test_must_fail git -c grep.patterntype=perl grep "foo.*bar"
417417
'
418418

@@ -1234,7 +1234,7 @@ test_expect_success PCRE 'grep --perl-regexp pattern' '
12341234
test_cmp expected actual
12351235
'
12361236

1237-
test_expect_success !PCRE 'grep --perl-regexp pattern errors without PCRE' '
1237+
test_expect_success !FAIL_PREREQS,!PCRE 'grep --perl-regexp pattern errors without PCRE' '
12381238
test_must_fail git grep --perl-regexp "foo.*bar"
12391239
'
12401240

@@ -1249,7 +1249,7 @@ test_expect_success LIBPCRE2 "grep -P with (*NO_JIT) doesn't error out" '
12491249
12501250
'
12511251

1252-
test_expect_success !PCRE 'grep -P pattern errors without PCRE' '
1252+
test_expect_success !FAIL_PREREQS,!PCRE 'grep -P pattern errors without PCRE' '
12531253
test_must_fail git grep -P "foo.*bar"
12541254
'
12551255

t/test-lib-functions.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,26 @@ test_unset_prereq () {
309309
}
310310

311311
test_set_prereq () {
312+
if test -n "$GIT_TEST_FAIL_PREREQS"
313+
then
314+
case "$1" in
315+
# The "!" case is handled below with
316+
# test_unset_prereq()
317+
!*)
318+
;;
319+
# (Temporary?) whitelist of things we can't easily
320+
# pretend not to support
321+
SYMLINKS)
322+
;;
323+
# Inspecting whether GIT_TEST_FAIL_PREREQS is on
324+
# should be unaffected.
325+
FAIL_PREREQS)
326+
;;
327+
*)
328+
return
329+
esac
330+
fi
331+
312332
case "$1" in
313333
!*)
314334
test_unset_prereq "${1#!}"

t/test-lib.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1607,3 +1607,7 @@ test_lazy_prereq SHA1 '
16071607
test_lazy_prereq REBASE_P '
16081608
test -z "$GIT_TEST_SKIP_REBASE_P"
16091609
'
1610+
1611+
test_lazy_prereq FAIL_PREREQS '
1612+
test -n "$GIT_TEST_FAIL_PREREQS"
1613+
'

0 commit comments

Comments
 (0)