t: extend test_lazy_prereq

Allow test_lazy_prereq script to signal a programming error by exiting with status 125 (like how bisect scripts do). This is used to signal a deprecated-and-then-removed prerequisite that should never be used in tests anymore. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Mar 11, 2025 at 14:25 UTC 1c24d55a2fdea3599a1cc3cdaeef1e1fa173b2c5
2 files changed +9 -2
t/README
+4 -2
@@ -983,8 +983,10 @@ see test-lib-functions.sh for the full list and their options.
983 SYMLINKS ...". The script is run in a temporary directory inside
984 a subshell, so you do not have to worry about removing temporary
985 files you create there. When the script exits with status 0, the
986 - prerequisite is set. Exiting with non-zero status makes the
987 - prerequisite unsatisified.
986 + prerequisite is set. Exiting with non-zero status other than 125
987 + makes the prerequisite unsatisified. Exiting the script with 125
988 + signals a programming error and is used to mark a prerequisite that
989 + should not be used by test scripts.
990
991 - test_expect_code <exit-code> <command>
992
t/test-lib-functions.sh
+5
@@ -773,6 +773,8 @@ mkdir -p "$TRASH_DIRECTORY/prereq-test-dir-'"$1"'" &&
773 rm -rf "$TRASH_DIRECTORY/prereq-test-dir-$1"
774 if test "$eval_ret" = 0; then
775 say >&3 "prerequisite $1 ok"
776 + elif test "$eval_ret" = 125; then
777 + :;
778 else
779 say >&3 "prerequisite $1 not satisfied"
780 fi
@@ -811,6 +813,9 @@ test_have_prereq () {
813 if test_run_lazy_prereq_ "$prerequisite" "$script"
814 then
815 test_set_prereq $prerequisite
816 + elif test $? = 125
817 + then
818 + BUG "Do not use $prerequisite"
819 fi
820 lazily_tested_prereq="$lazily_tested_prereq$prerequisite "
821 esac