@@ -38,12 +38,11 @@ fail() {
38
38
local stdout=$2
39
39
local stderr=$3
40
40
41
- format " $RED " " FAILURE" >& $LOG
42
- [[ -z $message ]] || printf -- " $message \n" >& $LOG
43
- [[ ! -z $stdout ]] && [ -s $stdout ] && cat $stdout | sed ' s:^:out> :' | format $GREEN >& $OUT
44
- [[ ! -z $stderr ]] && [ -s $stderr ] && cat $stderr | sed ' s:^:err> :' | format $RED >& $ERR
41
+ notify_test_failed $__bash_unit_current_test__ " $message "
42
+ [[ ! -z $stdout ]] && [ -s $stdout ] && cat $stdout | notify_stdout
43
+ [[ ! -z $stderr ]] && [ -s $stderr ] && cat $stderr | notify_stderr
45
44
46
- print_stack | grep -v ^$BASH_SOURCE | format " $YELLOW " >& $STACK
45
+ print_stack | grep -v ^$BASH_SOURCE | notify_stack
47
46
exit 1
48
47
}
49
48
@@ -137,7 +136,7 @@ run_test_suite() {
137
136
(
138
137
local status=0
139
138
declare -F | grep ' setup$' > /dev/null && setup
140
- (run_test $test ) || status=$?
139
+ (__bash_unit_current_test__= " $test " run_test ) || status=$?
141
140
declare -F | grep ' teardown$' > /dev/null && teardown
142
141
exit $status
143
142
)
@@ -148,9 +147,8 @@ run_test_suite() {
148
147
149
148
run_test () {
150
149
set -e
151
- local TEST=$1
152
- notify_test_starting " $TEST "
153
- $TEST && notify_test_succeeded " $TEST " >& $LOG
150
+ notify_test_starting " $__bash_unit_current_test__ "
151
+ $__bash_unit_current_test__ && notify_test_succeeded " $__bash_unit_current_test__ "
154
152
}
155
153
156
154
usage () {
@@ -198,13 +196,30 @@ notify_test_starting() {
198
196
}
199
197
200
198
notify_test_succeeded () {
201
- local test=" $1 "
202
199
format " $GREEN " " SUCCESS" >& $LOG
203
200
}
204
201
202
+ notify_test_failed () {
203
+ local message=" $2 "
204
+ format " $RED " " FAILURE" >& $LOG
205
+ [[ -z $message ]] || printf -- " $message \n" >& $LOG
206
+ }
207
+
208
+ notify_stdout () {
209
+ sed ' s:^:out> :' | format $GREEN >& $OUT
210
+ }
211
+
212
+ notify_stderr () {
213
+ sed ' s:^:err> :' | format $RED >& $ERR
214
+ }
215
+
216
+ notify_stack () {
217
+ format " $YELLOW " >& $STACK
218
+ }
219
+
205
220
tap_notify_suite_starting () {
206
221
test_file=" $1 "
207
- echo " # Running tests in $test_file " >& $LOG
222
+ echo " # Running tests in $test_file " >& $LOG
208
223
}
209
224
210
225
tap_notify_test_starting () {
@@ -214,8 +229,29 @@ tap_notify_test_starting() {
214
229
tap_notify_test_succeeded () {
215
230
local test=" $1 "
216
231
echo -n " ok" | format " $GREEN " >& $LOG
217
- echo -n " " >& $LOG
232
+ echo -n ' - ' >& $LOG
233
+ echo " $test " | format " $BLUE " >& $LOG
234
+ }
235
+
236
+ tap_notify_test_failed () {
237
+ local test=" $1 "
238
+ local message=" $2 "
239
+ echo -n " not ok" | format " $RED " >& $LOG
240
+ echo -n " - " >& $LOG
218
241
echo " $test " >& $LOG
242
+ [[ -z $message ]] || printf -- " $message \n" | sed -u -e ' s/^/# /' >& $LOG
243
+ }
244
+
245
+ tap_notify_stdout () {
246
+ sed ' s:^:# out> :' | format $GREEN >& $OUT
247
+ }
248
+
249
+ tap_notify_stderr () {
250
+ sed ' s:^:# err> :' | format $RED >& $ERR
251
+ }
252
+
253
+ tap_notify_stack () {
254
+ sed ' s:^:# :' | format " $YELLOW " >& $STACK
219
255
}
220
256
221
257
output_format=default
@@ -250,9 +286,13 @@ case "$output_format" in
250
286
default)
251
287
;;
252
288
tap)
253
- notify_suite_starting () { tap_notify_suite_starting " $@ " ; }
254
- notify_test_starting () { tap_notify_test_starting " $@ " ; }
255
- notify_test_succeeded () { tap_notify_test_succeeded " $@ " ; }
289
+ notify_suite_starting () { tap_notify_suite_starting " $@ " ; }
290
+ notify_test_starting () { tap_notify_test_starting " $@ " ; }
291
+ notify_test_succeeded () { tap_notify_test_succeeded " $@ " ; }
292
+ notify_test_failed () { tap_notify_test_failed " $@ " ; }
293
+ notify_stdout () { tap_notify_stdout " $@ " ; }
294
+ notify_stderr () { tap_notify_stderr " $@ " ; }
295
+ notify_stack () { tap_notify_stack " $@ " ; }
256
296
;;
257
297
* )
258
298
usage " unsupproted output format: $output_format "
0 commit comments