Skip to content

Commit 78ad729

Browse files
pks-tgitster
authored andcommitted
t: fix out-of-tree tests for some git-p4 tests
Both t9835 and t9836 exercise git-p4, but one exercises Python 2 whereas the other one uses Python 3. These tests do not exercise "git p4", but instead they use "git p4.py". This calls the unbuilt version of "git-p4.py" that still has the "#!/usr/bin/env python" shebang, which allows the test to modify which Python version comes first in $PATH, making it possible to force a Python version. But "git-p4.py" is not in our PATH during out-of-tree builds, and thus we cannot locate "git-p4.py". The tests thus break with CMake and Meson. Fix this by instead manually setting up script wrappers that invoke the respective Python interpreter directly. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 154ce05 commit 78ad729

File tree

2 files changed

+50
-50
lines changed

2 files changed

+50
-50
lines changed

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

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,29 @@ failing, and produces maximally sane output in git.'
88

99
. ./lib-git-p4.sh
1010

11-
python_target_version='2'
12-
1311
###############################
1412
## SECTION REPEATED IN t9836 ##
1513
###############################
1614

17-
# Please note: this test calls "git-p4.py" rather than "git-p4", because the
18-
# latter references a specific path so we can't easily force it to run under
19-
# the python version we need to.
20-
21-
python_major_version=$(python -V 2>&1 | cut -c 8)
22-
python_target_binary=$(which python$python_target_version)
23-
if ! test "$python_major_version" = "$python_target_version" && test "$python_target_binary"
15+
# These tests are specific to Python 2. Write a custom script that executes
16+
# git-p4 directly with the Python 2 interpreter to ensure that we use that
17+
# version even if Git was compiled with Python 3.
18+
python_target_binary=$(which python2)
19+
if test -n "$python_target_binary"
2420
then
2521
mkdir temp_python
26-
PATH="$(pwd)/temp_python:$PATH" && export PATH
27-
ln -s $python_target_binary temp_python/python
22+
PATH="$(pwd)/temp_python:$PATH"
23+
export PATH
24+
25+
write_script temp_python/git-p4-python2 <<-EOF
26+
exec "$python_target_binary" "$(git --exec-path)/git-p4" "\$@"
27+
EOF
2828
fi
2929

30-
python_major_version=$(python -V 2>&1 | cut -c 8)
31-
if ! test "$python_major_version" = "$python_target_version"
30+
git p4-python2 >err
31+
if ! grep 'valid commands' err
3232
then
33-
skip_all="skipping python$python_target_version-specific git p4 tests; python$python_target_version not available"
33+
skip_all="skipping python2 git p4 tests; python2 not available"
3434
test_done
3535
fi
3636

@@ -81,14 +81,14 @@ test_expect_success 'init depot' '
8181
test_expect_success 'clone non-utf8 repo with strict encoding' '
8282
test_when_finished cleanup_git &&
8383
test_when_finished remove_user_cache &&
84-
test_must_fail git -c git-p4.metadataDecodingStrategy=strict p4.py clone --dest="$git" //depot@all 2>err &&
84+
test_must_fail git -c git-p4.metadataDecodingStrategy=strict p4-python2 clone --dest="$git" //depot@all 2>err &&
8585
grep "Decoding perforce metadata failed!" err
8686
'
8787

8888
test_expect_success 'check utf-8 contents with passthrough strategy' '
8989
test_when_finished cleanup_git &&
9090
test_when_finished remove_user_cache &&
91-
git -c git-p4.metadataDecodingStrategy=passthrough p4.py clone --dest="$git" //depot@all &&
91+
git -c git-p4.metadataDecodingStrategy=passthrough p4-python2 clone --dest="$git" //depot@all &&
9292
(
9393
cd "$git" &&
9494
git log >actual &&
@@ -100,7 +100,7 @@ test_expect_success 'check utf-8 contents with passthrough strategy' '
100100
test_expect_success 'check latin-1 contents corrupted in git with passthrough strategy' '
101101
test_when_finished cleanup_git &&
102102
test_when_finished remove_user_cache &&
103-
git -c git-p4.metadataDecodingStrategy=passthrough p4.py clone --dest="$git" //depot@all &&
103+
git -c git-p4.metadataDecodingStrategy=passthrough p4-python2 clone --dest="$git" //depot@all &&
104104
(
105105
cd "$git" &&
106106
git log >actual &&
@@ -114,7 +114,7 @@ test_expect_success 'check latin-1 contents corrupted in git with passthrough st
114114
test_expect_success 'check utf-8 contents with fallback strategy' '
115115
test_when_finished cleanup_git &&
116116
test_when_finished remove_user_cache &&
117-
git -c git-p4.metadataDecodingStrategy=fallback p4.py clone --dest="$git" //depot@all &&
117+
git -c git-p4.metadataDecodingStrategy=fallback p4-python2 clone --dest="$git" //depot@all &&
118118
(
119119
cd "$git" &&
120120
git log >actual &&
@@ -126,7 +126,7 @@ test_expect_success 'check utf-8 contents with fallback strategy' '
126126
test_expect_success 'check latin-1 contents with fallback strategy' '
127127
test_when_finished cleanup_git &&
128128
test_when_finished remove_user_cache &&
129-
git -c git-p4.metadataDecodingStrategy=fallback p4.py clone --dest="$git" //depot@all &&
129+
git -c git-p4.metadataDecodingStrategy=fallback p4-python2 clone --dest="$git" //depot@all &&
130130
(
131131
cd "$git" &&
132132
git log >actual &&
@@ -138,7 +138,7 @@ test_expect_success 'check latin-1 contents with fallback strategy' '
138138
test_expect_success 'check cp-1252 contents with fallback strategy' '
139139
test_when_finished cleanup_git &&
140140
test_when_finished remove_user_cache &&
141-
git -c git-p4.metadataDecodingStrategy=fallback p4.py clone --dest="$git" //depot@all &&
141+
git -c git-p4.metadataDecodingStrategy=fallback p4-python2 clone --dest="$git" //depot@all &&
142142
(
143143
cd "$git" &&
144144
git log >actual &&
@@ -150,7 +150,7 @@ test_expect_success 'check cp-1252 contents with fallback strategy' '
150150
test_expect_success 'check cp850 contents parsed with correct fallback' '
151151
test_when_finished cleanup_git &&
152152
test_when_finished remove_user_cache &&
153-
git -c git-p4.metadataDecodingStrategy=fallback -c git-p4.metadataFallbackEncoding=cp850 p4.py clone --dest="$git" //depot@all &&
153+
git -c git-p4.metadataDecodingStrategy=fallback -c git-p4.metadataFallbackEncoding=cp850 p4-python2 clone --dest="$git" //depot@all &&
154154
(
155155
cd "$git" &&
156156
git log >actual &&
@@ -162,7 +162,7 @@ test_expect_success 'check cp850 contents parsed with correct fallback' '
162162
test_expect_success 'check cp850-only contents escaped when cp1252 is fallback' '
163163
test_when_finished cleanup_git &&
164164
test_when_finished remove_user_cache &&
165-
git -c git-p4.metadataDecodingStrategy=fallback p4.py clone --dest="$git" //depot@all &&
165+
git -c git-p4.metadataDecodingStrategy=fallback p4-python2 clone --dest="$git" //depot@all &&
166166
(
167167
cd "$git" &&
168168
git log >actual &&
@@ -174,7 +174,7 @@ test_expect_success 'check cp850-only contents escaped when cp1252 is fallback'
174174
test_expect_success 'check cp-1252 contents on later sync after clone with fallback strategy' '
175175
test_when_finished cleanup_git &&
176176
test_when_finished remove_user_cache &&
177-
git -c git-p4.metadataDecodingStrategy=fallback p4.py clone --dest="$git" //depot@all &&
177+
git -c git-p4.metadataDecodingStrategy=fallback p4-python2 clone --dest="$git" //depot@all &&
178178
(
179179
cd "$cli" &&
180180
P4USER=cp1252_author &&
@@ -186,7 +186,7 @@ test_expect_success 'check cp-1252 contents on later sync after clone with fallb
186186
(
187187
cd "$git" &&
188188
189-
git p4.py sync --branch=master &&
189+
git p4-python2 sync --branch=master &&
190190
191191
git log p4/master >actual &&
192192
grep "sœme more cp-1252 tæxt" actual &&
@@ -201,7 +201,7 @@ test_expect_success 'check cp-1252 contents on later sync after clone with fallb
201201
test_expect_success 'passthrough (latin-1 contents corrupted in git) is the default with python2' '
202202
test_when_finished cleanup_git &&
203203
test_when_finished remove_user_cache &&
204-
git -c git-p4.metadataDecodingStrategy=passthrough p4.py clone --dest="$git" //depot@all &&
204+
git -c git-p4.metadataDecodingStrategy=passthrough p4-python2 clone --dest="$git" //depot@all &&
205205
(
206206
cd "$git" &&
207207
git log >actual &&

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

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,29 @@ failing, and produces maximally sane output in git.'
88

99
. ./lib-git-p4.sh
1010

11-
python_target_version='3'
12-
1311
###############################
1412
## SECTION REPEATED IN t9835 ##
1513
###############################
1614

17-
# Please note: this test calls "git-p4.py" rather than "git-p4", because the
18-
# latter references a specific path so we can't easily force it to run under
19-
# the python version we need to.
20-
21-
python_major_version=$(python -V 2>&1 | cut -c 8)
22-
python_target_binary=$(which python$python_target_version)
23-
if ! test "$python_major_version" = "$python_target_version" && test "$python_target_binary"
15+
# These tests are specific to Python 3. Write a custom script that executes
16+
# git-p4 directly with the Python 3 interpreter to ensure that we use that
17+
# version even if Git was compiled with Python 2.
18+
python_target_binary=$(which python3)
19+
if test -n "$python_target_binary"
2420
then
2521
mkdir temp_python
26-
PATH="$(pwd)/temp_python:$PATH" && export PATH
27-
ln -s $python_target_binary temp_python/python
22+
PATH="$(pwd)/temp_python:$PATH"
23+
export PATH
24+
25+
write_script temp_python/git-p4-python3 <<-EOF
26+
exec "$python_target_binary" "$(git --exec-path)/git-p4" "\$@"
27+
EOF
2828
fi
2929

30-
python_major_version=$(python -V 2>&1 | cut -c 8)
31-
if ! test "$python_major_version" = "$python_target_version"
30+
git p4-python3 >err
31+
if ! grep 'valid commands' err
3232
then
33-
skip_all="skipping python$python_target_version-specific git p4 tests; python$python_target_version not available"
33+
skip_all="skipping python3 git p4 tests; python3 not available"
3434
test_done
3535
fi
3636

@@ -81,14 +81,14 @@ test_expect_success 'init depot' '
8181
test_expect_success 'clone non-utf8 repo with strict encoding' '
8282
test_when_finished cleanup_git &&
8383
test_when_finished remove_user_cache &&
84-
test_must_fail git -c git-p4.metadataDecodingStrategy=strict p4.py clone --dest="$git" //depot@all 2>err &&
84+
test_must_fail git -c git-p4.metadataDecodingStrategy=strict p4-python3 clone --dest="$git" //depot@all 2>err &&
8585
grep "Decoding perforce metadata failed!" err
8686
'
8787

8888
test_expect_success 'check utf-8 contents with passthrough strategy' '
8989
test_when_finished cleanup_git &&
9090
test_when_finished remove_user_cache &&
91-
git -c git-p4.metadataDecodingStrategy=passthrough p4.py clone --dest="$git" //depot@all &&
91+
git -c git-p4.metadataDecodingStrategy=passthrough p4-python3 clone --dest="$git" //depot@all &&
9292
(
9393
cd "$git" &&
9494
git log >actual &&
@@ -100,7 +100,7 @@ test_expect_success 'check utf-8 contents with passthrough strategy' '
100100
test_expect_success 'check latin-1 contents corrupted in git with passthrough strategy' '
101101
test_when_finished cleanup_git &&
102102
test_when_finished remove_user_cache &&
103-
git -c git-p4.metadataDecodingStrategy=passthrough p4.py clone --dest="$git" //depot@all &&
103+
git -c git-p4.metadataDecodingStrategy=passthrough p4-python3 clone --dest="$git" //depot@all &&
104104
(
105105
cd "$git" &&
106106
git log >actual &&
@@ -114,7 +114,7 @@ test_expect_success 'check latin-1 contents corrupted in git with passthrough st
114114
test_expect_success 'check utf-8 contents with fallback strategy' '
115115
test_when_finished cleanup_git &&
116116
test_when_finished remove_user_cache &&
117-
git -c git-p4.metadataDecodingStrategy=fallback p4.py clone --dest="$git" //depot@all &&
117+
git -c git-p4.metadataDecodingStrategy=fallback p4-python3 clone --dest="$git" //depot@all &&
118118
(
119119
cd "$git" &&
120120
git log >actual &&
@@ -126,7 +126,7 @@ test_expect_success 'check utf-8 contents with fallback strategy' '
126126
test_expect_success 'check latin-1 contents with fallback strategy' '
127127
test_when_finished cleanup_git &&
128128
test_when_finished remove_user_cache &&
129-
git -c git-p4.metadataDecodingStrategy=fallback p4.py clone --dest="$git" //depot@all &&
129+
git -c git-p4.metadataDecodingStrategy=fallback p4-python3 clone --dest="$git" //depot@all &&
130130
(
131131
cd "$git" &&
132132
git log >actual &&
@@ -138,7 +138,7 @@ test_expect_success 'check latin-1 contents with fallback strategy' '
138138
test_expect_success 'check cp-1252 contents with fallback strategy' '
139139
test_when_finished cleanup_git &&
140140
test_when_finished remove_user_cache &&
141-
git -c git-p4.metadataDecodingStrategy=fallback p4.py clone --dest="$git" //depot@all &&
141+
git -c git-p4.metadataDecodingStrategy=fallback p4-python3 clone --dest="$git" //depot@all &&
142142
(
143143
cd "$git" &&
144144
git log >actual &&
@@ -150,7 +150,7 @@ test_expect_success 'check cp-1252 contents with fallback strategy' '
150150
test_expect_success 'check cp850 contents parsed with correct fallback' '
151151
test_when_finished cleanup_git &&
152152
test_when_finished remove_user_cache &&
153-
git -c git-p4.metadataDecodingStrategy=fallback -c git-p4.metadataFallbackEncoding=cp850 p4.py clone --dest="$git" //depot@all &&
153+
git -c git-p4.metadataDecodingStrategy=fallback -c git-p4.metadataFallbackEncoding=cp850 p4-python3 clone --dest="$git" //depot@all &&
154154
(
155155
cd "$git" &&
156156
git log >actual &&
@@ -162,7 +162,7 @@ test_expect_success 'check cp850 contents parsed with correct fallback' '
162162
test_expect_success 'check cp850-only contents escaped when cp1252 is fallback' '
163163
test_when_finished cleanup_git &&
164164
test_when_finished remove_user_cache &&
165-
git -c git-p4.metadataDecodingStrategy=fallback p4.py clone --dest="$git" //depot@all &&
165+
git -c git-p4.metadataDecodingStrategy=fallback p4-python3 clone --dest="$git" //depot@all &&
166166
(
167167
cd "$git" &&
168168
git log >actual &&
@@ -174,7 +174,7 @@ test_expect_success 'check cp850-only contents escaped when cp1252 is fallback'
174174
test_expect_success 'check cp-1252 contents on later sync after clone with fallback strategy' '
175175
test_when_finished cleanup_git &&
176176
test_when_finished remove_user_cache &&
177-
git -c git-p4.metadataDecodingStrategy=fallback p4.py clone --dest="$git" //depot@all &&
177+
git -c git-p4.metadataDecodingStrategy=fallback p4-python3 clone --dest="$git" //depot@all &&
178178
(
179179
cd "$cli" &&
180180
P4USER=cp1252_author &&
@@ -186,7 +186,7 @@ test_expect_success 'check cp-1252 contents on later sync after clone with fallb
186186
(
187187
cd "$git" &&
188188
189-
git p4.py sync --branch=master &&
189+
git p4-python3 sync --branch=master &&
190190
191191
git log p4/master >actual &&
192192
grep "sœme more cp-1252 tæxt" actual &&
@@ -202,7 +202,7 @@ test_expect_success 'check cp-1252 contents on later sync after clone with fallb
202202
test_expect_success 'fallback (both utf-8 and cp-1252 contents handled) is the default with python3' '
203203
test_when_finished cleanup_git &&
204204
test_when_finished remove_user_cache &&
205-
git p4.py clone --dest="$git" //depot@all &&
205+
git p4-python3 clone --dest="$git" //depot@all &&
206206
(
207207
cd "$git" &&
208208
git log >actual &&

0 commit comments

Comments
 (0)