Skip to content

Commit

Permalink
Merge branch 'vr/use-our-perl-in-tests'
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gitster committed Jul 9, 2012
2 parents ee02c2a + ad78585 commit 967abba
Show file tree
Hide file tree
Showing 26 changed files with 65 additions and 44 deletions.
25 changes: 22 additions & 3 deletions t/README
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,25 @@ Don't:
Use test_done instead if you need to stop the tests early (see
"Skipping tests" below).

- use '! git cmd' when you want to make sure the git command exits
with failure in a controlled way by calling "die()". Instead,
use 'test_must_fail git cmd'. This will signal a failure if git
dies in an unexpected way (e.g. segfault).

- use perl without spelling it as "$PERL_PATH". This is to help our
friends on Windows where the platform Perl often adds CR before
the end of line, and they bundle Git with a version of Perl that
does not do so, whose path is specified with $PERL_PATH.

- use sh without spelling it as "$SHELL_PATH", when the script can
be misinterpreted by broken platform shell (e.g. Solaris).

- chdir around in tests. It is not sufficient to chdir to
somewhere and then chdir back to the original location later in
the test, as any intermediate step can fail and abort the test,
causing the next test to start in an unexpected directory. Do so
inside a subshell if necessary.

- Break the TAP output

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

test_expect_success PERL 'I need Perl' "
'$PERL_PATH' -e 'hlagh() if unf_unf()'
"
test_expect_success PERL 'I need Perl' '
"$PERL_PATH" -e "hlagh() if unf_unf()"
'

The advantage of skipping tests like this is that platforms that don't
have the PERL and other optional dependencies get an indication of how
Expand Down
4 changes: 2 additions & 2 deletions t/t1010-mktree.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ test_expect_success 'ls-tree piped to mktree (2)' '
'

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

test_expect_success 'ls-tree output in wrong order given to mktree (2)' '
perl -e "print reverse <>" <top.withsub |
"$PERL_PATH" -e "print reverse <>" <top.withsub |
git mktree >actual &&
test_cmp tree.withsub actual
'
Expand Down
6 changes: 3 additions & 3 deletions t/t3300-funny-names.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ test_expect_success 'ls-files -z does not quote funny filename' '
tabs ," (dq) and spaces
EOF
git ls-files -z >ls-files.z &&
perl -pe "y/\000/\012/" <ls-files.z >current &&
"$PERL_PATH" -pe "y/\000/\012/" <ls-files.z >current &&
test_cmp expected current
'

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

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

Expand Down
2 changes: 1 addition & 1 deletion t/t4014-format-patch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ check_threading () {
(git format-patch --stdout "$@"; echo $? > status.out) |
# Prints everything between the Message-ID and In-Reply-To,
# and replaces all Message-ID-lookalikes by a sequence number
perl -ne '
"$PERL_PATH" -ne '
if (/^(message-id|references|in-reply-to)/i) {
$printing = 1;
} elsif (/^\S/) {
Expand Down
2 changes: 1 addition & 1 deletion t/t4020-diff-external.sh
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ test_expect_success 'no diff with -diff' '
git diff | grep Binary
'

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

test_expect_success 'force diff with "diff"' '
echo >.gitattributes "file diff" &&
Expand Down
2 changes: 1 addition & 1 deletion t/t4029-diff-trailing-space.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ test_expect_success \
git config --bool diff.suppressBlankEmpty true &&
git diff f > actual &&
test_cmp exp actual &&
perl -i.bak -p -e "s/^\$/ /" exp &&
"$PERL_PATH" -i.bak -p -e "s/^\$/ /" exp &&
git config --bool diff.suppressBlankEmpty false &&
git diff f > actual &&
test_cmp exp actual &&
Expand Down
2 changes: 1 addition & 1 deletion t/t4030-diff-textconv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ EOF

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

Expand Down
2 changes: 1 addition & 1 deletion t/t4031-diff-rewrite-binary.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ test_expect_success 'diff --stat counts binary rewrite as 0 lines' '
{
echo "#!$SHELL_PATH"
cat <<'EOF'
perl -e '$/ = undef; $_ = <>; s/./ord($&)/ge; print $_' < "$1"
"$PERL_PATH" -e '$/ = undef; $_ = <>; s/./ord($&)/ge; print $_' < "$1"
EOF
} >dump
chmod +x dump
Expand Down
4 changes: 2 additions & 2 deletions t/t4103-apply-binary.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ test_expect_success 'setup' "
git commit -m 'Initial Version' 2>/dev/null &&
git checkout -b binary &&
perl -pe 'y/x/\000/' <file1 >file3 &&
"$PERL_PATH" -pe 'y/x/\000/' <file1 >file3 &&
cat file3 >file4 &&
git add file2 &&
perl -pe 'y/\000/v/' <file3 >file1 &&
"$PERL_PATH" -pe 'y/\000/v/' <file3 >file1 &&
rm -f file2 &&
git update-index --add --remove file1 file2 file3 file4 &&
git commit -m 'Second Version' &&
Expand Down
4 changes: 2 additions & 2 deletions t/t4116-apply-reverse.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ test_description='git apply in reverse
test_expect_success setup '
for i in a b c d e f g h i j k l m n; do echo $i; done >file1 &&
perl -pe "y/ijk/\\000\\001\\002/" <file1 >file2 &&
"$PERL_PATH" -pe "y/ijk/\\000\\001\\002/" <file1 >file2 &&
git add file1 file2 &&
git commit -m initial &&
git tag initial &&
for i in a b c g h i J K L m o n p q; do echo $i; done >file1 &&
perl -pe "y/mon/\\000\\001\\002/" <file1 >file2 &&
"$PERL_PATH" -pe "y/mon/\\000\\001\\002/" <file1 >file2 &&
git commit -a -m second &&
git tag second &&
Expand Down
8 changes: 4 additions & 4 deletions t/t4200-rerere.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ test_expect_success 'activate rerere, old style (conflicting merge)' '
test_might_fail git config --unset rerere.enabled &&
test_must_fail git merge first &&
sha1=$(perl -pe "s/ .*//" .git/MERGE_RR) &&
sha1=$("$PERL_PATH" -pe "s/ .*//" .git/MERGE_RR) &&
rr=.git/rr-cache/$sha1 &&
grep "^=======\$" $rr/preimage &&
! test -f $rr/postimage &&
Expand All @@ -91,7 +91,7 @@ test_expect_success 'rerere.enabled works, too' '
git reset --hard &&
test_must_fail git merge first &&
sha1=$(perl -pe "s/ .*//" .git/MERGE_RR) &&
sha1=$("$PERL_PATH" -pe "s/ .*//" .git/MERGE_RR) &&
rr=.git/rr-cache/$sha1 &&
grep ^=======$ $rr/preimage
'
Expand All @@ -101,7 +101,7 @@ test_expect_success 'set up rr-cache' '
git config rerere.enabled true &&
git reset --hard &&
test_must_fail git merge first &&
sha1=$(perl -pe "s/ .*//" .git/MERGE_RR) &&
sha1=$("$PERL_PATH" -pe "s/ .*//" .git/MERGE_RR) &&
rr=.git/rr-cache/$sha1
'

Expand Down Expand Up @@ -185,7 +185,7 @@ test_expect_success 'rerere updates postimage timestamp' '

test_expect_success 'rerere clear' '
rm $rr/postimage &&
echo "$sha1 a1" | perl -pe "y/\012/\000/" >.git/MERGE_RR &&
echo "$sha1 a1" | "$PERL_PATH" -pe "y/\012/\000/" >.git/MERGE_RR &&
git rerere clear &&
! test -d $rr
'
Expand Down
8 changes: 4 additions & 4 deletions t/t5300-pack-object.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ TRASH=`pwd`
test_expect_success \
'setup' \
'rm -f .git/index* &&
perl -e "print \"a\" x 4096;" > a &&
perl -e "print \"b\" x 4096;" > b &&
perl -e "print \"c\" x 4096;" > c &&
"$PERL_PATH" -e "print \"a\" x 4096;" > a &&
"$PERL_PATH" -e "print \"b\" x 4096;" > b &&
"$PERL_PATH" -e "print \"c\" x 4096;" > c &&
test-genrandom "seed a" 2097152 > a_big &&
test-genrandom "seed b" 2097152 > b_big &&
git update-index --add a a_big b b_big c &&
Expand Down Expand Up @@ -129,7 +129,7 @@ test_expect_success \
cd "$TRASH"

test_expect_success 'compare delta flavors' '
perl -e '\''
"$PERL_PATH" -e '\''
defined($_ = -s $_) or die for @ARGV;
exit 1 if $ARGV[0] <= $ARGV[1];
'\'' test-2-$packname_2.pack test-3-$packname_3.pack
Expand Down
4 changes: 2 additions & 2 deletions t/t5303-pack-corruption-resilience.sh
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ test_expect_success \
'create_new_pack &&
git prune-packed &&
chmod +w ${pack}.pack &&
perl -i.bak -pe "s/ base /abcdef/" ${pack}.pack &&
"$PERL_PATH" -i.bak -pe "s/ base /abcdef/" ${pack}.pack &&
test_must_fail git cat-file blob $blob_1 > /dev/null &&
test_must_fail git cat-file blob $blob_2 > /dev/null &&
test_must_fail git cat-file blob $blob_3 > /dev/null'
Expand Down Expand Up @@ -155,7 +155,7 @@ test_expect_success \
'create_new_pack &&
git prune-packed &&
chmod +w ${pack}.pack &&
perl -i.bak -pe "s/ delta1 /abcdefgh/" ${pack}.pack &&
"$PERL_PATH" -i.bak -pe "s/ delta1 /abcdefgh/" ${pack}.pack &&
git cat-file blob $blob_1 > /dev/null &&
test_must_fail git cat-file blob $blob_2 > /dev/null &&
test_must_fail git cat-file blob $blob_3 > /dev/null'
Expand Down
2 changes: 1 addition & 1 deletion t/t5532-fetch-proxy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ test_expect_success 'setup remote repo' '
cat >proxy <<'EOF'
#!/bin/sh
echo >&2 "proxying for $*"
cmd=`perl -e '
cmd=`"$PERL_PATH" -e '
read(STDIN, $buf, 4);
my $n = hex($buf) - 4;
read(STDIN, $buf, $n);
Expand Down
2 changes: 1 addition & 1 deletion t/t5551-http-fetch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ test_expect_success EXPENSIVE 'create 50,000 tags in the repo' '
done | git fast-import --export-marks=marks &&
# now assign tags to all the dangling commits we created above
tag=$(perl -e "print \"bla\" x 30") &&
tag=$("$PERL_PATH" -e "print \"bla\" x 30") &&
sed -e "s/^:\(.\+\) \(.\+\)$/\2 refs\/tags\/$tag-\1/" <marks >>packed-refs
)
'
Expand Down
2 changes: 1 addition & 1 deletion t/t6011-rev-list-with-bad-commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ test_expect_success 'verify number of revisions' \

test_expect_success 'corrupt second commit object' \
'
perl -i.bak -pe "s/second commit/socond commit/" .git/objects/pack/*.pack &&
"$PERL_PATH" -i.bak -pe "s/second commit/socond commit/" .git/objects/pack/*.pack &&
test_must_fail git fsck --full
'

Expand Down
4 changes: 2 additions & 2 deletions t/t6013-rev-list-reverse-parents.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ test_expect_success 'set up --reverse example' '

test_expect_success '--reverse --parents --full-history combines correctly' '
git rev-list --parents --full-history master -- foo |
perl -e "print reverse <>" > expected &&
"$PERL_PATH" -e "print reverse <>" > expected &&
git rev-list --reverse --parents --full-history master -- foo \
> actual &&
test_cmp actual expected
'

test_expect_success '--boundary does too' '
git rev-list --boundary --parents --full-history master ^root -- foo |
perl -e "print reverse <>" > expected &&
"$PERL_PATH" -e "print reverse <>" > expected &&
git rev-list --boundary --reverse --parents --full-history \
master ^root -- foo > actual &&
test_cmp actual expected
Expand Down
2 changes: 1 addition & 1 deletion t/t7508-status.sh
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ test_expect_success 'status -s submodule summary (clean submodule)' '

test_expect_success 'status -z implies porcelain' '
git status --porcelain |
perl -pe "s/\012/\000/g" >expect &&
"$PERL_PATH" -pe "s/\012/\000/g" >expect &&
git status -z >output &&
test_cmp expect output
'
Expand Down
2 changes: 1 addition & 1 deletion t/t8006-blame-textconv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ find_blame() {
cat >helper <<'EOF'
#!/bin/sh
grep -q '^bin: ' "$1" || { echo "E: $1 is not \"binary\" file" 1>&2; exit 1; }
perl -p -e 's/^bin: /converted: /' "$1"
"$PERL_PATH" -p -e 's/^bin: /converted: /' "$1"
EOF
chmod +x helper

Expand Down
2 changes: 1 addition & 1 deletion t/t9129-git-svn-i18n-commitencoding.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fi
compare_svn_head_with () {
# extract just the log message and strip out committer info.
# don't use --limit here since svn 1.1.x doesn't have it,
LC_ALL="$a_utf8_locale" svn log `git svn info --url` | perl -w -e '
LC_ALL="$a_utf8_locale" svn log `git svn info --url` | "$PERL_PATH" -w -e '
use bytes;
$/ = ("-"x72) . "\n";
my @x = <STDIN>;
Expand Down
8 changes: 4 additions & 4 deletions t/t9137-git-svn-dcommit-clobber-series.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ test_expect_success '(supposedly) non-conflicting change from SVN' '
test x"`sed -n -e 61p < file`" = x61 &&
svn_cmd co "$svnrepo" tmp &&
(cd tmp &&
perl -i.bak -p -e "s/^58$/5588/" file &&
perl -i.bak -p -e "s/^61$/6611/" file &&
"$PERL_PATH" -i.bak -p -e "s/^58$/5588/" file &&
"$PERL_PATH" -i.bak -p -e "s/^61$/6611/" file &&
poke file &&
test x"`sed -n -e 58p < file`" = x5588 &&
test x"`sed -n -e 61p < file`" = x6611 &&
Expand All @@ -40,8 +40,8 @@ test_expect_success 'some unrelated changes to git' "
test_expect_success 'change file but in unrelated area' "
test x\"\`sed -n -e 4p < file\`\" = x4 &&
test x\"\`sed -n -e 7p < file\`\" = x7 &&
perl -i.bak -p -e 's/^4\$/4444/' file &&
perl -i.bak -p -e 's/^7\$/7777/' file &&
"$PERL_PATH" -i.bak -p -e 's/^4\$/4444/' file &&
"$PERL_PATH" -i.bak -p -e 's/^7\$/7777/' file &&
test x\"\`sed -n -e 4p < file\`\" = x4444 &&
test x\"\`sed -n -e 7p < file\`\" = x7777 &&
git commit -m '4 => 4444, 7 => 7777' file &&
Expand Down
2 changes: 1 addition & 1 deletion t/t9300-fast-import.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test_description='test git fast-import utility'
# This could be written as "head -c $1", but IRIX "head" does not
# support the -c option.
head_c () {
perl -e '
"$PERL_PATH" -e '
my $len = $ARGV[1];
while ($len > 0) {
my $s;
Expand Down
2 changes: 1 addition & 1 deletion t/t9350-fast-export.sh
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ test_expect_success 'fast-export quotes pathnames' '
--cacheinfo 100644 $blob "path with \\backslash" \
--cacheinfo 100644 $blob "path with space" &&
git commit -m addition &&
git ls-files -z -s | perl -0pe "s{\\t}{$&subdir/}" >index &&
git ls-files -z -s | "$PERL_PATH" -0pe "s{\\t}{$&subdir/}" >index &&
git read-tree --empty &&
git update-index -z --index-info <index &&
git commit -m rename &&
Expand Down
2 changes: 1 addition & 1 deletion t/t9810-git-p4-rcs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ test_expect_success 'cope with rcs keyword expansion damage' '
git config git-p4.attemptRCSCleanup true &&
(cd ../cli && p4_append_to_file kwfile1.c) &&
old_lines=$(wc -l <kwfile1.c) &&
perl -n -i -e "print unless m/Revision:/" kwfile1.c &&
"$PERL_PATH" -n -i -e "print unless m/Revision:/" kwfile1.c &&
new_lines=$(wc -l <kwfile1.c) &&
test $new_lines = $(($old_lines - 1)) &&
Expand Down
4 changes: 2 additions & 2 deletions t/test-lib-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ test_decode_color () {
}

nul_to_q () {
perl -pe 'y/\000/Q/'
"$PERL_PATH" -pe 'y/\000/Q/'
}

q_to_nul () {
perl -pe 'y/Q/\000/'
"$PERL_PATH" -pe 'y/Q/\000/'
}

q_to_cr () {
Expand Down
2 changes: 2 additions & 0 deletions t/test-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,8 @@ export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_ATTR_NOSYSTEM

. "$GIT_BUILD_DIR"/GIT-BUILD-OPTIONS

export PERL_PATH

if test -z "$GIT_TEST_CMP"
then
if test -n "$GIT_TEST_CMP_USE_COPIED_CONTEXT"
Expand Down

0 comments on commit 967abba

Please sign in to comment.