test-lib: introduce required prereq for test runs

In certain environments or for specific test scenarios we might expect a specific prerequisite check to succeed. Therefore we would like to abort running our tests if this is not the case. To remedy this we add the environment variable GIT_TEST_REQUIRE_PREREQ which can be set to a space separated list of prereqs. If one of these prereq tests fail then the whole test run will abort. Signed-off-by: Fabian Stelzer <fs@gigacodes.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Fabian Stelzer committed Nov 20, 2021 at 16:04 UTC 5024ade1b1445107091c429e0da97f45e06bb7c9
2 files changed +17
t/README
+6
@@ -466,6 +466,12 @@ explicitly providing repositories when accessing submodule objects is
466 complete or needs to be abandoned for whatever reason (in which case the
467 migrated codepaths still retain their performance benefits).
468
469 +GIT_TEST_REQUIRE_PREREQ=<list> allows specifying a space speparated list of
470 +prereqs that are required to succeed. If a prereq in this list is triggered by
471 +a test and then fails then the whole test run will abort. This can help to make
472 +sure the expected tests are executed and not silently skipped when their
473 +dependency breaks or is simply not present in a new environment.
474 +
475 Naming Tests
476 ------------
477
t/test-lib-functions.sh
+11
@@ -680,6 +680,17 @@ test_have_prereq () {
680 # Keep a list of missing prerequisites; restore
681 # the negative marker if necessary.
682 prerequisite=${negative_prereq:+!}$prerequisite
683 +
684 + # Abort if this prereq was marked as required
685 + if test -n "$GIT_TEST_REQUIRE_PREREQ"
686 + then
687 + case " $GIT_TEST_REQUIRE_PREREQ " in
688 + *" $prerequisite "*)
689 + BAIL_OUT "required prereq $prerequisite failed"
690 + ;;
691 + esac
692 + fi
693 +
694 if test -z "$missing_prereq"
695 then
696 missing_prereq=$prerequisite