|
59 | 59 | # ' |
60 | 60 | # . ./test-lib.sh |
61 | 61 |
|
62 | | -error () { |
63 | | - echo "* error: $*" |
64 | | - trap - exit |
65 | | - exit 1 |
66 | | -} |
67 | | - |
68 | | -say () { |
69 | | - echo "* $*" |
70 | | -} |
| 62 | +[ "x$TERM" != "xdumb" ] && |
| 63 | + tput bold >/dev/null 2>&1 && |
| 64 | + tput setaf 1 >/dev/null 2>&1 && |
| 65 | + tput sgr0 >/dev/null 2>&1 && |
| 66 | + color=t |
71 | 67 |
|
72 | 68 | test "${test_description}" != "" || |
73 | 69 | error "Test script did not set test_description." |
|
84 | 80 | exit 0 ;; |
85 | 81 | -v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose) |
86 | 82 | verbose=t; shift ;; |
| 83 | + -q|--q|--qu|--qui|--quie|--quiet) |
| 84 | + quiet=t; shift ;; |
| 85 | + --no-color) |
| 86 | + color=; shift ;; |
87 | 87 | --no-python) |
88 | 88 | # noop now... |
89 | 89 | shift ;; |
|
92 | 92 | esac |
93 | 93 | done |
94 | 94 |
|
| 95 | +if test -n "$color"; then |
| 96 | + say_color () { |
| 97 | + case "$1" in |
| 98 | + error) tput bold; tput setaf 1;; # bold red |
| 99 | + skip) tput bold; tput setaf 2;; # bold green |
| 100 | + pass) tput setaf 2;; # green |
| 101 | + info) tput setaf 3;; # brown |
| 102 | + *) test -n "$quiet" && return;; |
| 103 | + esac |
| 104 | + shift |
| 105 | + echo "* $*" |
| 106 | + tput sgr0 |
| 107 | + } |
| 108 | +else |
| 109 | + say_color() { |
| 110 | + test -z "$1" && test -n "$quiet" && return |
| 111 | + shift |
| 112 | + echo "* $*" |
| 113 | + } |
| 114 | +fi |
| 115 | + |
| 116 | +error () { |
| 117 | + say_color error "error: $*" |
| 118 | + trap - exit |
| 119 | + exit 1 |
| 120 | +} |
| 121 | + |
| 122 | +say () { |
| 123 | + say_color info "$*" |
| 124 | +} |
| 125 | + |
95 | 126 | exec 5>&1 |
96 | 127 | if test "$verbose" = "t" |
97 | 128 | then |
@@ -122,13 +153,13 @@ test_tick () { |
122 | 153 |
|
123 | 154 | test_ok_ () { |
124 | 155 | test_count=$(expr "$test_count" + 1) |
125 | | - say " ok $test_count: $@" |
| 156 | + say_color "" " ok $test_count: $@" |
126 | 157 | } |
127 | 158 |
|
128 | 159 | test_failure_ () { |
129 | 160 | test_count=$(expr "$test_count" + 1) |
130 | 161 | test_failure=$(expr "$test_failure" + 1); |
131 | | - say "FAIL $test_count: $1" |
| 162 | + say_color error "FAIL $test_count: $1" |
132 | 163 | shift |
133 | 164 | echo "$@" | sed -e 's/^/ /' |
134 | 165 | test "$immediate" = "" || { trap - exit; exit 1; } |
@@ -158,9 +189,9 @@ test_skip () { |
158 | 189 | done |
159 | 190 | case "$to_skip" in |
160 | 191 | t) |
161 | | - say >&3 "skipping test: $@" |
| 192 | + say_color skip >&3 "skipping test: $@" |
162 | 193 | test_count=$(expr "$test_count" + 1) |
163 | | - say "skip $test_count: $1" |
| 194 | + say_color skip "skip $test_count: $1" |
164 | 195 | : true |
165 | 196 | ;; |
166 | 197 | *) |
@@ -247,11 +278,11 @@ test_done () { |
247 | 278 | # The Makefile provided will clean this test area so |
248 | 279 | # we will leave things as they are. |
249 | 280 |
|
250 | | - say "passed all $test_count test(s)" |
| 281 | + say_color pass "passed all $test_count test(s)" |
251 | 282 | exit 0 ;; |
252 | 283 |
|
253 | 284 | *) |
254 | | - say "failed $test_failure among $test_count test(s)" |
| 285 | + say_color error "failed $test_failure among $test_count test(s)" |
255 | 286 | exit 1 ;; |
256 | 287 |
|
257 | 288 | esac |
|
296 | 327 | done |
297 | 328 | case "$to_skip" in |
298 | 329 | t) |
299 | | - say >&3 "skipping test $this_test altogether" |
300 | | - say "skip all tests in $this_test" |
| 330 | + say_color skip >&3 "skipping test $this_test altogether" |
| 331 | + say_color skip "skip all tests in $this_test" |
301 | 332 | test_done |
302 | 333 | esac |
303 | 334 | done |
0 commit comments