t983*: use prereq to check for Python-specific git-p4(1) support

The tests in t9835 and t9836 verify that git-p4(1) works with both Python 2 and 3, respectively. To determine whether we have those Python versions in the first place we create a wrapper script that directly executes the git-p4(1) script with `python2` or `python3` binaries. We then condition the execution of tests on whether that wrapper script can be executed successfully. The logic that does all of this is not contained in a prerequisite block though, so the output it generates causes us to break the TAP format. Refactor the logic to use `test_lazy_prereq()` to fix this. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Jun 2, 2025 at 08:44 UTC a1199a23896c674f57f3942358e2f05b3a075e7a
2 files changed +26 -22
t/t9835-git-p4-metadata-encoding-python2.sh
+13 -11
@@ -12,23 +12,25 @@ failing, and produces maximally sane output in git.'
12 ## SECTION REPEATED IN t9836 ##
13 ###############################
14
15 +EXTRA_PATH="$(pwd)/temp_python"
16 +mkdir "$EXTRA_PATH"
17 +PATH="$EXTRA_PATH:$PATH"
18 +export PATH
19 +
20 # These tests are specific to Python 2. Write a custom script that executes
21 # git-p4 directly with the Python 2 interpreter to ensure that we use that
22 # version even if Git was compiled with Python 3.
18 -python_target_binary=$(which python2)
19 -if test -n "$python_target_binary"
20 -then
21 - mkdir temp_python
22 - PATH="$(pwd)/temp_python:$PATH"
23 - export PATH
24 -
25 - write_script temp_python/git-p4-python2 <<-EOF
23 +test_lazy_prereq P4_PYTHON2 '
24 + python_target_binary=$(which python2) &&
25 + test -n "$python_target_binary" &&
26 + write_script "$EXTRA_PATH"/git-p4-python2 <<-EOF &&
27 exec "$python_target_binary" "$(git --exec-path)/git-p4" "\$@"
28 EOF
28 -fi
29 + ( git p4-python2 || true ) >err &&
30 + test_grep "valid commands" err
31 +'
32
30 -git p4-python2 >err
31 -if ! grep 'valid commands' err
33 +if ! test_have_prereq P4_PYTHON2
34 then
35 skip_all="skipping python2 git p4 tests; python2 not available"
36 test_done
t/t9836-git-p4-metadata-encoding-python3.sh
+13 -11
@@ -12,23 +12,25 @@ failing, and produces maximally sane output in git.'
12 ## SECTION REPEATED IN t9835 ##
13 ###############################
14
15 +EXTRA_PATH="$(pwd)/temp_python"
16 +mkdir "$EXTRA_PATH"
17 +PATH="$EXTRA_PATH:$PATH"
18 +export PATH
19 +
20 # These tests are specific to Python 3. Write a custom script that executes
21 # git-p4 directly with the Python 3 interpreter to ensure that we use that
22 # version even if Git was compiled with Python 2.
18 -python_target_binary=$(which python3)
19 -if test -n "$python_target_binary"
20 -then
21 - mkdir temp_python
22 - PATH="$(pwd)/temp_python:$PATH"
23 - export PATH
24 -
25 - write_script temp_python/git-p4-python3 <<-EOF
23 +test_lazy_prereq P4_PYTHON3 '
24 + python_target_binary=$(which python3) &&
25 + test -n "$python_target_binary" &&
26 + write_script "$EXTRA_PATH"/git-p4-python3 <<-EOF &&
27 exec "$python_target_binary" "$(git --exec-path)/git-p4" "\$@"
28 EOF
28 -fi
29 + ( git p4-python3 || true ) >err &&
30 + test_grep "valid commands" err
31 +'
32
30 -git p4-python3 >err
31 -if ! grep 'valid commands' err
33 +if ! test_have_prereq P4_PYTHON3
34 then
35 skip_all="skipping python3 git p4 tests; python3 not available"
36 test_done