Skip to content

Commit

Permalink
tests: Fix race condition in t7006-pager
Browse files Browse the repository at this point in the history
Pagers that do not consume their input are dangerous: for example,

 $ GIT_PAGER=: git log
 $ echo $?
 141
 $

The only reason these tests were able to work before was that
'git log' would write to the pipe (and not fill it) before the
pager had time to terminate and close the pipe.

Fix it by using a program that consumes its input, namely wc (as
suggested by Johannes).

Reported-by: Johannes Sixt <j.sixt@viscovery.net>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jonathan Nieder authored and Junio C Hamano committed Feb 22, 2010
1 parent 2d3ca21 commit 8c33b4c
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions t/t7006-pager.sh
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ rm -f default_pager_used
test_expect_success SIMPLEPAGER 'default pager is used by default' '
cat > $less <<-EOF &&
#!$SHELL_PATH
: > default_pager_used
wc > default_pager_used
EOF
chmod +x $less &&
PATH=.:$PATH test_terminal git log &&
Expand All @@ -148,7 +148,7 @@ unset GIT_PAGER
git config --unset core.pager
rm -f PAGER_used
test_expect_success TTY 'PAGER overrides default pager' '
PAGER=": > PAGER_used" &&
PAGER="wc > PAGER_used" &&
export PAGER &&
test_terminal git log &&
test -e PAGER_used
Expand All @@ -157,17 +157,17 @@ test_expect_success TTY 'PAGER overrides default pager' '
unset GIT_PAGER
rm -f core.pager_used
test_expect_success TTY 'core.pager overrides PAGER' '
PAGER=: &&
PAGER=wc &&
export PAGER &&
git config core.pager ": > core.pager_used" &&
git config core.pager "wc > core.pager_used" &&
test_terminal git log &&
test -e core.pager_used
'

rm -f GIT_PAGER_used
test_expect_success TTY 'GIT_PAGER overrides core.pager' '
git config core.pager : &&
GIT_PAGER=": > GIT_PAGER_used" &&
git config core.pager wc &&
GIT_PAGER="wc > GIT_PAGER_used" &&
export GIT_PAGER &&
test_terminal git log &&
test -e GIT_PAGER_used
Expand Down

0 comments on commit 8c33b4c

Please sign in to comment.