Andrew's git
/
gitweb.git
/ diff
summary
|
log
|
commit
| diff |
tree
commit
grep
author
committer
pickaxe
?
re
Add some fancy colors in the test library when terminal supports it.
author
Pierre Habouzit
<madcoder@debian.org>
Wed, 24 Oct 2007 20:03:38 +0000
(22:03 +0200)
committer
Junio C Hamano
<gitster@pobox.com>
Thu, 25 Oct 2007 05:44:14 +0000
(22:44 -0700)
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/test-lib.sh
patch
|
blob
|
history
raw
|
patch
|
inline
| side by side (parent:
d90a7fd
)
diff --git
a/t/test-lib.sh
b/t/test-lib.sh
index cc1253ccabf6afe0a3903f9f15177f73e8e33183..66efcdaacd72c0242a567830ea9a4cf95fc0860d 100644
(file)
--- a/
t/test-lib.sh
+++ b/
t/test-lib.sh
@@
-59,15
+59,11
@@
esac
# '
# . ./test-lib.sh
# '
# . ./test-lib.sh
-error () {
- echo "* error: $*"
- trap - exit
- exit 1
-}
-
-say () {
- echo "* $*"
-}
+[ "x$TERM" != "xdumb" ] &&
+ tput bold >/dev/null 2>&1 &&
+ tput setaf 1 >/dev/null 2>&1 &&
+ tput sgr0 >/dev/null 2>&1 &&
+ color=t
test "${test_description}" != "" ||
error "Test script did not set test_description."
test "${test_description}" != "" ||
error "Test script did not set test_description."
@@
-84,6
+80,8
@@
do
exit 0 ;;
-v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose)
verbose=t; shift ;;
exit 0 ;;
-v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose)
verbose=t; shift ;;
+ --no-color)
+ color=; shift ;;
--no-python)
# noop now...
shift ;;
--no-python)
# noop now...
shift ;;
@@
-92,6
+90,36
@@
do
esac
done
esac
done
+if test -n "$color"; then
+ say_color () {
+ case "$1" in
+ error) tput bold; tput setaf 1;; # bold red
+ skip) tput bold; tput setaf 2;; # bold green
+ pass) tput setaf 2;; # green
+ info) tput setaf 3;; # brown
+ *);;
+ esac
+ shift
+ echo "* $*"
+ tput sgr0
+ }
+else
+ say_color() {
+ shift
+ echo "* $*"
+ }
+fi
+
+error () {
+ say_color error "error: $*"
+ trap - exit
+ exit 1
+}
+
+say () {
+ say_color info "$*"
+}
+
exec 5>&1
if test "$verbose" = "t"
then
exec 5>&1
if test "$verbose" = "t"
then
@@
-122,13
+150,13
@@
test_tick () {
test_ok_ () {
test_count=$(expr "$test_count" + 1)
test_ok_ () {
test_count=$(expr "$test_count" + 1)
- say " ok $test_count: $@"
+ say
_color ""
" ok $test_count: $@"
}
test_failure_ () {
test_count=$(expr "$test_count" + 1)
test_failure=$(expr "$test_failure" + 1);
}
test_failure_ () {
test_count=$(expr "$test_count" + 1)
test_failure=$(expr "$test_failure" + 1);
- say "FAIL $test_count: $1"
+ say
_color error
"FAIL $test_count: $1"
shift
echo "$@" | sed -e 's/^/ /'
test "$immediate" = "" || { trap - exit; exit 1; }
shift
echo "$@" | sed -e 's/^/ /'
test "$immediate" = "" || { trap - exit; exit 1; }
@@
-158,9
+186,9
@@
test_skip () {
done
case "$to_skip" in
t)
done
case "$to_skip" in
t)
- say >&3 "skipping test: $@"
+ say
_color skip
>&3 "skipping test: $@"
test_count=$(expr "$test_count" + 1)
test_count=$(expr "$test_count" + 1)
- say "skip $test_count: $1"
+ say
_color skip
"skip $test_count: $1"
: true
;;
*)
: true
;;
*)
@@
-247,11
+275,11
@@
test_done () {
# The Makefile provided will clean this test area so
# we will leave things as they are.
# The Makefile provided will clean this test area so
# we will leave things as they are.
- say "passed all $test_count test(s)"
+ say
_color pass
"passed all $test_count test(s)"
exit 0 ;;
*)
exit 0 ;;
*)
- say "failed $test_failure among $test_count test(s)"
+ say
_color error
"failed $test_failure among $test_count test(s)"
exit 1 ;;
esac
exit 1 ;;
esac
@@
-296,8
+324,8
@@
do
done
case "$to_skip" in
t)
done
case "$to_skip" in
t)
- say >&3 "skipping test $this_test altogether"
- say "skip all tests in $this_test"
+ say
_color skip
>&3 "skipping test $this_test altogether"
+ say
_color skip
"skip all tests in $this_test"
test_done
esac
done
test_done
esac
done