Skip to content

Commit 102fc80

Browse files
rhansengitster
authored andcommitted
test-lib.sh: do tests for color support after changing HOME
If ncurses needs ~/.terminfo for the current $TERM, then tput will succeed before changing HOME to $TRASH_DIRECTORY but fail afterward. Move the tests that determine whether there is color support after changing HOME so that color=t is set if and only if tput would succeed when say_color() is run. Note that color=t is now set after --no-color is processed, so the condition to set color=t has changed: it is now set only if color has not already been set to the empty string by --no-color. This disables color support for those that need ~/.terminfo for their TERM, but it's better than filling the screen with: tput: unknown terminal "custom-terminal-name-here" An alternative would be to symlink or copy the user's terminfo database into $TRASH_DIRECTORY, but this is tricky due to the lack of a standard name for the terminfo database (for example, instead of a ~/.terminfo directory, NetBSD uses a ~/.terminfo.cdb database file). Signed-off-by: Richard Hansen <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 46f32a9 commit 102fc80

File tree

1 file changed

+47
-43
lines changed

1 file changed

+47
-43
lines changed

t/test-lib.sh

Lines changed: 47 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -184,16 +184,8 @@ export _x05 _x40 _z40 LF u200c
184184
# This test checks if command xyzzy does the right thing...
185185
# '
186186
# . ./test-lib.sh
187-
test "x$ORIGINAL_TERM" != "xdumb" && (
188-
TERM=$ORIGINAL_TERM &&
189-
export TERM &&
190-
test -t 1 &&
191-
tput bold >/dev/null 2>&1 &&
192-
tput setaf 1 >/dev/null 2>&1 &&
193-
tput sgr0 >/dev/null 2>&1
194-
) &&
195-
color=t
196187

188+
unset color
197189
while test "$#" -ne 0
198190
do
199191
case "$1" in
@@ -258,40 +250,6 @@ then
258250
verbose=t
259251
fi
260252

261-
if test -n "$color"
262-
then
263-
say_color () {
264-
(
265-
TERM=$ORIGINAL_TERM
266-
export TERM
267-
case "$1" in
268-
error)
269-
tput bold; tput setaf 1;; # bold red
270-
skip)
271-
tput setaf 4;; # blue
272-
warn)
273-
tput setaf 3;; # brown/yellow
274-
pass)
275-
tput setaf 2;; # green
276-
info)
277-
tput setaf 6;; # cyan
278-
*)
279-
test -n "$quiet" && return;;
280-
esac
281-
shift
282-
printf "%s" "$*"
283-
tput sgr0
284-
echo
285-
)
286-
}
287-
else
288-
say_color() {
289-
test -z "$1" && test -n "$quiet" && return
290-
shift
291-
printf "%s\n" "$*"
292-
}
293-
fi
294-
295253
error () {
296254
say_color error "error: $*"
297255
GIT_EXIT_OK=t
@@ -857,6 +815,52 @@ HOME="$TRASH_DIRECTORY"
857815
GNUPGHOME="$HOME/gnupg-home-not-used"
858816
export HOME GNUPGHOME
859817

818+
# run the tput tests *after* changing HOME (in case ncurses needs
819+
# ~/.terminfo for $TERM)
820+
test -n "${color+set}" || test "x$ORIGINAL_TERM" != "xdumb" && (
821+
TERM=$ORIGINAL_TERM &&
822+
export TERM &&
823+
test -t 1 &&
824+
tput bold >/dev/null 2>&1 &&
825+
tput setaf 1 >/dev/null 2>&1 &&
826+
tput sgr0 >/dev/null 2>&1
827+
) &&
828+
color=t
829+
830+
if test -n "$color"
831+
then
832+
say_color () {
833+
(
834+
TERM=$ORIGINAL_TERM
835+
export TERM
836+
case "$1" in
837+
error)
838+
tput bold; tput setaf 1;; # bold red
839+
skip)
840+
tput setaf 4;; # blue
841+
warn)
842+
tput setaf 3;; # brown/yellow
843+
pass)
844+
tput setaf 2;; # green
845+
info)
846+
tput setaf 6;; # cyan
847+
*)
848+
test -n "$quiet" && return;;
849+
esac
850+
shift
851+
printf "%s" "$*"
852+
tput sgr0
853+
echo
854+
)
855+
}
856+
else
857+
say_color() {
858+
test -z "$1" && test -n "$quiet" && return
859+
shift
860+
printf "%s\n" "$*"
861+
}
862+
fi
863+
860864
if test -z "$TEST_NO_CREATE_REPO"
861865
then
862866
test_create_repo "$TRASH_DIRECTORY"

0 commit comments

Comments
 (0)