@@ -38,12 +38,11 @@ fail() {
3838 local stdout=$2
3939 local stderr=$3
4040
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
4544
46- print_stack | grep -v ^$BASH_SOURCE | format " $YELLOW " >& $STACK
45+ print_stack | grep -v ^$BASH_SOURCE | notify_stack
4746 exit 1
4847}
4948
@@ -137,7 +136,7 @@ run_test_suite() {
137136 (
138137 local status=0
139138 declare -F | grep ' setup$' > /dev/null && setup
140- (run_test $test ) || status=$?
139+ (__bash_unit_current_test__= " $test " run_test ) || status=$?
141140 declare -F | grep ' teardown$' > /dev/null && teardown
142141 exit $status
143142 )
@@ -148,9 +147,8 @@ run_test_suite() {
148147
149148run_test () {
150149 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__ "
154152}
155153
156154usage () {
@@ -198,13 +196,30 @@ notify_test_starting() {
198196}
199197
200198notify_test_succeeded () {
201- local test=" $1 "
202199 format " $GREEN " " SUCCESS" >& $LOG
203200}
204201
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+
205220tap_notify_suite_starting () {
206221 test_file=" $1 "
207- echo " # Running tests in $test_file " >& $LOG
222+ echo " # Running tests in $test_file " >& $LOG
208223}
209224
210225tap_notify_test_starting () {
@@ -214,8 +229,29 @@ tap_notify_test_starting() {
214229tap_notify_test_succeeded () {
215230 local test=" $1 "
216231 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
218241 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
219255}
220256
221257output_format=default
@@ -250,9 +286,13 @@ case "$output_format" in
250286 default)
251287 ;;
252288 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 " $@ " ; }
256296 ;;
257297 * )
258298 usage " unsupproted output format: $output_format "
0 commit comments