|
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 | + --no-color) |
| 84 | + color=; shift ;; |
87 | 85 | --no-python) |
88 | 86 | # noop now... |
89 | 87 | shift ;; |
|
92 | 90 | esac |
93 | 91 | done |
94 | 92 |
|
| 93 | +if test -n "$color"; then |
| 94 | + say_color () { |
| 95 | + case "$1" in |
| 96 | + error) tput bold; tput setaf 1;; # bold red |
| 97 | + skip) tput bold; tput setaf 2;; # bold green |
| 98 | + pass) tput setaf 2;; # green |
| 99 | + info) tput setaf 3;; # brown |
| 100 | + *);; |
| 101 | + esac |
| 102 | + shift |
| 103 | + echo "* $*" |
| 104 | + tput sgr0 |
| 105 | + } |
| 106 | +else |
| 107 | + say_color() { |
| 108 | + shift |
| 109 | + echo "* $*" |
| 110 | + } |
| 111 | +fi |
| 112 | + |
| 113 | +error () { |
| 114 | + say_color error "error: $*" |
| 115 | + trap - exit |
| 116 | + exit 1 |
| 117 | +} |
| 118 | + |
| 119 | +say () { |
| 120 | + say_color info "$*" |
| 121 | +} |
| 122 | + |
95 | 123 | exec 5>&1 |
96 | 124 | if test "$verbose" = "t" |
97 | 125 | then |
@@ -122,13 +150,13 @@ test_tick () { |
122 | 150 |
|
123 | 151 | test_ok_ () { |
124 | 152 | test_count=$(expr "$test_count" + 1) |
125 | | - say " ok $test_count: $@" |
| 153 | + say_color "" " ok $test_count: $@" |
126 | 154 | } |
127 | 155 |
|
128 | 156 | test_failure_ () { |
129 | 157 | test_count=$(expr "$test_count" + 1) |
130 | 158 | test_failure=$(expr "$test_failure" + 1); |
131 | | - say "FAIL $test_count: $1" |
| 159 | + say_color error "FAIL $test_count: $1" |
132 | 160 | shift |
133 | 161 | echo "$@" | sed -e 's/^/ /' |
134 | 162 | test "$immediate" = "" || { trap - exit; exit 1; } |
@@ -158,9 +186,9 @@ test_skip () { |
158 | 186 | done |
159 | 187 | case "$to_skip" in |
160 | 188 | t) |
161 | | - say >&3 "skipping test: $@" |
| 189 | + say_color skip >&3 "skipping test: $@" |
162 | 190 | test_count=$(expr "$test_count" + 1) |
163 | | - say "skip $test_count: $1" |
| 191 | + say_color skip "skip $test_count: $1" |
164 | 192 | : true |
165 | 193 | ;; |
166 | 194 | *) |
@@ -247,11 +275,11 @@ test_done () { |
247 | 275 | # The Makefile provided will clean this test area so |
248 | 276 | # we will leave things as they are. |
249 | 277 |
|
250 | | - say "passed all $test_count test(s)" |
| 278 | + say_color pass "passed all $test_count test(s)" |
251 | 279 | exit 0 ;; |
252 | 280 |
|
253 | 281 | *) |
254 | | - say "failed $test_failure among $test_count test(s)" |
| 282 | + say_color error "failed $test_failure among $test_count test(s)" |
255 | 283 | exit 1 ;; |
256 | 284 |
|
257 | 285 | esac |
|
296 | 324 | done |
297 | 325 | case "$to_skip" in |
298 | 326 | t) |
299 | | - say >&3 "skipping test $this_test altogether" |
300 | | - say "skip all tests in $this_test" |
| 327 | + say_color skip >&3 "skipping test $this_test altogether" |
| 328 | + say_color skip "skip all tests in $this_test" |
301 | 329 | test_done |
302 | 330 | esac |
303 | 331 | done |
0 commit comments