Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>2021-02-02 04:59:58 +0300
committerJunio C Hamano <gitster@pobox.com>2021-02-02 08:15:58 +0300
commitc24b7f67364fc89575926c7c79118df55b6103ef (patch)
tree2ceec0de92e3aea52b7e344f8cf76b4963f95d61 /t/t7006-pager.sh
parent61ff12fa50b051141dd3b451d74dde76a87fece3 (diff)
pager: test for exit code with and without SIGPIPE
Add tests for how git behaves when the pager itself exits with non-zero, as well as for us exiting with 141 when we're killed with SIGPIPE due to the pager not consuming its output. There is some recent discussion[1] about these semantics, but aside from what we want to do in the future, we should have a test for the current behavior. This test construct is stolen from 7559a1be8a0 (unblock and unignore SIGPIPE, 2014-09-18). The reason not to make the test itself depend on the MINGW prerequisite is to make a subsequent commit easier to read. 1. https://lore.kernel.org/git/87o8h4omqa.fsf@evledraar.gmail.com/ Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t7006-pager.sh')
-rwxr-xr-xt/t7006-pager.sh82
1 files changed, 82 insertions, 0 deletions
diff --git a/t/t7006-pager.sh b/t/t7006-pager.sh
index fdb450e446..0aa030962b 100755
--- a/t/t7006-pager.sh
+++ b/t/t7006-pager.sh
@@ -656,4 +656,86 @@ test_expect_success TTY 'git tag with auto-columns ' '
test_cmp expect actual
'
+test_expect_success TTY 'git returns SIGPIPE on early pager exit' '
+ test_when_finished "rm pager-used" &&
+ test_config core.pager ">pager-used; head -n 1; exit 0" &&
+
+ if test_have_prereq !MINGW
+ then
+ OUT=$( ((test_terminal git log; echo $? 1>&3) | :) 3>&1 ) &&
+ test_match_signal 13 "$OUT"
+ else
+ test_terminal git log
+ fi &&
+ test_path_is_file pager-used
+'
+
+test_expect_success TTY 'git returns SIGPIPE on early pager non-zero exit' '
+ test_when_finished "rm pager-used" &&
+ test_config core.pager ">pager-used; head -n 1; exit 1" &&
+
+ if test_have_prereq !MINGW
+ then
+ OUT=$( ((test_terminal git log; echo $? 1>&3) | :) 3>&1 ) &&
+ test_match_signal 13 "$OUT"
+ else
+ test_terminal git log
+ fi &&
+ test_path_is_file pager-used
+'
+
+test_expect_success TTY 'git discards pager non-zero exit without SIGPIPE' '
+ test_when_finished "rm pager-used" &&
+ test_config core.pager "wc >pager-used; exit 1" &&
+
+ if test_have_prereq !MINGW
+ then
+ OUT=$( ((test_terminal git log; echo $? 1>&3) | :) 3>&1 ) &&
+ test "$OUT" -eq 0
+ else
+ test_terminal git log
+ fi &&
+ test_path_is_file pager-used
+'
+
+test_expect_success TTY 'git discards nonexisting pager without SIGPIPE' '
+ test_when_finished "rm pager-used" &&
+ test_config core.pager "wc >pager-used; does-not-exist" &&
+
+ if test_have_prereq !MINGW
+ then
+ OUT=$( ((test_terminal git log; echo $? 1>&3) | :) 3>&1 ) &&
+ test "$OUT" -eq 0
+ else
+ test_terminal git log
+ fi &&
+ test_path_is_file pager-used
+'
+
+test_expect_success TTY 'git attempts to page to nonexisting pager command, gets SIGPIPE' '
+ test_config core.pager "does-not-exist" &&
+
+ if test_have_prereq !MINGW
+ then
+ OUT=$( ((test_terminal git log; echo $? 1>&3) | :) 3>&1 ) &&
+ test_match_signal 13 "$OUT"
+ else
+ test_terminal git log
+ fi
+'
+
+test_expect_success TTY 'git returns SIGPIPE on propagated signals from pager' '
+ test_when_finished "rm pager-used" &&
+ test_config core.pager ">pager-used; test-tool sigchain" &&
+
+ if test_have_prereq !MINGW
+ then
+ OUT=$( ((test_terminal git log; echo $? 1>&3) | :) 3>&1 ) &&
+ test_match_signal 13 "$OUT"
+ else
+ test_terminal git log
+ fi &&
+ test_path_is_file pager-used
+'
+
test_done