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 <shivam828787@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Shubham Mishra committed Mar 12, 2022 at 11:51 UTC eed36fce38c406b548d53c56483e1d2e25c5c971
2 files changed +50 -28
t/t0030-stripspace.sh
+48 -27
@@ -13,6 +13,10 @@ s40=' '
13 sss="$s40$s40$s40$s40$s40$s40$s40$s40$s40$s40" # 400
14 ttt="$t40$t40$t40$t40$t40$t40$t40$t40$t40$t40" # 400
15
16 +printf_git_stripspace () {
17 + printf "$1" | git stripspace
18 +}
19 +
20 test_expect_success \
21 'long lines without spaces should be unchanged' '
22 echo "$ttt" >expect &&
@@ -225,32 +229,38 @@ test_expect_success \
229
230 test_expect_success \
231 '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"
236 '
237
238 # text plus spaces at the end:
239
240 test_expect_success \
241 '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"
248 '
249
250 test_expect_success \
251 '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
264 '
265
266 test_expect_success \
@@ -282,12 +292,18 @@ test_expect_success \
292
293 test_expect_success \
294 '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
307 '
308
309 test_expect_success \
@@ -339,11 +355,16 @@ test_expect_success \
355
356 test_expect_success \
357 '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
368 '
369
370 test_expect_success \
t/t0050-filesystem.sh
+2 -1
@@ -104,7 +104,8 @@ test_expect_failure CASE_INSENSITIVE_FS 'add (with different case)' '
104 rm camelcase &&
105 echo 1 >CamelCase &&
106 git add CamelCase &&
107 - camel=$(git ls-files | grep -i camelcase) &&
107 + git ls-files >tmp &&
108 + camel=$(grep -i camelcase tmp) &&
109 test $(echo "$camel" | wc -l) = 1 &&
110 test "z$(git cat-file blob :$camel)" = z1
111 '