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 <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Dec 13, 2024 at 11:41 UTC
78ad7291df6185df54d86908bd268bfeffe0c13d
2 files changed
+50
-50
t/t9835-git-p4-metadata-encoding-python2.sh
+25
-25
@@ -8,29 +8,29 @@ failing, and produces maximally sane output in git.'
8
9
. ./lib-git-p4.sh
10
11
-python_target_version='2'
12
-
11
###############################
12
## SECTION REPEATED IN t9836 ##
13
###############################
14
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"
20
then
21
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
28
fi
29
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
32
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"
34
test_done
35
fi
36
@@ -81,14 +81,14 @@ test_expect_success 'init depot' '
81
test_expect_success 'clone non-utf8 repo with strict encoding' '
82
test_when_finished cleanup_git &&
83
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 &&
85
grep "Decoding perforce metadata failed!" err
86
'
87
88
test_expect_success 'check utf-8 contents with passthrough strategy' '
89
test_when_finished cleanup_git &&
90
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 &&
92
(
93
cd "$git" &&
94
git log >actual &&
@@ -100,7 +100,7 @@ test_expect_success 'check utf-8 contents with passthrough strategy' '
100
test_expect_success 'check latin-1 contents corrupted in git with passthrough strategy' '
101
test_when_finished cleanup_git &&
102
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 &&
104
(
105
cd "$git" &&
106
git log >actual &&
@@ -114,7 +114,7 @@ test_expect_success 'check latin-1 contents corrupted in git with passthrough st
114
test_expect_success 'check utf-8 contents with fallback strategy' '
115
test_when_finished cleanup_git &&
116
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 &&
118
(
119
cd "$git" &&
120
git log >actual &&
@@ -126,7 +126,7 @@ test_expect_success 'check utf-8 contents with fallback strategy' '
126
test_expect_success 'check latin-1 contents with fallback strategy' '
127
test_when_finished cleanup_git &&
128
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 &&
130
(
131
cd "$git" &&
132
git log >actual &&
@@ -138,7 +138,7 @@ test_expect_success 'check latin-1 contents with fallback strategy' '
138
test_expect_success 'check cp-1252 contents with fallback strategy' '
139
test_when_finished cleanup_git &&
140
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 &&
142
(
143
cd "$git" &&
144
git log >actual &&
@@ -150,7 +150,7 @@ test_expect_success 'check cp-1252 contents with fallback strategy' '
150
test_expect_success 'check cp850 contents parsed with correct fallback' '
151
test_when_finished cleanup_git &&
152
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 &&
154
(
155
cd "$git" &&
156
git log >actual &&
@@ -162,7 +162,7 @@ test_expect_success 'check cp850 contents parsed with correct fallback' '
162
test_expect_success 'check cp850-only contents escaped when cp1252 is fallback' '
163
test_when_finished cleanup_git &&
164
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 &&
166
(
167
cd "$git" &&
168
git log >actual &&
@@ -174,7 +174,7 @@ test_expect_success 'check cp850-only contents escaped when cp1252 is fallback'
174
test_expect_success 'check cp-1252 contents on later sync after clone with fallback strategy' '
175
test_when_finished cleanup_git &&
176
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 &&
178
(
179
cd "$cli" &&
180
P4USER=cp1252_author &&
@@ -186,7 +186,7 @@ test_expect_success 'check cp-1252 contents on later sync after clone with fallb
186
(
187
cd "$git" &&
188
189
- git p4.py sync --branch=master &&
189
+ git p4-python2 sync --branch=master &&
190
191
git log p4/master >actual &&
192
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
201
test_expect_success 'passthrough (latin-1 contents corrupted in git) is the default with python2' '
202
test_when_finished cleanup_git &&
203
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 &&
205
(
206
cd "$git" &&
207
git log >actual &&
t/t9836-git-p4-metadata-encoding-python3.sh
+25
-25
@@ -8,29 +8,29 @@ failing, and produces maximally sane output in git.'
8
9
. ./lib-git-p4.sh
10
11
-python_target_version='3'
12
-
11
###############################
12
## SECTION REPEATED IN t9835 ##
13
###############################
14
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"
20
then
21
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
28
fi
29
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
32
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"
34
test_done
35
fi
36
@@ -81,14 +81,14 @@ test_expect_success 'init depot' '
81
test_expect_success 'clone non-utf8 repo with strict encoding' '
82
test_when_finished cleanup_git &&
83
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 &&
85
grep "Decoding perforce metadata failed!" err
86
'
87
88
test_expect_success 'check utf-8 contents with passthrough strategy' '
89
test_when_finished cleanup_git &&
90
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 &&
92
(
93
cd "$git" &&
94
git log >actual &&
@@ -100,7 +100,7 @@ test_expect_success 'check utf-8 contents with passthrough strategy' '
100
test_expect_success 'check latin-1 contents corrupted in git with passthrough strategy' '
101
test_when_finished cleanup_git &&
102
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 &&
104
(
105
cd "$git" &&
106
git log >actual &&
@@ -114,7 +114,7 @@ test_expect_success 'check latin-1 contents corrupted in git with passthrough st
114
test_expect_success 'check utf-8 contents with fallback strategy' '
115
test_when_finished cleanup_git &&
116
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 &&
118
(
119
cd "$git" &&
120
git log >actual &&
@@ -126,7 +126,7 @@ test_expect_success 'check utf-8 contents with fallback strategy' '
126
test_expect_success 'check latin-1 contents with fallback strategy' '
127
test_when_finished cleanup_git &&
128
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 &&
130
(
131
cd "$git" &&
132
git log >actual &&
@@ -138,7 +138,7 @@ test_expect_success 'check latin-1 contents with fallback strategy' '
138
test_expect_success 'check cp-1252 contents with fallback strategy' '
139
test_when_finished cleanup_git &&
140
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 &&
142
(
143
cd "$git" &&
144
git log >actual &&
@@ -150,7 +150,7 @@ test_expect_success 'check cp-1252 contents with fallback strategy' '
150
test_expect_success 'check cp850 contents parsed with correct fallback' '
151
test_when_finished cleanup_git &&
152
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 &&
154
(
155
cd "$git" &&
156
git log >actual &&
@@ -162,7 +162,7 @@ test_expect_success 'check cp850 contents parsed with correct fallback' '
162
test_expect_success 'check cp850-only contents escaped when cp1252 is fallback' '
163
test_when_finished cleanup_git &&
164
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 &&
166
(
167
cd "$git" &&
168
git log >actual &&
@@ -174,7 +174,7 @@ test_expect_success 'check cp850-only contents escaped when cp1252 is fallback'
174
test_expect_success 'check cp-1252 contents on later sync after clone with fallback strategy' '
175
test_when_finished cleanup_git &&
176
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 &&
178
(
179
cd "$cli" &&
180
P4USER=cp1252_author &&
@@ -186,7 +186,7 @@ test_expect_success 'check cp-1252 contents on later sync after clone with fallb
186
(
187
cd "$git" &&
188
189
- git p4.py sync --branch=master &&
189
+ git p4-python3 sync --branch=master &&
190
191
git log p4/master >actual &&
192
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
202
test_expect_success 'fallback (both utf-8 and cp-1252 contents handled) is the default with python3' '
203
test_when_finished cleanup_git &&
204
test_when_finished remove_user_cache &&
205
- git p4.py clone --dest="$git" //depot@all &&
205
+ git p4-python3 clone --dest="$git" //depot@all &&
206
(
207
cd "$git" &&
208
git log >actual &&