Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge branch 'vr/use-our-perl-in-tests'

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...
commit 967abba7169ad10eff841fe32b70f3e7a1126b63 2 parents ee02c2a + ad78585
Junio C Hamano authored
25  t/README
@@ -307,6 +307,25 @@ Don't:
307 307
    Use test_done instead if you need to stop the tests early (see
308 308
    "Skipping tests" below).
309 309
 
  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
+
310 329
  - Break the TAP output
311 330
 
312 331
    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
342 361
 of the test_* functions (see the "Test harness library" section
343 362
 below), e.g.:
344 363
 
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
+    '
348 367
 
349 368
 The advantage of skipping tests like this is that platforms that don't
350 369
 have the PERL and other optional dependencies get an indication of how
4  t/t1010-mktree.sh
@@ -42,13 +42,13 @@ test_expect_success 'ls-tree piped to mktree (2)' '
42 42
 '
43 43
 
44 44
 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 |
46 46
 	git mktree >actual &&
47 47
 	test_cmp tree actual
48 48
 '
49 49
 
50 50
 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 |
52 52
 	git mktree >actual &&
53 53
 	test_cmp tree.withsub actual
54 54
 '
6  t/t3300-funny-names.sh
@@ -71,7 +71,7 @@ test_expect_success 'ls-files -z does not quote funny filename' '
71 71
 	tabs	," (dq) and spaces
72 72
 	EOF
73 73
 	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 &&
75 75
 	test_cmp expected current
76 76
 '
77 77
 
@@ -108,7 +108,7 @@ test_expect_success 'diff-index -z does not quote funny filename' '
108 108
 	tabs	," (dq) and spaces
109 109
 	EOF
110 110
 	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 &&
112 112
 	test_cmp expected current
113 113
 '
114 114
 
@@ -118,7 +118,7 @@ test_expect_success 'diff-tree -z does not quote funny filename' '
118 118
 	tabs	," (dq) and spaces
119 119
 	EOF
120 120
 	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 &&
122 122
 	test_cmp expected current
123 123
 '
124 124
 
2  t/t4014-format-patch.sh
@@ -243,7 +243,7 @@ check_threading () {
243 243
 	(git format-patch --stdout "$@"; echo $? > status.out) |
244 244
 	# Prints everything between the Message-ID and In-Reply-To,
245 245
 	# and replaces all Message-ID-lookalikes by a sequence number
246  
-	perl -ne '
  246
+	"$PERL_PATH" -ne '
247 247
 		if (/^(message-id|references|in-reply-to)/i) {
248 248
 			$printing = 1;
249 249
 		} elsif (/^\S/) {
2  t/t4020-diff-external.sh
@@ -118,7 +118,7 @@ test_expect_success 'no diff with -diff' '
118 118
 	git diff | grep Binary
119 119
 '
120 120
 
121  
-echo NULZbetweenZwords | perl -pe 'y/Z/\000/' > file
  121
+echo NULZbetweenZwords | "$PERL_PATH" -pe 'y/Z/\000/' > file
122 122
 
123 123
 test_expect_success 'force diff with "diff"' '
124 124
 	echo >.gitattributes "file diff" &&
2  t/t4029-diff-trailing-space.sh
@@ -27,7 +27,7 @@ test_expect_success \
27 27
      git config --bool diff.suppressBlankEmpty true &&
28 28
      git diff f > actual &&
29 29
      test_cmp exp actual &&
30  
-     perl -i.bak -p -e "s/^\$/ /" exp &&
  30
+     "$PERL_PATH" -i.bak -p -e "s/^\$/ /" exp &&
31 31
      git config --bool diff.suppressBlankEmpty false &&
32 32
      git diff f > actual &&
33 33
      test_cmp exp actual &&
2  t/t4030-diff-textconv.sh
@@ -21,7 +21,7 @@ EOF
21 21
 
22 22
 cat >hexdump <<'EOF'
23 23
 #!/bin/sh
24  
-perl -e '$/ = undef; $_ = <>; s/./ord($&)/ge; print $_' < "$1"
  24
+"$PERL_PATH" -e '$/ = undef; $_ = <>; s/./ord($&)/ge; print $_' < "$1"
25 25
 EOF
26 26
 chmod +x hexdump
27 27
 
2  t/t4031-diff-rewrite-binary.sh
@@ -60,7 +60,7 @@ test_expect_success 'diff --stat counts binary rewrite as 0 lines' '
60 60
 {
61 61
 	echo "#!$SHELL_PATH"
62 62
 	cat <<'EOF'
63  
-perl -e '$/ = undef; $_ = <>; s/./ord($&)/ge; print $_' < "$1"
  63
+"$PERL_PATH" -e '$/ = undef; $_ = <>; s/./ord($&)/ge; print $_' < "$1"
64 64
 EOF
65 65
 } >dump
66 66
 chmod +x dump
4  t/t4103-apply-binary.sh
@@ -25,10 +25,10 @@ test_expect_success 'setup' "
25 25
 	git commit -m 'Initial Version' 2>/dev/null &&
26 26
 
27 27
 	git checkout -b binary &&
28  
-	perl -pe 'y/x/\000/' <file1 >file3 &&
  28
+	"$PERL_PATH" -pe 'y/x/\000/' <file1 >file3 &&
29 29
 	cat file3 >file4 &&
30 30
 	git add file2 &&
31  
-	perl -pe 'y/\000/v/' <file3 >file1 &&
  31
+	"$PERL_PATH" -pe 'y/\000/v/' <file3 >file1 &&
32 32
 	rm -f file2 &&
33 33
 	git update-index --add --remove file1 file2 file3 file4 &&
34 34
 	git commit -m 'Second Version' &&
4  t/t4116-apply-reverse.sh
@@ -12,14 +12,14 @@ test_description='git apply in reverse
12 12
 test_expect_success setup '
13 13
 
14 14
 	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 &&
16 16
 
17 17
 	git add file1 file2 &&
18 18
 	git commit -m initial &&
19 19
 	git tag initial &&
20 20
 
21 21
 	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 &&
23 23
 
24 24
 	git commit -a -m second &&
25 25
 	git tag second &&
8  t/t4200-rerere.sh
@@ -78,7 +78,7 @@ test_expect_success 'activate rerere, old style (conflicting merge)' '
78 78
 	test_might_fail git config --unset rerere.enabled &&
79 79
 	test_must_fail git merge first &&
80 80
 
81  
-	sha1=$(perl -pe "s/	.*//" .git/MERGE_RR) &&
  81
+	sha1=$("$PERL_PATH" -pe "s/	.*//" .git/MERGE_RR) &&
82 82
 	rr=.git/rr-cache/$sha1 &&
83 83
 	grep "^=======\$" $rr/preimage &&
84 84
 	! test -f $rr/postimage &&
@@ -91,7 +91,7 @@ test_expect_success 'rerere.enabled works, too' '
91 91
 	git reset --hard &&
92 92
 	test_must_fail git merge first &&
93 93
 
94  
-	sha1=$(perl -pe "s/	.*//" .git/MERGE_RR) &&
  94
+	sha1=$("$PERL_PATH" -pe "s/	.*//" .git/MERGE_RR) &&
95 95
 	rr=.git/rr-cache/$sha1 &&
96 96
 	grep ^=======$ $rr/preimage
97 97
 '
@@ -101,7 +101,7 @@ test_expect_success 'set up rr-cache' '
101 101
 	git config rerere.enabled true &&
102 102
 	git reset --hard &&
103 103
 	test_must_fail git merge first &&
104  
-	sha1=$(perl -pe "s/	.*//" .git/MERGE_RR) &&
  104
+	sha1=$("$PERL_PATH" -pe "s/	.*//" .git/MERGE_RR) &&
105 105
 	rr=.git/rr-cache/$sha1
106 106
 '
107 107
 
@@ -185,7 +185,7 @@ test_expect_success 'rerere updates postimage timestamp' '
185 185
 
186 186
 test_expect_success 'rerere clear' '
187 187
 	rm $rr/postimage &&
188  
-	echo "$sha1	a1" | perl -pe "y/\012/\000/" >.git/MERGE_RR &&
  188
+	echo "$sha1	a1" | "$PERL_PATH" -pe "y/\012/\000/" >.git/MERGE_RR &&
189 189
 	git rerere clear &&
190 190
 	! test -d $rr
191 191
 '
8  t/t5300-pack-object.sh
@@ -13,9 +13,9 @@ TRASH=`pwd`
13 13
 test_expect_success \
14 14
     'setup' \
15 15
     'rm -f .git/index* &&
16  
-     perl -e "print \"a\" x 4096;" > a &&
17  
-     perl -e "print \"b\" x 4096;" > b &&
18  
-     perl -e "print \"c\" x 4096;" > c &&
  16
+     "$PERL_PATH" -e "print \"a\" x 4096;" > a &&
  17
+     "$PERL_PATH" -e "print \"b\" x 4096;" > b &&
  18
+     "$PERL_PATH" -e "print \"c\" x 4096;" > c &&
19 19
      test-genrandom "seed a" 2097152 > a_big &&
20 20
      test-genrandom "seed b" 2097152 > b_big &&
21 21
      git update-index --add a a_big b b_big c &&
@@ -129,7 +129,7 @@ test_expect_success \
129 129
 cd "$TRASH"
130 130
 
131 131
 test_expect_success 'compare delta flavors' '
132  
-	perl -e '\''
  132
+	"$PERL_PATH" -e '\''
133 133
 		defined($_ = -s $_) or die for @ARGV;
134 134
 		exit 1 if $ARGV[0] <= $ARGV[1];
135 135
 	'\'' test-2-$packname_2.pack test-3-$packname_3.pack
4  t/t5303-pack-corruption-resilience.sh
@@ -98,7 +98,7 @@ test_expect_success \
98 98
     'create_new_pack &&
99 99
      git prune-packed &&
100 100
      chmod +w ${pack}.pack &&
101  
-     perl -i.bak -pe "s/ base /abcdef/" ${pack}.pack &&
  101
+     "$PERL_PATH" -i.bak -pe "s/ base /abcdef/" ${pack}.pack &&
102 102
      test_must_fail git cat-file blob $blob_1 > /dev/null &&
103 103
      test_must_fail git cat-file blob $blob_2 > /dev/null &&
104 104
      test_must_fail git cat-file blob $blob_3 > /dev/null'
@@ -155,7 +155,7 @@ test_expect_success \
155 155
     'create_new_pack &&
156 156
      git prune-packed &&
157 157
      chmod +w ${pack}.pack &&
158  
-     perl -i.bak -pe "s/ delta1 /abcdefgh/" ${pack}.pack &&
  158
+     "$PERL_PATH" -i.bak -pe "s/ delta1 /abcdefgh/" ${pack}.pack &&
159 159
      git cat-file blob $blob_1 > /dev/null &&
160 160
      test_must_fail git cat-file blob $blob_2 > /dev/null &&
161 161
      test_must_fail git cat-file blob $blob_3 > /dev/null'
2  t/t5532-fetch-proxy.sh
@@ -15,7 +15,7 @@ test_expect_success 'setup remote repo' '
15 15
 cat >proxy <<'EOF'
16 16
 #!/bin/sh
17 17
 echo >&2 "proxying for $*"
18  
-cmd=`perl -e '
  18
+cmd=`"$PERL_PATH" -e '
19 19
 	read(STDIN, $buf, 4);
20 20
 	my $n = hex($buf) - 4;
21 21
 	read(STDIN, $buf, $n);
2  t/t5551-http-fetch.sh
@@ -130,7 +130,7 @@ test_expect_success EXPENSIVE 'create 50,000 tags in the repo' '
130 130
 	done | git fast-import --export-marks=marks &&
131 131
 
132 132
 	# now assign tags to all the dangling commits we created above
133  
-	tag=$(perl -e "print \"bla\" x 30") &&
  133
+	tag=$("$PERL_PATH" -e "print \"bla\" x 30") &&
134 134
 	sed -e "s/^:\(.\+\) \(.\+\)$/\2 refs\/tags\/$tag-\1/" <marks >>packed-refs
135 135
 	)
136 136
 '
2  t/t6011-rev-list-with-bad-commit.sh
@@ -37,7 +37,7 @@ test_expect_success 'verify number of revisions' \
37 37
 
38 38
 test_expect_success 'corrupt second commit object' \
39 39
    '
40  
-   perl -i.bak -pe "s/second commit/socond commit/" .git/objects/pack/*.pack &&
  40
+   "$PERL_PATH" -i.bak -pe "s/second commit/socond commit/" .git/objects/pack/*.pack &&
41 41
    test_must_fail git fsck --full
42 42
    '
43 43
 
4  t/t6013-rev-list-reverse-parents.sh
@@ -25,7 +25,7 @@ test_expect_success 'set up --reverse example' '
25 25
 
26 26
 test_expect_success '--reverse --parents --full-history combines correctly' '
27 27
 	git rev-list --parents --full-history master -- foo |
28  
-		perl -e "print reverse <>" > expected &&
  28
+		"$PERL_PATH" -e "print reverse <>" > expected &&
29 29
 	git rev-list --reverse --parents --full-history master -- foo \
30 30
 		> actual &&
31 31
 	test_cmp actual expected
@@ -33,7 +33,7 @@ test_expect_success '--reverse --parents --full-history combines correctly' '
33 33
 
34 34
 test_expect_success '--boundary does too' '
35 35
 	git rev-list --boundary --parents --full-history master ^root -- foo |
36  
-		perl -e "print reverse <>" > expected &&
  36
+		"$PERL_PATH" -e "print reverse <>" > expected &&
37 37
 	git rev-list --boundary --reverse --parents --full-history \
38 38
 		master ^root -- foo > actual &&
39 39
 	test_cmp actual expected
2  t/t7508-status.sh
@@ -941,7 +941,7 @@ test_expect_success 'status -s submodule summary (clean submodule)' '
941 941
 
942 942
 test_expect_success 'status -z implies porcelain' '
943 943
 	git status --porcelain |
944  
-	perl -pe "s/\012/\000/g" >expect &&
  944
+	"$PERL_PATH" -pe "s/\012/\000/g" >expect &&
945 945
 	git status -z >output &&
946 946
 	test_cmp expect output
947 947
 '
2  t/t8006-blame-textconv.sh
@@ -10,7 +10,7 @@ find_blame() {
10 10
 cat >helper <<'EOF'
11 11
 #!/bin/sh
12 12
 grep -q '^bin: ' "$1" || { echo "E: $1 is not \"binary\" file" 1>&2; exit 1; }
13  
-perl -p -e 's/^bin: /converted: /' "$1"
  13
+"$PERL_PATH" -p -e 's/^bin: /converted: /' "$1"
14 14
 EOF
15 15
 chmod +x helper
16 16
 
2  t/t9129-git-svn-i18n-commitencoding.sh
@@ -29,7 +29,7 @@ fi
29 29
 compare_svn_head_with () {
30 30
 	# extract just the log message and strip out committer info.
31 31
 	# don't use --limit here since svn 1.1.x doesn't have it,
32  
-	LC_ALL="$a_utf8_locale" svn log `git svn info --url` | perl -w -e '
  32
+	LC_ALL="$a_utf8_locale" svn log `git svn info --url` | "$PERL_PATH" -w -e '
33 33
 		use bytes;
34 34
 		$/ = ("-"x72) . "\n";
35 35
 		my @x = <STDIN>;
8  t/t9137-git-svn-dcommit-clobber-series.sh
@@ -20,8 +20,8 @@ test_expect_success '(supposedly) non-conflicting change from SVN' '
20 20
 	test x"`sed -n -e 61p < file`" = x61 &&
21 21
 	svn_cmd co "$svnrepo" tmp &&
22 22
 	(cd tmp &&
23  
-		perl -i.bak -p -e "s/^58$/5588/" file &&
24  
-		perl -i.bak -p -e "s/^61$/6611/" file &&
  23
+		"$PERL_PATH" -i.bak -p -e "s/^58$/5588/" file &&
  24
+		"$PERL_PATH" -i.bak -p -e "s/^61$/6611/" file &&
25 25
 		poke file &&
26 26
 		test x"`sed -n -e 58p < file`" = x5588 &&
27 27
 		test x"`sed -n -e 61p < file`" = x6611 &&
@@ -40,8 +40,8 @@ test_expect_success 'some unrelated changes to git' "
40 40
 test_expect_success 'change file but in unrelated area' "
41 41
 	test x\"\`sed -n -e 4p < file\`\" = x4 &&
42 42
 	test x\"\`sed -n -e 7p < file\`\" = x7 &&
43  
-	perl -i.bak -p -e 's/^4\$/4444/' file &&
44  
-	perl -i.bak -p -e 's/^7\$/7777/' file &&
  43
+	"$PERL_PATH" -i.bak -p -e 's/^4\$/4444/' file &&
  44
+	"$PERL_PATH" -i.bak -p -e 's/^7\$/7777/' file &&
45 45
 	test x\"\`sed -n -e 4p < file\`\" = x4444 &&
46 46
 	test x\"\`sed -n -e 7p < file\`\" = x7777 &&
47 47
 	git commit -m '4 => 4444, 7 => 7777' file &&
2  t/t9300-fast-import.sh
@@ -12,7 +12,7 @@ test_description='test git fast-import utility'
12 12
 # This could be written as "head -c $1", but IRIX "head" does not
13 13
 # support the -c option.
14 14
 head_c () {
15  
-	perl -e '
  15
+	"$PERL_PATH" -e '
16 16
 		my $len = $ARGV[1];
17 17
 		while ($len > 0) {
18 18
 			my $s;
2  t/t9350-fast-export.sh
@@ -424,7 +424,7 @@ test_expect_success 'fast-export quotes pathnames' '
424 424
 		--cacheinfo 100644 $blob "path with \\backslash" \
425 425
 		--cacheinfo 100644 $blob "path with space" &&
426 426
 	 git commit -m addition &&
427  
-	 git ls-files -z -s | perl -0pe "s{\\t}{$&subdir/}" >index &&
  427
+	 git ls-files -z -s | "$PERL_PATH" -0pe "s{\\t}{$&subdir/}" >index &&
428 428
 	 git read-tree --empty &&
429 429
 	 git update-index -z --index-info <index &&
430 430
 	 git commit -m rename &&
2  t/t9810-git-p4-rcs.sh
@@ -246,7 +246,7 @@ test_expect_success 'cope with rcs keyword expansion damage' '
246 246
 		git config git-p4.attemptRCSCleanup true &&
247 247
 		(cd ../cli && p4_append_to_file kwfile1.c) &&
248 248
 		old_lines=$(wc -l <kwfile1.c) &&
249  
-		perl -n -i -e "print unless m/Revision:/" kwfile1.c &&
  249
+		"$PERL_PATH" -n -i -e "print unless m/Revision:/" kwfile1.c &&
250 250
 		new_lines=$(wc -l <kwfile1.c) &&
251 251
 		test $new_lines = $(($old_lines - 1)) &&
252 252
 
4  t/test-lib-functions.sh
@@ -76,11 +76,11 @@ test_decode_color () {
76 76
 }
77 77
 
78 78
 nul_to_q () {
79  
-	perl -pe 'y/\000/Q/'
  79
+	"$PERL_PATH" -pe 'y/\000/Q/'
80 80
 }
81 81
 
82 82
 q_to_nul () {
83  
-	perl -pe 'y/Q/\000/'
  83
+	"$PERL_PATH" -pe 'y/Q/\000/'
84 84
 }
85 85
 
86 86
 q_to_cr () {
2  t/test-lib.sh
@@ -494,6 +494,8 @@ export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_ATTR_NOSYSTEM
494 494
 
495 495
 . "$GIT_BUILD_DIR"/GIT-BUILD-OPTIONS
496 496
 
  497
+export PERL_PATH
  498
+
497 499
 if test -z "$GIT_TEST_CMP"
498 500
 then
499 501
 	if test -n "$GIT_TEST_CMP_USE_COPIED_CONTEXT"

0 notes on commit 967abba

Please sign in to comment.
Something went wrong with that request. Please try again.