]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t983*: use prereq to check for Python-specific git-p4(1) support
authorPatrick Steinhardt <ps@pks.im>
Mon, 2 Jun 2025 06:44:44 +0000 (08:44 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 2 Jun 2025 14:51:42 +0000 (07:51 -0700)
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>
t/t9835-git-p4-metadata-encoding-python2.sh
t/t9836-git-p4-metadata-encoding-python3.sh

index 6116f806f631157aca7de6dbd33dcd94bbefb8aa..b969c7e0d5aef6ff7c11fcf2dc2bf2f48e6d2bb1 100755 (executable)
@@ -12,23 +12,25 @@ failing, and produces maximally sane output in git.'
 ## SECTION REPEATED IN t9836 ##
 ###############################
 
+EXTRA_PATH="$(pwd)/temp_python"
+mkdir "$EXTRA_PATH"
+PATH="$EXTRA_PATH:$PATH"
+export PATH
+
 # These tests are specific to Python 2. Write a custom script that executes
 # git-p4 directly with the Python 2 interpreter to ensure that we use that
 # version even if Git was compiled with Python 3.
-python_target_binary=$(which python2)
-if test -n "$python_target_binary"
-then
-       mkdir temp_python
-       PATH="$(pwd)/temp_python:$PATH"
-       export PATH
-
-       write_script temp_python/git-p4-python2 <<-EOF
+test_lazy_prereq P4_PYTHON2 '
+       python_target_binary=$(which python2) &&
+       test -n "$python_target_binary" &&
+       write_script "$EXTRA_PATH"/git-p4-python2 <<-EOF &&
        exec "$python_target_binary" "$(git --exec-path)/git-p4" "\$@"
        EOF
-fi
+       ( git p4-python2 || true ) >err &&
+       test_grep "valid commands" err
+'
 
-git p4-python2 >err
-if ! grep 'valid commands' err
+if ! test_have_prereq P4_PYTHON2
 then
        skip_all="skipping python2 git p4 tests; python2 not available"
        test_done
index 5e5217a66b4fdb3c7fcf073a50952c7e9009e9fe..da6669bf7119e59938a2128bd2e4581342af6d49 100755 (executable)
@@ -12,23 +12,25 @@ failing, and produces maximally sane output in git.'
 ## SECTION REPEATED IN t9835 ##
 ###############################
 
+EXTRA_PATH="$(pwd)/temp_python"
+mkdir "$EXTRA_PATH"
+PATH="$EXTRA_PATH:$PATH"
+export PATH
+
 # These tests are specific to Python 3. Write a custom script that executes
 # git-p4 directly with the Python 3 interpreter to ensure that we use that
 # version even if Git was compiled with Python 2.
-python_target_binary=$(which python3)
-if test -n "$python_target_binary"
-then
-       mkdir temp_python
-       PATH="$(pwd)/temp_python:$PATH"
-       export PATH
-
-       write_script temp_python/git-p4-python3 <<-EOF
+test_lazy_prereq P4_PYTHON3 '
+       python_target_binary=$(which python3) &&
+       test -n "$python_target_binary" &&
+       write_script "$EXTRA_PATH"/git-p4-python3 <<-EOF &&
        exec "$python_target_binary" "$(git --exec-path)/git-p4" "\$@"
        EOF
-fi
+       ( git p4-python3 || true ) >err &&
+       test_grep "valid commands" err
+'
 
-git p4-python3 >err
-if ! grep 'valid commands' err
+if ! test_have_prereq P4_PYTHON3
 then
        skip_all="skipping python3 git p4 tests; python3 not available"
        test_done