Skip to content

Commit a1199a2

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8445370 commit a1199a2

File tree

2 files changed

+26
-22
lines changed

2 files changed

+26
-22
lines changed

t/t9835-git-p4-metadata-encoding-python2.sh

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,25 @@ failing, and produces maximally sane output in git.'
1212
## SECTION REPEATED IN t9836 ##
1313
###############################
1414

15+
EXTRA_PATH="$(pwd)/temp_python"
16+
mkdir "$EXTRA_PATH"
17+
PATH="$EXTRA_PATH:$PATH"
18+
export PATH
19+
1520
# These tests are specific to Python 2. Write a custom script that executes
1621
# git-p4 directly with the Python 2 interpreter to ensure that we use that
1722
# 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 &&
2627
exec "$python_target_binary" "$(git --exec-path)/git-p4" "\$@"
2728
EOF
28-
fi
29+
( git p4-python2 || true ) >err &&
30+
test_grep "valid commands" err
31+
'
2932

30-
git p4-python2 >err
31-
if ! grep 'valid commands' err
33+
if ! test_have_prereq P4_PYTHON2
3234
then
3335
skip_all="skipping python2 git p4 tests; python2 not available"
3436
test_done

t/t9836-git-p4-metadata-encoding-python3.sh

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,25 @@ failing, and produces maximally sane output in git.'
1212
## SECTION REPEATED IN t9835 ##
1313
###############################
1414

15+
EXTRA_PATH="$(pwd)/temp_python"
16+
mkdir "$EXTRA_PATH"
17+
PATH="$EXTRA_PATH:$PATH"
18+
export PATH
19+
1520
# These tests are specific to Python 3. Write a custom script that executes
1621
# git-p4 directly with the Python 3 interpreter to ensure that we use that
1722
# 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 &&
2627
exec "$python_target_binary" "$(git --exec-path)/git-p4" "\$@"
2728
EOF
28-
fi
29+
( git p4-python3 || true ) >err &&
30+
test_grep "valid commands" err
31+
'
2932

30-
git p4-python3 >err
31-
if ! grep 'valid commands' err
33+
if ! test_have_prereq P4_PYTHON3
3234
then
3335
skip_all="skipping python3 git p4 tests; python3 not available"
3436
test_done

0 commit comments

Comments
 (0)