]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t7006: simplify exit-code checks for sigpipe tests
authorJeff King <peff@peff.net>
Sun, 21 Nov 2021 23:10:56 +0000 (18:10 -0500)
committerJunio C Hamano <gitster@pobox.com>
Mon, 22 Nov 2021 23:43:44 +0000 (15:43 -0800)
Some tests in t7006 check for a SIGPIPE result by recording $? and
comparing it with test_match_signal. Before the previous commit, the
command was on the left-hand side of a pipe, and so we had to do some
subshell trickery to extract it.

But now that this is no longer the case, we can do things much more
simply: just run the command directly, using braces to avoid wrecking
the &&-chain, and then record $?. We could almost use test_expect_code
here, but it doesn't know about test_match_signal.

Likewise, for tests which expect success (i.e., not SIGPIPE), we can
just put them in the &&-chain as usual. That even lets us get rid of the
!MINGW check, since the expectation is the same on both sides.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t7006-pager.sh

index c980e8dca5791302551778338ba48823a48bc5bd..a87ef3780339782564bc668b065b0c99a75fca17 100755 (executable)
@@ -677,7 +677,7 @@ test_expect_success TTY 'git returns SIGPIPE on early pager exit' '
 
        if test_have_prereq !MINGW
        then
-               OUT=$( ((test_terminal git log; echo $? 1>&3) >/dev/null) 3>&1 ) &&
+               { test_terminal git log >/dev/null; OUT=$?; } &&
                test_match_signal 13 "$OUT"
        else
                test_terminal git log
@@ -698,7 +698,7 @@ test_expect_success TTY 'git returns SIGPIPE on early pager non-zero exit' '
 
        if test_have_prereq !MINGW
        then
-               OUT=$( ((test_terminal git log; echo $? 1>&3) >/dev/null) 3>&1 ) &&
+               { test_terminal git log >/dev/null; OUT=$?; } &&
                test_match_signal 13 "$OUT"
        else
                test_terminal git log
@@ -717,13 +717,7 @@ test_expect_success TTY 'git discards pager non-zero exit without SIGPIPE' '
        export GIT_TRACE2 &&
        test_when_finished "unset GIT_TRACE2" &&
 
-       if test_have_prereq !MINGW
-       then
-               OUT=$( ((test_terminal git log; echo $? 1>&3) >/dev/null) 3>&1 ) &&
-               test "$OUT" -eq 0
-       else
-               test_terminal git log
-       fi &&
+       test_terminal git log &&
 
        grep child_exit trace.normal >child-exits &&
        test_line_count = 1 child-exits &&
@@ -738,13 +732,7 @@ test_expect_success TTY 'git skips paging nonexisting command' '
        export GIT_TRACE2 &&
        test_when_finished "unset GIT_TRACE2" &&
 
-       if test_have_prereq !MINGW
-       then
-               OUT=$( ((test_terminal git log; echo $? 1>&3) >/dev/null) 3>&1 ) &&
-               test "$OUT" -eq 0
-       else
-               test_terminal git log
-       fi &&
+       test_terminal git log &&
 
        grep child_exit trace.normal >child-exits &&
        test_line_count = 1 child-exits &&
@@ -760,7 +748,7 @@ test_expect_success TTY 'git returns SIGPIPE on propagated signals from pager' '
 
        if test_have_prereq !MINGW
        then
-               OUT=$( ((test_terminal git log; echo $? 1>&3) >/dev/null) 3>&1 ) &&
+               { test_terminal git log >/dev/null; OUT=$?; } &&
                test_match_signal 13 "$OUT"
        else
                test_terminal git log