Skip to content

Commit eed36fc

Browse files
Shubham8287gitster
authored andcommitted
t0030-t0050: avoid pipes with Git on LHS
Pipes ignore error codes of LHS command and thus we should not use them with Git in tests. As an alternative, use a 'tmp' file to write the Git output so we can test the exit code. Signed-off-by: Shubham Mishra <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9b6d1fc commit eed36fc

File tree

2 files changed

+50
-28
lines changed

2 files changed

+50
-28
lines changed

t/t0030-stripspace.sh

Lines changed: 48 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ s40=' '
1313
sss="$s40$s40$s40$s40$s40$s40$s40$s40$s40$s40" # 400
1414
ttt="$t40$t40$t40$t40$t40$t40$t40$t40$t40$t40" # 400
1515

16+
printf_git_stripspace () {
17+
printf "$1" | git stripspace
18+
}
19+
1620
test_expect_success \
1721
'long lines without spaces should be unchanged' '
1822
echo "$ttt" >expect &&
@@ -225,32 +229,38 @@ test_expect_success \
225229

226230
test_expect_success \
227231
'text without newline at end should end with newline' '
228-
test $(printf "$ttt" | git stripspace | wc -l) -gt 0 &&
229-
test $(printf "$ttt$ttt" | git stripspace | wc -l) -gt 0 &&
230-
test $(printf "$ttt$ttt$ttt" | git stripspace | wc -l) -gt 0 &&
231-
test $(printf "$ttt$ttt$ttt$ttt" | git stripspace | wc -l) -gt 0
232+
test_stdout_line_count -gt 0 printf_git_stripspace "$ttt" &&
233+
test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$ttt" &&
234+
test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$ttt$ttt" &&
235+
test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$ttt$ttt$ttt"
232236
'
233237

234238
# text plus spaces at the end:
235239

236240
test_expect_success \
237241
'text plus spaces without newline at end should end with newline' '
238-
test $(printf "$ttt$sss" | git stripspace | wc -l) -gt 0 &&
239-
test $(printf "$ttt$ttt$sss" | git stripspace | wc -l) -gt 0 &&
240-
test $(printf "$ttt$ttt$ttt$sss" | git stripspace | wc -l) -gt 0 &&
241-
test $(printf "$ttt$sss$sss" | git stripspace | wc -l) -gt 0 &&
242-
test $(printf "$ttt$ttt$sss$sss" | git stripspace | wc -l) -gt 0 &&
243-
test $(printf "$ttt$sss$sss$sss" | git stripspace | wc -l) -gt 0
242+
test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$sss" &&
243+
test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$ttt$sss" &&
244+
test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$ttt$ttt$sss" &&
245+
test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$sss$sss" &&
246+
test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$ttt$sss$sss" &&
247+
test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$sss$sss$sss"
244248
'
245249

246250
test_expect_success \
247251
'text plus spaces without newline at end should not show spaces' '
248-
! (printf "$ttt$sss" | git stripspace | grep " " >/dev/null) &&
249-
! (printf "$ttt$ttt$sss" | git stripspace | grep " " >/dev/null) &&
250-
! (printf "$ttt$ttt$ttt$sss" | git stripspace | grep " " >/dev/null) &&
251-
! (printf "$ttt$sss$sss" | git stripspace | grep " " >/dev/null) &&
252-
! (printf "$ttt$ttt$sss$sss" | git stripspace | grep " " >/dev/null) &&
253-
! (printf "$ttt$sss$sss$sss" | git stripspace | grep " " >/dev/null)
252+
printf "$ttt$sss" | git stripspace >tmp &&
253+
! grep " " tmp >/dev/null &&
254+
printf "$ttt$ttt$sss" | git stripspace >tmp &&
255+
! grep " " tmp >/dev/null &&
256+
printf "$ttt$ttt$ttt$sss" | git stripspace >tmp &&
257+
! grep " " tmp >/dev/null &&
258+
printf "$ttt$sss$sss" | git stripspace >tmp &&
259+
! grep " " tmp >/dev/null &&
260+
printf "$ttt$ttt$sss$sss" | git stripspace >tmp &&
261+
! grep " " tmp >/dev/null &&
262+
printf "$ttt$sss$sss$sss" | git stripspace >tmp &&
263+
! grep " " tmp >/dev/null
254264
'
255265

256266
test_expect_success \
@@ -282,12 +292,18 @@ test_expect_success \
282292

283293
test_expect_success \
284294
'text plus spaces at end should not show spaces' '
285-
! (echo "$ttt$sss" | git stripspace | grep " " >/dev/null) &&
286-
! (echo "$ttt$ttt$sss" | git stripspace | grep " " >/dev/null) &&
287-
! (echo "$ttt$ttt$ttt$sss" | git stripspace | grep " " >/dev/null) &&
288-
! (echo "$ttt$sss$sss" | git stripspace | grep " " >/dev/null) &&
289-
! (echo "$ttt$ttt$sss$sss" | git stripspace | grep " " >/dev/null) &&
290-
! (echo "$ttt$sss$sss$sss" | git stripspace | grep " " >/dev/null)
295+
echo "$ttt$sss" | git stripspace >tmp &&
296+
! grep " " tmp >/dev/null &&
297+
echo "$ttt$ttt$sss" | git stripspace >tmp &&
298+
! grep " " tmp >/dev/null &&
299+
echo "$ttt$ttt$ttt$sss" | git stripspace >tmp &&
300+
! grep " " tmp >/dev/null &&
301+
echo "$ttt$sss$sss" | git stripspace >tmp &&
302+
! grep " " tmp >/dev/null &&
303+
echo "$ttt$ttt$sss$sss" | git stripspace >tmp &&
304+
! grep " " tmp >/dev/null &&
305+
echo "$ttt$sss$sss$sss" | git stripspace >tmp &&
306+
! grep " " tmp >/dev/null
291307
'
292308

293309
test_expect_success \
@@ -339,11 +355,16 @@ test_expect_success \
339355

340356
test_expect_success \
341357
'spaces without newline at end should not show spaces' '
342-
! (printf "" | git stripspace | grep " " >/dev/null) &&
343-
! (printf "$sss" | git stripspace | grep " " >/dev/null) &&
344-
! (printf "$sss$sss" | git stripspace | grep " " >/dev/null) &&
345-
! (printf "$sss$sss$sss" | git stripspace | grep " " >/dev/null) &&
346-
! (printf "$sss$sss$sss$sss" | git stripspace | grep " " >/dev/null)
358+
printf "" | git stripspace >tmp &&
359+
! grep " " tmp >/dev/null &&
360+
printf "$sss" | git stripspace >tmp &&
361+
! grep " " tmp >/dev/null &&
362+
printf "$sss$sss" | git stripspace >tmp &&
363+
! grep " " tmp >/dev/null &&
364+
printf "$sss$sss$sss" | git stripspace >tmp &&
365+
! grep " " tmp >/dev/null &&
366+
printf "$sss$sss$sss$sss" | git stripspace >tmp &&
367+
! grep " " tmp >/dev/null
347368
'
348369

349370
test_expect_success \

t/t0050-filesystem.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ test_expect_failure CASE_INSENSITIVE_FS 'add (with different case)' '
104104
rm camelcase &&
105105
echo 1 >CamelCase &&
106106
git add CamelCase &&
107-
camel=$(git ls-files | grep -i camelcase) &&
107+
git ls-files >tmp &&
108+
camel=$(grep -i camelcase tmp) &&
108109
test $(echo "$camel" | wc -l) = 1 &&
109110
test "z$(git cat-file blob :$camel)" = z1
110111
'

0 commit comments

Comments
 (0)