Skip to content

Commit bb3ed29

Browse files
committed
Merge branch 'vr/use-our-perl-in-tests' into maint
Some implementations of Perl terminates "lines" with CRLF even when the script is operating on just a sequence of bytes. Make sure to use "$PERL_PATH", the version of Perl the user told Git to use, in our tests to avoid unnecessary breakages in tests. * vr/use-our-perl-in-tests: t/README: add a bit more Don'ts tests: enclose $PERL_PATH in double quotes t/test-lib.sh: export PERL_PATH for use in scripts t: Replace 'perl' by $PERL_PATH
2 parents 8d141a1 + ad78585 commit bb3ed29

26 files changed

+65
-44
lines changed

t/README

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,25 @@ Don't:
307307
Use test_done instead if you need to stop the tests early (see
308308
"Skipping tests" below).
309309

310+
- use '! git cmd' when you want to make sure the git command exits
311+
with failure in a controlled way by calling "die()". Instead,
312+
use 'test_must_fail git cmd'. This will signal a failure if git
313+
dies in an unexpected way (e.g. segfault).
314+
315+
- use perl without spelling it as "$PERL_PATH". This is to help our
316+
friends on Windows where the platform Perl often adds CR before
317+
the end of line, and they bundle Git with a version of Perl that
318+
does not do so, whose path is specified with $PERL_PATH.
319+
320+
- use sh without spelling it as "$SHELL_PATH", when the script can
321+
be misinterpreted by broken platform shell (e.g. Solaris).
322+
323+
- chdir around in tests. It is not sufficient to chdir to
324+
somewhere and then chdir back to the original location later in
325+
the test, as any intermediate step can fail and abort the test,
326+
causing the next test to start in an unexpected directory. Do so
327+
inside a subshell if necessary.
328+
310329
- Break the TAP output
311330

312331
The raw output from your test may be interpreted by a TAP harness. TAP
@@ -342,9 +361,9 @@ If you need to skip tests you should do so by using the three-arg form
342361
of the test_* functions (see the "Test harness library" section
343362
below), e.g.:
344363

345-
test_expect_success PERL 'I need Perl' "
346-
'$PERL_PATH' -e 'hlagh() if unf_unf()'
347-
"
364+
test_expect_success PERL 'I need Perl' '
365+
"$PERL_PATH" -e "hlagh() if unf_unf()"
366+
'
348367

349368
The advantage of skipping tests like this is that platforms that don't
350369
have the PERL and other optional dependencies get an indication of how

t/t1010-mktree.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ test_expect_success 'ls-tree piped to mktree (2)' '
4242
'
4343

4444
test_expect_success 'ls-tree output in wrong order given to mktree (1)' '
45-
perl -e "print reverse <>" <top |
45+
"$PERL_PATH" -e "print reverse <>" <top |
4646
git mktree >actual &&
4747
test_cmp tree actual
4848
'
4949

5050
test_expect_success 'ls-tree output in wrong order given to mktree (2)' '
51-
perl -e "print reverse <>" <top.withsub |
51+
"$PERL_PATH" -e "print reverse <>" <top.withsub |
5252
git mktree >actual &&
5353
test_cmp tree.withsub actual
5454
'

t/t3300-funny-names.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ test_expect_success 'ls-files -z does not quote funny filename' '
7171
tabs ," (dq) and spaces
7272
EOF
7373
git ls-files -z >ls-files.z &&
74-
perl -pe "y/\000/\012/" <ls-files.z >current &&
74+
"$PERL_PATH" -pe "y/\000/\012/" <ls-files.z >current &&
7575
test_cmp expected current
7676
'
7777

@@ -108,7 +108,7 @@ test_expect_success 'diff-index -z does not quote funny filename' '
108108
tabs ," (dq) and spaces
109109
EOF
110110
git diff-index -z --name-status $t0 >diff-index.z &&
111-
perl -pe "y/\000/\012/" <diff-index.z >current &&
111+
"$PERL_PATH" -pe "y/\000/\012/" <diff-index.z >current &&
112112
test_cmp expected current
113113
'
114114

@@ -118,7 +118,7 @@ test_expect_success 'diff-tree -z does not quote funny filename' '
118118
tabs ," (dq) and spaces
119119
EOF
120120
git diff-tree -z --name-status $t0 $t1 >diff-tree.z &&
121-
perl -pe y/\\000/\\012/ <diff-tree.z >current &&
121+
"$PERL_PATH" -pe y/\\000/\\012/ <diff-tree.z >current &&
122122
test_cmp expected current
123123
'
124124

t/t4014-format-patch.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ check_threading () {
243243
(git format-patch --stdout "$@"; echo $? > status.out) |
244244
# Prints everything between the Message-ID and In-Reply-To,
245245
# and replaces all Message-ID-lookalikes by a sequence number
246-
perl -ne '
246+
"$PERL_PATH" -ne '
247247
if (/^(message-id|references|in-reply-to)/i) {
248248
$printing = 1;
249249
} elsif (/^\S/) {

t/t4020-diff-external.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ test_expect_success 'no diff with -diff' '
118118
git diff | grep Binary
119119
'
120120

121-
echo NULZbetweenZwords | perl -pe 'y/Z/\000/' > file
121+
echo NULZbetweenZwords | "$PERL_PATH" -pe 'y/Z/\000/' > file
122122

123123
test_expect_success 'force diff with "diff"' '
124124
echo >.gitattributes "file diff" &&

t/t4029-diff-trailing-space.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ test_expect_success \
2727
git config --bool diff.suppressBlankEmpty true &&
2828
git diff f > actual &&
2929
test_cmp exp actual &&
30-
perl -i.bak -p -e "s/^\$/ /" exp &&
30+
"$PERL_PATH" -i.bak -p -e "s/^\$/ /" exp &&
3131
git config --bool diff.suppressBlankEmpty false &&
3232
git diff f > actual &&
3333
test_cmp exp actual &&

t/t4030-diff-textconv.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ EOF
2121

2222
cat >hexdump <<'EOF'
2323
#!/bin/sh
24-
perl -e '$/ = undef; $_ = <>; s/./ord($&)/ge; print $_' < "$1"
24+
"$PERL_PATH" -e '$/ = undef; $_ = <>; s/./ord($&)/ge; print $_' < "$1"
2525
EOF
2626
chmod +x hexdump
2727

t/t4031-diff-rewrite-binary.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ test_expect_success 'diff --stat counts binary rewrite as 0 lines' '
6060
{
6161
echo "#!$SHELL_PATH"
6262
cat <<'EOF'
63-
perl -e '$/ = undef; $_ = <>; s/./ord($&)/ge; print $_' < "$1"
63+
"$PERL_PATH" -e '$/ = undef; $_ = <>; s/./ord($&)/ge; print $_' < "$1"
6464
EOF
6565
} >dump
6666
chmod +x dump

t/t4103-apply-binary.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ test_expect_success 'setup' "
2525
git commit -m 'Initial Version' 2>/dev/null &&
2626
2727
git checkout -b binary &&
28-
perl -pe 'y/x/\000/' <file1 >file3 &&
28+
"$PERL_PATH" -pe 'y/x/\000/' <file1 >file3 &&
2929
cat file3 >file4 &&
3030
git add file2 &&
31-
perl -pe 'y/\000/v/' <file3 >file1 &&
31+
"$PERL_PATH" -pe 'y/\000/v/' <file3 >file1 &&
3232
rm -f file2 &&
3333
git update-index --add --remove file1 file2 file3 file4 &&
3434
git commit -m 'Second Version' &&

t/t4116-apply-reverse.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ test_description='git apply in reverse
1212
test_expect_success setup '
1313
1414
for i in a b c d e f g h i j k l m n; do echo $i; done >file1 &&
15-
perl -pe "y/ijk/\\000\\001\\002/" <file1 >file2 &&
15+
"$PERL_PATH" -pe "y/ijk/\\000\\001\\002/" <file1 >file2 &&
1616
1717
git add file1 file2 &&
1818
git commit -m initial &&
1919
git tag initial &&
2020
2121
for i in a b c g h i J K L m o n p q; do echo $i; done >file1 &&
22-
perl -pe "y/mon/\\000\\001\\002/" <file1 >file2 &&
22+
"$PERL_PATH" -pe "y/mon/\\000\\001\\002/" <file1 >file2 &&
2323
2424
git commit -a -m second &&
2525
git tag second &&

0 commit comments

Comments
 (0)