Skip to content

Commit a4d4e32

Browse files
prertikgitster
authored andcommitted
test: avoid pipes in git related commands for test
Avoid using pipes downstream of Git commands since the exit codes of commands upstream of pipes get swallowed, thus potentially hiding failure of those commands. Instead, capture Git command output to a file and apply the downstream command(s) to that file. Signed-off-by: Pratik Karki <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d32eb83 commit a4d4e32

15 files changed

+179
-159
lines changed

t/t5300-pack-object.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,8 @@ test_expect_success 'unpacking with --strict' '
311311
rm -f .git/index &&
312312
tail -n 10 LIST | git update-index --index-info &&
313313
ST=$(git write-tree) &&
314-
PACK5=$( git rev-list --objects "$LIST" "$LI" "$ST" | \
315-
git pack-objects test-5 ) &&
314+
git rev-list --objects "$LIST" "$LI" "$ST" >actual &&
315+
PACK5=$( git pack-objects test-5 <actual ) &&
316316
PACK6=$( (
317317
echo "$LIST"
318318
echo "$LI"
@@ -358,8 +358,8 @@ test_expect_success 'index-pack with --strict' '
358358
rm -f .git/index &&
359359
tail -n 10 LIST | git update-index --index-info &&
360360
ST=$(git write-tree) &&
361-
PACK5=$( git rev-list --objects "$LIST" "$LI" "$ST" | \
362-
git pack-objects test-5 ) &&
361+
git rev-list --objects "$LIST" "$LI" "$ST" >actual &&
362+
PACK5=$( git pack-objects test-5 <actual ) &&
363363
PACK6=$( (
364364
echo "$LIST"
365365
echo "$LI"

t/t5510-fetch.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -690,8 +690,8 @@ test_expect_success C_LOCALE_OUTPUT 'fetch aligned output' '
690690
test_commit looooooooooooong-tag &&
691691
(
692692
cd full-output &&
693-
git -c fetch.output=full fetch origin 2>&1 | \
694-
grep -e "->" | cut -c 22- >../actual
693+
git -c fetch.output=full fetch origin >actual 2>&1 &&
694+
grep -e "->" actual | cut -c 22- >../actual
695695
) &&
696696
cat >expect <<-\EOF &&
697697
master -> origin/master
@@ -705,8 +705,8 @@ test_expect_success C_LOCALE_OUTPUT 'fetch compact output' '
705705
test_commit extraaa &&
706706
(
707707
cd compact &&
708-
git -c fetch.output=compact fetch origin 2>&1 | \
709-
grep -e "->" | cut -c 22- >../actual
708+
git -c fetch.output=compact fetch origin >actual 2>&1 &&
709+
grep -e "->" actual | cut -c 22- >../actual
710710
) &&
711711
cat >expect <<-\EOF &&
712712
master -> origin/*

t/t7001-mv.sh

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ test_expect_success \
2121

2222
test_expect_success \
2323
'checking the commit' \
24-
'git diff-tree -r -M --name-status HEAD^ HEAD | \
25-
grep "^R100..*path0/COPYING..*path1/COPYING"'
24+
'git diff-tree -r -M --name-status HEAD^ HEAD >actual &&
25+
grep "^R100..*path0/COPYING..*path1/COPYING" actual'
2626

2727
test_expect_success \
2828
'moving the file back into subdirectory' \
@@ -35,8 +35,8 @@ test_expect_success \
3535

3636
test_expect_success \
3737
'checking the commit' \
38-
'git diff-tree -r -M --name-status HEAD^ HEAD | \
39-
grep "^R100..*path1/COPYING..*path0/COPYING"'
38+
'git diff-tree -r -M --name-status HEAD^ HEAD >actual &&
39+
grep "^R100..*path1/COPYING..*path0/COPYING" actual'
4040

4141
test_expect_success \
4242
'mv --dry-run does not move file' \
@@ -122,10 +122,9 @@ test_expect_success \
122122

123123
test_expect_success \
124124
'checking the commit' \
125-
'git diff-tree -r -M --name-status HEAD^ HEAD | \
126-
grep "^R100..*path0/COPYING..*path2/COPYING" &&
127-
git diff-tree -r -M --name-status HEAD^ HEAD | \
128-
grep "^R100..*path0/README..*path2/README"'
125+
'git diff-tree -r -M --name-status HEAD^ HEAD >actual &&
126+
grep "^R100..*path0/COPYING..*path2/COPYING" actual &&
127+
grep "^R100..*path0/README..*path2/README" actual'
129128

130129
test_expect_success \
131130
'succeed when source is a prefix of destination' \
@@ -141,10 +140,9 @@ test_expect_success \
141140

142141
test_expect_success \
143142
'checking the commit' \
144-
'git diff-tree -r -M --name-status HEAD^ HEAD | \
145-
grep "^R100..*path2/COPYING..*path1/path2/COPYING" &&
146-
git diff-tree -r -M --name-status HEAD^ HEAD | \
147-
grep "^R100..*path2/README..*path1/path2/README"'
143+
'git diff-tree -r -M --name-status HEAD^ HEAD >actual &&
144+
grep "^R100..*path2/COPYING..*path1/path2/COPYING" actual &&
145+
grep "^R100..*path2/README..*path1/path2/README" actual'
148146

149147
test_expect_success \
150148
'do not move directory over existing directory' \

t/t7003-filter-branch.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ test_expect_success 'author information is preserved' '
187187
test \$GIT_COMMIT != $(git rev-parse master) || \
188188
echo Hallo" \
189189
preserved-author) &&
190-
test 1 = $(git rev-list --author="B V Uips" preserved-author | wc -l)
190+
git rev-list --author="B V Uips" preserved-author >actual &&
191+
test_line_count = 1 actual
191192
'
192193

193194
test_expect_success "remove a certain author's commits" '
@@ -205,7 +206,8 @@ test_expect_success "remove a certain author's commits" '
205206
cnt1=$(git rev-list master | wc -l) &&
206207
cnt2=$(git rev-list removed-author | wc -l) &&
207208
test $cnt1 -eq $(($cnt2 + 1)) &&
208-
test 0 = $(git rev-list --author="B V Uips" removed-author | wc -l)
209+
git rev-list --author="B V Uips" removed-author >actual &&
210+
test_line_count = 0 actual
209211
'
210212

211213
test_expect_success 'barf on invalid name' '
@@ -258,7 +260,8 @@ test_expect_success 'Subdirectory filter with disappearing trees' '
258260
git commit -m "Re-adding foo" &&
259261
260262
git filter-branch -f --subdirectory-filter foo &&
261-
test $(git rev-list master | wc -l) = 3
263+
git rev-list master >actual &&
264+
test_line_count = 3 actual
262265
'
263266

264267
test_expect_success 'Tag name filtering retains tag message' '

t/t9104-git-svn-follow-parent.sh

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ test_expect_success 'init and fetch a moved directory' '
3333
git svn fetch -i thunk &&
3434
test "$(git rev-parse --verify refs/remotes/thunk@2)" \
3535
= "$(git rev-parse --verify refs/remotes/thunk~1)" &&
36-
test "$(git cat-file blob refs/remotes/thunk:readme |\
37-
sed -n -e "3p")" = goodbye &&
36+
git cat-file blob refs/remotes/thunk:readme >actual &&
37+
test "$(sed -n -e "3p" actual)" = goodbye &&
3838
test -z "$(git config --get svn-remote.svn.fetch \
3939
"^trunk:refs/remotes/thunk@2$")"
4040
'
@@ -48,8 +48,8 @@ test_expect_success 'init and fetch from one svn-remote' '
4848
git svn fetch -i svn/thunk &&
4949
test "$(git rev-parse --verify refs/remotes/svn/trunk)" \
5050
= "$(git rev-parse --verify refs/remotes/svn/thunk~1)" &&
51-
test "$(git cat-file blob refs/remotes/svn/thunk:readme |\
52-
sed -n -e "3p")" = goodbye
51+
git cat-file blob refs/remotes/svn/thunk:readme >actual &&
52+
test "$(sed -n -e "3p" actual)" = goodbye
5353
'
5454

5555
test_expect_success 'follow deleted parent' '
@@ -107,7 +107,8 @@ test_expect_success 'follow deleted directory' '
107107
git svn init --minimize-url -i glob "$svnrepo"/glob &&
108108
git svn fetch -i glob &&
109109
test "$(git cat-file blob refs/remotes/glob:blob/bye)" = hi &&
110-
test "$(git ls-tree refs/remotes/glob | wc -l )" -eq 1
110+
git ls-tree refs/remotes/glob >actual &&
111+
test_line_count = 1 actual
111112
'
112113

113114
# ref: r9270 of the Subversion repository: (http://svn.collab.net/repos/svn)
@@ -204,8 +205,9 @@ test_expect_success "follow-parent is atomic" '
204205
test_expect_success "track multi-parent paths" '
205206
svn_cmd cp -m "resurrect /glob" "$svnrepo"/r9270 "$svnrepo"/glob &&
206207
git svn multi-fetch &&
207-
test $(git cat-file commit refs/remotes/glob | \
208-
grep "^parent " | wc -l) -eq 2
208+
git cat-file commit refs/remotes/glob >actual &&
209+
grep "^parent " actual >actual2 &&
210+
test_line_count = 2 actual2
209211
'
210212

211213
test_expect_success "multi-fetch continues to work" "

t/t9108-git-svn-glob.sh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ test_expect_success 'test refspec globbing' '
4747
git config --add svn-remote.svn.tags\
4848
"tags/*/src/a:refs/remotes/tags/*" &&
4949
git svn multi-fetch &&
50-
git log --pretty=oneline refs/remotes/tags/end | \
51-
sed -e "s/^.\{41\}//" > output.end &&
50+
git log --pretty=oneline refs/remotes/tags/end >actual &&
51+
sed -e "s/^.\{41\}//" actual >output.end &&
5252
test_cmp expect.end output.end &&
5353
test "$(git rev-parse refs/remotes/tags/end~1)" = \
5454
"$(git rev-parse refs/remotes/branches/start)" &&
@@ -75,14 +75,16 @@ test_expect_success 'test left-hand-side only globbing' '
7575
svn_cmd commit -m "try to try"
7676
) &&
7777
git svn fetch two &&
78-
test $(git rev-list refs/remotes/two/tags/end | wc -l) -eq 6 &&
79-
test $(git rev-list refs/remotes/two/branches/start | wc -l) -eq 3 &&
78+
git rev-list refs/remotes/two/tags/end >actual &&
79+
test_line_count = 6 actual &&
80+
git rev-list refs/remotes/two/branches/start >actual &&
81+
test_line_count = 3 actual &&
8082
test $(git rev-parse refs/remotes/two/branches/start~2) = \
8183
$(git rev-parse refs/remotes/two/trunk) &&
8284
test $(git rev-parse refs/remotes/two/tags/end~3) = \
8385
$(git rev-parse refs/remotes/two/branches/start) &&
84-
git log --pretty=oneline refs/remotes/two/tags/end | \
85-
sed -e "s/^.\{41\}//" > output.two &&
86+
git log --pretty=oneline refs/remotes/two/tags/end >actual &&
87+
sed -e "s/^.\{41\}//" actual >output.two &&
8688
test_cmp expect.two output.two
8789
'
8890

t/t9109-git-svn-multi-glob.sh

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ test_expect_success 'test refspec globbing' '
4747
git config --add svn-remote.svn.tags\
4848
"tags/*/src/a:refs/remotes/tags/*" &&
4949
git svn multi-fetch &&
50-
git log --pretty=oneline refs/remotes/tags/end | \
51-
sed -e "s/^.\{41\}//" > output.end &&
50+
git log --pretty=oneline refs/remotes/tags/end >actual &&
51+
sed -e "s/^.\{41\}//" actual >output.end &&
5252
test_cmp expect.end output.end &&
5353
test "$(git rev-parse refs/remotes/tags/end~1)" = \
5454
"$(git rev-parse refs/remotes/branches/v1/start)" &&
@@ -75,14 +75,16 @@ test_expect_success 'test left-hand-side only globbing' '
7575
svn_cmd commit -m "try to try"
7676
) &&
7777
git svn fetch two &&
78-
test $(git rev-list refs/remotes/two/tags/end | wc -l) -eq 6 &&
79-
test $(git rev-list refs/remotes/two/branches/v1/start | wc -l) -eq 3 &&
78+
git rev-list refs/remotes/two/tags/end >actual &&
79+
test_line_count = 6 actual &&
80+
git rev-list refs/remotes/two/branches/v1/start >actual &&
81+
test_line_count = 3 actual &&
8082
test $(git rev-parse refs/remotes/two/branches/v1/start~2) = \
8183
$(git rev-parse refs/remotes/two/trunk) &&
8284
test $(git rev-parse refs/remotes/two/tags/end~3) = \
8385
$(git rev-parse refs/remotes/two/branches/v1/start) &&
84-
git log --pretty=oneline refs/remotes/two/tags/end | \
85-
sed -e "s/^.\{41\}//" > output.two &&
86+
git log --pretty=oneline refs/remotes/two/tags/end >actual &&
87+
sed -e "s/^.\{41\}//" actual >output.two &&
8688
test_cmp expect.two output.two
8789
'
8890
cat > expect.four <<EOF
@@ -124,14 +126,16 @@ test_expect_success 'test another branch' '
124126
git config --add svn-remote.four.tags \
125127
"tags/*:refs/remotes/four/tags/*" &&
126128
git svn fetch four &&
127-
test $(git rev-list refs/remotes/four/tags/next | wc -l) -eq 5 &&
128-
test $(git rev-list refs/remotes/four/branches/v2/start | wc -l) -eq 3 &&
129+
git rev-list refs/remotes/four/tags/next >actual &&
130+
test_line_count = 5 actual &&
131+
git rev-list refs/remotes/four/branches/v2/start >actual &&
132+
test_line_count = 3 actual &&
129133
test $(git rev-parse refs/remotes/four/branches/v2/start~2) = \
130134
$(git rev-parse refs/remotes/four/trunk) &&
131135
test $(git rev-parse refs/remotes/four/tags/next~2) = \
132136
$(git rev-parse refs/remotes/four/branches/v2/start) &&
133-
git log --pretty=oneline refs/remotes/four/tags/next | \
134-
sed -e "s/^.\{41\}//" > output.four &&
137+
git log --pretty=oneline refs/remotes/four/tags/next >actual &&
138+
sed -e "s/^.\{41\}//" actual >output.four &&
135139
test_cmp expect.four output.four
136140
'
137141

t/t9110-git-svn-use-svm-props.sh

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,37 +21,37 @@ uuid=161ce429-a9dd-4828-af4a-52023f968c89
2121

2222
bar_url=http://mayonaise/svnrepo/bar
2323
test_expect_success 'verify metadata for /bar' "
24-
git cat-file commit refs/remotes/bar | \
25-
grep '^git-svn-id: $bar_url@12 $uuid$' &&
26-
git cat-file commit refs/remotes/bar~1 | \
27-
grep '^git-svn-id: $bar_url@11 $uuid$' &&
28-
git cat-file commit refs/remotes/bar~2 | \
29-
grep '^git-svn-id: $bar_url@10 $uuid$' &&
30-
git cat-file commit refs/remotes/bar~3 | \
31-
grep '^git-svn-id: $bar_url@9 $uuid$' &&
32-
git cat-file commit refs/remotes/bar~4 | \
33-
grep '^git-svn-id: $bar_url@6 $uuid$' &&
34-
git cat-file commit refs/remotes/bar~5 | \
35-
grep '^git-svn-id: $bar_url@1 $uuid$'
24+
git cat-file commit refs/remotes/bar >actual &&
25+
grep '^git-svn-id: $bar_url@12 $uuid$' actual &&
26+
git cat-file commit refs/remotes/bar~1 >actual &&
27+
grep '^git-svn-id: $bar_url@11 $uuid$' actual &&
28+
git cat-file commit refs/remotes/bar~2 >actual &&
29+
grep '^git-svn-id: $bar_url@10 $uuid$' actual &&
30+
git cat-file commit refs/remotes/bar~3 >actual &&
31+
grep '^git-svn-id: $bar_url@9 $uuid$' actual &&
32+
git cat-file commit refs/remotes/bar~4 >actual &&
33+
grep '^git-svn-id: $bar_url@6 $uuid$' actual &&
34+
git cat-file commit refs/remotes/bar~5 >actual &&
35+
grep '^git-svn-id: $bar_url@1 $uuid$' actual
3636
"
3737

3838
e_url=http://mayonaise/svnrepo/dir/a/b/c/d/e
3939
test_expect_success 'verify metadata for /dir/a/b/c/d/e' "
40-
git cat-file commit refs/remotes/e | \
41-
grep '^git-svn-id: $e_url@1 $uuid$'
40+
git cat-file commit refs/remotes/e >actual &&
41+
grep '^git-svn-id: $e_url@1 $uuid$' actual
4242
"
4343

4444
dir_url=http://mayonaise/svnrepo/dir
4545
test_expect_success 'verify metadata for /dir' "
46-
git cat-file commit refs/remotes/dir | \
47-
grep '^git-svn-id: $dir_url@2 $uuid$' &&
48-
git cat-file commit refs/remotes/dir~1 | \
49-
grep '^git-svn-id: $dir_url@1 $uuid$'
46+
git cat-file commit refs/remotes/dir >actual &&
47+
grep '^git-svn-id: $dir_url@2 $uuid$' actual &&
48+
git cat-file commit refs/remotes/dir~1 >actual &&
49+
grep '^git-svn-id: $dir_url@1 $uuid$' actual
5050
"
5151

5252
test_expect_success 'find commit based on SVN revision number' "
53-
git svn find-rev r12 |
54-
grep $(git rev-parse HEAD)
53+
git svn find-rev r12 >actual &&
54+
grep $(git rev-parse HEAD) actual
5555
"
5656

5757
test_expect_success 'empty rebase' "

t/t9111-git-svn-use-svnsync-props.sh

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,32 @@ uuid=161ce429-a9dd-4828-af4a-52023f968c89
2020

2121
bar_url=http://mayonaise/svnrepo/bar
2222
test_expect_success 'verify metadata for /bar' "
23-
git cat-file commit refs/remotes/bar | \
24-
grep '^git-svn-id: $bar_url@12 $uuid$' &&
25-
git cat-file commit refs/remotes/bar~1 | \
26-
grep '^git-svn-id: $bar_url@11 $uuid$' &&
27-
git cat-file commit refs/remotes/bar~2 | \
28-
grep '^git-svn-id: $bar_url@10 $uuid$' &&
29-
git cat-file commit refs/remotes/bar~3 | \
30-
grep '^git-svn-id: $bar_url@9 $uuid$' &&
31-
git cat-file commit refs/remotes/bar~4 | \
32-
grep '^git-svn-id: $bar_url@6 $uuid$' &&
33-
git cat-file commit refs/remotes/bar~5 | \
34-
grep '^git-svn-id: $bar_url@1 $uuid$'
23+
git cat-file commit refs/remotes/bar >actual &&
24+
grep '^git-svn-id: $bar_url@12 $uuid$' actual &&
25+
git cat-file commit refs/remotes/bar~1 >actual &&
26+
grep '^git-svn-id: $bar_url@11 $uuid$' actual &&
27+
git cat-file commit refs/remotes/bar~2 >actual &&
28+
grep '^git-svn-id: $bar_url@10 $uuid$' actual &&
29+
git cat-file commit refs/remotes/bar~3 >actual &&
30+
grep '^git-svn-id: $bar_url@9 $uuid$' actual &&
31+
git cat-file commit refs/remotes/bar~4 >actual &&
32+
grep '^git-svn-id: $bar_url@6 $uuid$' actual &&
33+
git cat-file commit refs/remotes/bar~5 >actual &&
34+
grep '^git-svn-id: $bar_url@1 $uuid$' actual
3535
"
3636

3737
e_url=http://mayonaise/svnrepo/dir/a/b/c/d/e
3838
test_expect_success 'verify metadata for /dir/a/b/c/d/e' "
39-
git cat-file commit refs/remotes/e | \
40-
grep '^git-svn-id: $e_url@1 $uuid$'
39+
git cat-file commit refs/remotes/e >actual &&
40+
grep '^git-svn-id: $e_url@1 $uuid$' actual
4141
"
4242

4343
dir_url=http://mayonaise/svnrepo/dir
4444
test_expect_success 'verify metadata for /dir' "
45-
git cat-file commit refs/remotes/dir | \
46-
grep '^git-svn-id: $dir_url@2 $uuid$' &&
47-
git cat-file commit refs/remotes/dir~1 | \
48-
grep '^git-svn-id: $dir_url@1 $uuid$'
45+
git cat-file commit refs/remotes/dir >actual &&
46+
grep '^git-svn-id: $dir_url@2 $uuid$' actual &&
47+
git cat-file commit refs/remotes/dir~1 >actual &&
48+
grep '^git-svn-id: $dir_url@1 $uuid$' actual
4949
"
5050

5151
test_done

t/t9114-git-svn-dcommit-merge.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ test_debug 'gitk --all & sleep 1'
6868
test_expect_success 'verify pre-merge ancestry' "
6969
test x\$(git rev-parse --verify refs/heads/svn^2) = \
7070
x\$(git rev-parse --verify refs/heads/merge) &&
71-
git cat-file commit refs/heads/svn^ | grep '^friend$'
71+
git cat-file commit refs/heads/svn^ >actual &&
72+
grep '^friend$' actual
7273
"
7374

7475
test_expect_success 'git svn dcommit merges' "
@@ -82,12 +83,13 @@ test_expect_success 'verify post-merge ancestry' "
8283
x\$(git rev-parse --verify refs/remotes/origin/trunk) &&
8384
test x\$(git rev-parse --verify refs/heads/svn^2) = \
8485
x\$(git rev-parse --verify refs/heads/merge) &&
85-
git cat-file commit refs/heads/svn^ | grep '^friend$'
86+
git cat-file commit refs/heads/svn^ >actual &&
87+
grep '^friend$' actual
8688
"
8789

8890
test_expect_success 'verify merge commit message' "
89-
git rev-list --pretty=raw -1 refs/heads/svn | \
90-
grep \" Merge branch 'merge' into svn\"
91+
git rev-list --pretty=raw -1 refs/heads/svn >actual &&
92+
grep \" Merge branch 'merge' into svn\" actual
9193
"
9294

9395
test_done

0 commit comments

Comments
 (0)