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>

Ævar Arnfjörð Bjarmason committed Feb 2, 2021 at 02:59 UTC c24b7f67364fc89575926c7c79118df55b6103ef
1 file changed +82
t/t7006-pager.sh
+82
@@ -656,4 +656,86 @@ test_expect_success TTY 'git tag with auto-columns ' '
656 test_cmp expect actual
657 '
658
659 +test_expect_success TTY 'git returns SIGPIPE on early pager exit' '
660 + test_when_finished "rm pager-used" &&
661 + test_config core.pager ">pager-used; head -n 1; exit 0" &&
662 +
663 + if test_have_prereq !MINGW
664 + then
665 + OUT=$( ((test_terminal git log; echo $? 1>&3) | :) 3>&1 ) &&
666 + test_match_signal 13 "$OUT"
667 + else
668 + test_terminal git log
669 + fi &&
670 + test_path_is_file pager-used
671 +'
672 +
673 +test_expect_success TTY 'git returns SIGPIPE on early pager non-zero exit' '
674 + test_when_finished "rm pager-used" &&
675 + test_config core.pager ">pager-used; head -n 1; exit 1" &&
676 +
677 + if test_have_prereq !MINGW
678 + then
679 + OUT=$( ((test_terminal git log; echo $? 1>&3) | :) 3>&1 ) &&
680 + test_match_signal 13 "$OUT"
681 + else
682 + test_terminal git log
683 + fi &&
684 + test_path_is_file pager-used
685 +'
686 +
687 +test_expect_success TTY 'git discards pager non-zero exit without SIGPIPE' '
688 + test_when_finished "rm pager-used" &&
689 + test_config core.pager "wc >pager-used; exit 1" &&
690 +
691 + if test_have_prereq !MINGW
692 + then
693 + OUT=$( ((test_terminal git log; echo $? 1>&3) | :) 3>&1 ) &&
694 + test "$OUT" -eq 0
695 + else
696 + test_terminal git log
697 + fi &&
698 + test_path_is_file pager-used
699 +'
700 +
701 +test_expect_success TTY 'git discards nonexisting pager without SIGPIPE' '
702 + test_when_finished "rm pager-used" &&
703 + test_config core.pager "wc >pager-used; does-not-exist" &&
704 +
705 + if test_have_prereq !MINGW
706 + then
707 + OUT=$( ((test_terminal git log; echo $? 1>&3) | :) 3>&1 ) &&
708 + test "$OUT" -eq 0
709 + else
710 + test_terminal git log
711 + fi &&
712 + test_path_is_file pager-used
713 +'
714 +
715 +test_expect_success TTY 'git attempts to page to nonexisting pager command, gets SIGPIPE' '
716 + test_config core.pager "does-not-exist" &&
717 +
718 + if test_have_prereq !MINGW
719 + then
720 + OUT=$( ((test_terminal git log; echo $? 1>&3) | :) 3>&1 ) &&
721 + test_match_signal 13 "$OUT"
722 + else
723 + test_terminal git log
724 + fi
725 +'
726 +
727 +test_expect_success TTY 'git returns SIGPIPE on propagated signals from pager' '
728 + test_when_finished "rm pager-used" &&
729 + test_config core.pager ">pager-used; test-tool sigchain" &&
730 +
731 + if test_have_prereq !MINGW
732 + then
733 + OUT=$( ((test_terminal git log; echo $? 1>&3) | :) 3>&1 ) &&
734 + test_match_signal 13 "$OUT"
735 + else
736 + test_terminal git log
737 + fi &&
738 + test_path_is_file pager-used
739 +'
740 +
741 test_done