mirror of
https://github.com/git/git.git
synced 2024-10-31 14:27:54 +01:00
Merge branch 'jn/t7006-fixup'
* jn/t7006-fixup: t7006: guard cleanup with test_expect_success
This commit is contained in:
commit
f9a518e884
2 changed files with 117 additions and 48 deletions
149
t/t7006-pager.sh
149
t/t7006-pager.sh
|
@ -4,17 +4,24 @@ test_description='Test automatic use of a pager.'
|
||||||
|
|
||||||
. ./test-lib.sh
|
. ./test-lib.sh
|
||||||
|
|
||||||
rm -f stdout_is_tty
|
cleanup_fail() {
|
||||||
|
echo >&2 cleanup failed
|
||||||
|
(exit 1)
|
||||||
|
}
|
||||||
|
|
||||||
test_expect_success 'set up terminal for tests' '
|
test_expect_success 'set up terminal for tests' '
|
||||||
|
rm -f stdout_is_tty ||
|
||||||
|
cleanup_fail &&
|
||||||
|
|
||||||
if test -t 1
|
if test -t 1
|
||||||
then
|
then
|
||||||
: > stdout_is_tty
|
>stdout_is_tty
|
||||||
elif
|
elif
|
||||||
test_have_prereq PERL &&
|
test_have_prereq PERL &&
|
||||||
"$PERL_PATH" "$TEST_DIRECTORY"/t7006/test-terminal.perl \
|
"$PERL_PATH" "$TEST_DIRECTORY"/t7006/test-terminal.perl \
|
||||||
sh -c "test -t 1"
|
sh -c "test -t 1"
|
||||||
then
|
then
|
||||||
: > test_terminal_works
|
>test_terminal_works
|
||||||
fi
|
fi
|
||||||
'
|
'
|
||||||
|
|
||||||
|
@ -32,53 +39,68 @@ else
|
||||||
say no usable terminal, so skipping some tests
|
say no usable terminal, so skipping some tests
|
||||||
fi
|
fi
|
||||||
|
|
||||||
unset GIT_PAGER GIT_PAGER_IN_USE
|
|
||||||
git config --unset core.pager
|
|
||||||
PAGER='cat > paginated.out'
|
|
||||||
export PAGER
|
|
||||||
|
|
||||||
test_expect_success 'setup' '
|
test_expect_success 'setup' '
|
||||||
|
unset GIT_PAGER GIT_PAGER_IN_USE &&
|
||||||
|
test_might_fail git config --unset core.pager &&
|
||||||
|
|
||||||
|
PAGER="cat >paginated.out" &&
|
||||||
|
export PAGER &&
|
||||||
|
|
||||||
test_commit initial
|
test_commit initial
|
||||||
'
|
'
|
||||||
|
|
||||||
rm -f paginated.out
|
|
||||||
test_expect_success TTY 'some commands use a pager' '
|
test_expect_success TTY 'some commands use a pager' '
|
||||||
|
rm -f paginated.out ||
|
||||||
|
cleanup_fail &&
|
||||||
|
|
||||||
test_terminal git log &&
|
test_terminal git log &&
|
||||||
test -e paginated.out
|
test -e paginated.out
|
||||||
'
|
'
|
||||||
|
|
||||||
rm -f paginated.out
|
|
||||||
test_expect_success TTY 'some commands do not use a pager' '
|
test_expect_success TTY 'some commands do not use a pager' '
|
||||||
|
rm -f paginated.out ||
|
||||||
|
cleanup_fail &&
|
||||||
|
|
||||||
test_terminal git rev-list HEAD &&
|
test_terminal git rev-list HEAD &&
|
||||||
! test -e paginated.out
|
! test -e paginated.out
|
||||||
'
|
'
|
||||||
|
|
||||||
rm -f paginated.out
|
|
||||||
test_expect_success 'no pager when stdout is a pipe' '
|
test_expect_success 'no pager when stdout is a pipe' '
|
||||||
|
rm -f paginated.out ||
|
||||||
|
cleanup_fail &&
|
||||||
|
|
||||||
git log | cat &&
|
git log | cat &&
|
||||||
! test -e paginated.out
|
! test -e paginated.out
|
||||||
'
|
'
|
||||||
|
|
||||||
rm -f paginated.out
|
|
||||||
test_expect_success 'no pager when stdout is a regular file' '
|
test_expect_success 'no pager when stdout is a regular file' '
|
||||||
git log > file &&
|
rm -f paginated.out ||
|
||||||
|
cleanup_fail &&
|
||||||
|
|
||||||
|
git log >file &&
|
||||||
! test -e paginated.out
|
! test -e paginated.out
|
||||||
'
|
'
|
||||||
|
|
||||||
rm -f paginated.out
|
|
||||||
test_expect_success TTY 'git --paginate rev-list uses a pager' '
|
test_expect_success TTY 'git --paginate rev-list uses a pager' '
|
||||||
|
rm -f paginated.out ||
|
||||||
|
cleanup_fail &&
|
||||||
|
|
||||||
test_terminal git --paginate rev-list HEAD &&
|
test_terminal git --paginate rev-list HEAD &&
|
||||||
test -e paginated.out
|
test -e paginated.out
|
||||||
'
|
'
|
||||||
|
|
||||||
rm -f file paginated.out
|
|
||||||
test_expect_success 'no pager even with --paginate when stdout is a pipe' '
|
test_expect_success 'no pager even with --paginate when stdout is a pipe' '
|
||||||
|
rm -f file paginated.out ||
|
||||||
|
cleanup_fail &&
|
||||||
|
|
||||||
git --paginate log | cat &&
|
git --paginate log | cat &&
|
||||||
! test -e paginated.out
|
! test -e paginated.out
|
||||||
'
|
'
|
||||||
|
|
||||||
rm -f paginated.out
|
|
||||||
test_expect_success TTY 'no pager with --no-pager' '
|
test_expect_success TTY 'no pager with --no-pager' '
|
||||||
|
rm -f paginated.out ||
|
||||||
|
cleanup_fail &&
|
||||||
|
|
||||||
test_terminal git --no-pager log &&
|
test_terminal git --no-pager log &&
|
||||||
! test -e paginated.out
|
! test -e paginated.out
|
||||||
'
|
'
|
||||||
|
@ -86,88 +108,119 @@ test_expect_success TTY 'no pager with --no-pager' '
|
||||||
# A colored commit log will begin with an appropriate ANSI escape
|
# A colored commit log will begin with an appropriate ANSI escape
|
||||||
# for the first color; the text "commit" comes later.
|
# for the first color; the text "commit" comes later.
|
||||||
colorful() {
|
colorful() {
|
||||||
read firstline < $1
|
read firstline <$1
|
||||||
! expr "$firstline" : "^[a-zA-Z]" >/dev/null
|
! expr "$firstline" : "^[a-zA-Z]" >/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
rm -f colorful.log colorless.log
|
|
||||||
test_expect_success 'tests can detect color' '
|
test_expect_success 'tests can detect color' '
|
||||||
git log --no-color > colorless.log &&
|
rm -f colorful.log colorless.log ||
|
||||||
git log --color > colorful.log &&
|
cleanup_fail &&
|
||||||
|
|
||||||
|
git log --no-color >colorless.log &&
|
||||||
|
git log --color >colorful.log &&
|
||||||
! colorful colorless.log &&
|
! colorful colorless.log &&
|
||||||
colorful colorful.log
|
colorful colorful.log
|
||||||
'
|
'
|
||||||
|
|
||||||
rm -f colorless.log
|
|
||||||
git config color.ui auto
|
|
||||||
test_expect_success 'no color when stdout is a regular file' '
|
test_expect_success 'no color when stdout is a regular file' '
|
||||||
git log > colorless.log &&
|
rm -f colorless.log &&
|
||||||
|
git config color.ui auto ||
|
||||||
|
cleanup_fail &&
|
||||||
|
|
||||||
|
git log >colorless.log &&
|
||||||
! colorful colorless.log
|
! colorful colorless.log
|
||||||
'
|
'
|
||||||
|
|
||||||
rm -f paginated.out
|
|
||||||
git config color.ui auto
|
|
||||||
test_expect_success TTY 'color when writing to a pager' '
|
test_expect_success TTY 'color when writing to a pager' '
|
||||||
TERM=vt100 test_terminal git log &&
|
rm -f paginated.out &&
|
||||||
|
git config color.ui auto ||
|
||||||
|
cleanup_fail &&
|
||||||
|
|
||||||
|
(
|
||||||
|
TERM=vt100 &&
|
||||||
|
export TERM &&
|
||||||
|
test_terminal git log
|
||||||
|
) &&
|
||||||
colorful paginated.out
|
colorful paginated.out
|
||||||
'
|
'
|
||||||
|
|
||||||
rm -f colorful.log
|
|
||||||
git config color.ui auto
|
|
||||||
test_expect_success 'color when writing to a file intended for a pager' '
|
test_expect_success 'color when writing to a file intended for a pager' '
|
||||||
TERM=vt100 GIT_PAGER_IN_USE=true git log > colorful.log &&
|
rm -f colorful.log &&
|
||||||
|
git config color.ui auto ||
|
||||||
|
cleanup_fail &&
|
||||||
|
|
||||||
|
(
|
||||||
|
TERM=vt100 &&
|
||||||
|
GIT_PAGER_IN_USE=true &&
|
||||||
|
export TERM GIT_PAGER_IN_USE &&
|
||||||
|
git log >colorful.log
|
||||||
|
) &&
|
||||||
colorful colorful.log
|
colorful colorful.log
|
||||||
'
|
'
|
||||||
|
|
||||||
unset PAGER GIT_PAGER
|
|
||||||
git config --unset core.pager
|
|
||||||
test_expect_success 'determine default pager' '
|
test_expect_success 'determine default pager' '
|
||||||
|
unset PAGER GIT_PAGER &&
|
||||||
|
test_might_fail git config --unset core.pager ||
|
||||||
|
cleanup_fail &&
|
||||||
|
|
||||||
less=$(git var GIT_PAGER) &&
|
less=$(git var GIT_PAGER) &&
|
||||||
test -n "$less"
|
test -n "$less"
|
||||||
'
|
'
|
||||||
|
|
||||||
if expr "$less" : '^[a-z]*$' > /dev/null && test_have_prereq TTY
|
if expr "$less" : '^[a-z][a-z]*$' >/dev/null && test_have_prereq TTY
|
||||||
then
|
then
|
||||||
test_set_prereq SIMPLEPAGER
|
test_set_prereq SIMPLEPAGER
|
||||||
fi
|
fi
|
||||||
|
|
||||||
unset PAGER GIT_PAGER
|
|
||||||
git config --unset core.pager
|
|
||||||
rm -f default_pager_used
|
|
||||||
test_expect_success SIMPLEPAGER 'default pager is used by default' '
|
test_expect_success SIMPLEPAGER 'default pager is used by default' '
|
||||||
cat > $less <<-EOF &&
|
unset PAGER GIT_PAGER &&
|
||||||
#!$SHELL_PATH
|
test_might_fail git config --unset core.pager &&
|
||||||
wc > default_pager_used
|
rm -f default_pager_used ||
|
||||||
|
cleanup_fail &&
|
||||||
|
|
||||||
|
cat >$less <<-\EOF &&
|
||||||
|
#!/bin/sh
|
||||||
|
wc >default_pager_used
|
||||||
EOF
|
EOF
|
||||||
chmod +x $less &&
|
chmod +x $less &&
|
||||||
PATH=.:$PATH test_terminal git log &&
|
(
|
||||||
|
PATH=.:$PATH &&
|
||||||
|
export PATH &&
|
||||||
|
test_terminal git log
|
||||||
|
) &&
|
||||||
test -e default_pager_used
|
test -e default_pager_used
|
||||||
'
|
'
|
||||||
|
|
||||||
unset GIT_PAGER
|
|
||||||
git config --unset core.pager
|
|
||||||
rm -f PAGER_used
|
|
||||||
test_expect_success TTY 'PAGER overrides default pager' '
|
test_expect_success TTY 'PAGER overrides default pager' '
|
||||||
PAGER="wc > PAGER_used" &&
|
unset GIT_PAGER &&
|
||||||
|
test_might_fail git config --unset core.pager &&
|
||||||
|
rm -f PAGER_used ||
|
||||||
|
cleanup_fail &&
|
||||||
|
|
||||||
|
PAGER="wc >PAGER_used" &&
|
||||||
export PAGER &&
|
export PAGER &&
|
||||||
test_terminal git log &&
|
test_terminal git log &&
|
||||||
test -e PAGER_used
|
test -e PAGER_used
|
||||||
'
|
'
|
||||||
|
|
||||||
unset GIT_PAGER
|
|
||||||
rm -f core.pager_used
|
|
||||||
test_expect_success TTY 'core.pager overrides PAGER' '
|
test_expect_success TTY 'core.pager overrides PAGER' '
|
||||||
|
unset GIT_PAGER &&
|
||||||
|
rm -f core.pager_used ||
|
||||||
|
cleanup_fail &&
|
||||||
|
|
||||||
PAGER=wc &&
|
PAGER=wc &&
|
||||||
export PAGER &&
|
export PAGER &&
|
||||||
git config core.pager "wc > core.pager_used" &&
|
git config core.pager "wc >core.pager_used" &&
|
||||||
test_terminal git log &&
|
test_terminal git log &&
|
||||||
test -e core.pager_used
|
test -e core.pager_used
|
||||||
'
|
'
|
||||||
|
|
||||||
rm -f GIT_PAGER_used
|
|
||||||
test_expect_success TTY 'GIT_PAGER overrides core.pager' '
|
test_expect_success TTY 'GIT_PAGER overrides core.pager' '
|
||||||
|
rm -f GIT_PAGER_used ||
|
||||||
|
cleanup_fail &&
|
||||||
|
|
||||||
git config core.pager wc &&
|
git config core.pager wc &&
|
||||||
GIT_PAGER="wc > GIT_PAGER_used" &&
|
GIT_PAGER="wc >GIT_PAGER_used" &&
|
||||||
export GIT_PAGER &&
|
export GIT_PAGER &&
|
||||||
test_terminal git log &&
|
test_terminal git log &&
|
||||||
test -e GIT_PAGER_used
|
test -e GIT_PAGER_used
|
||||||
|
|
|
@ -530,6 +530,22 @@ test_must_fail () {
|
||||||
test $? -gt 0 -a $? -le 129 -o $? -gt 192
|
test $? -gt 0 -a $? -le 129 -o $? -gt 192
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Similar to test_must_fail, but tolerates success, too. This is
|
||||||
|
# meant to be used in contexts like:
|
||||||
|
#
|
||||||
|
# test_expect_success 'some command works without configuration' '
|
||||||
|
# test_might_fail git config --unset all.configuration &&
|
||||||
|
# do something
|
||||||
|
# '
|
||||||
|
#
|
||||||
|
# Writing "git config --unset all.configuration || :" would be wrong,
|
||||||
|
# because we want to notice if it fails due to segv.
|
||||||
|
|
||||||
|
test_might_fail () {
|
||||||
|
"$@"
|
||||||
|
test $? -ge 0 -a $? -le 129 -o $? -gt 192
|
||||||
|
}
|
||||||
|
|
||||||
# test_cmp is a helper function to compare actual and expected output.
|
# test_cmp is a helper function to compare actual and expected output.
|
||||||
# You can use it like:
|
# You can use it like:
|
||||||
#
|
#
|
||||||
|
|
Loading…
Reference in a new issue