@@ -272,6 +272,11 @@ function bashunit::state::print_line() {
272272 return
273273 fi
274274
275+ if bashunit::env::is_tap_output_enabled; then
276+ bashunit::state::print_tap_line " $type " " $line "
277+ return
278+ fi
279+
275280 if ! bashunit::env::is_simple_output_enabled; then
276281 printf " %s\n" " $line "
277282 return
@@ -300,3 +305,61 @@ function bashunit::state::print_line() {
300305 fi
301306 fi
302307}
308+
309+ function bashunit::state::print_tap_line() {
310+ local type=$1
311+ local line=$2
312+
313+ local clean_line
314+ clean_line=$( printf " %s" " $line " | sed ' s/\x1B\[[0-9;]*[mK]//g' )
315+ local test_name=" ${clean_line#*: } "
316+ test_name=" ${test_name%% $' \n ' * } "
317+ # Strip trailing whitespace and duration
318+ test_name=$( printf " %s" " $test_name " | \
319+ sed ' s/[[:space:]]*[0-9][0-9]*m\{0,1\}[[:space:]]*[0-9.]*[ms]*[[:space:]]*$//' )
320+
321+ case " $type " in
322+ successful)
323+ printf " ok %d - %s\n" " $_BASHUNIT_TOTAL_TESTS_COUNT " " $test_name "
324+ ;;
325+ failure | failed | failed_snapshot | error)
326+ printf " not ok %d - %s\n" " $_BASHUNIT_TOTAL_TESTS_COUNT " " $test_name "
327+ local detail_line
328+ printf " ---\n"
329+ while IFS= read -r detail_line; do
330+ detail_line=$( printf " %s" " $detail_line " | sed ' s/\x1B\[[0-9;]*[mK]//g' )
331+ if [[ -n " $detail_line " \
332+ && " $detail_line " != * " Failed:" * \
333+ && " $detail_line " != * " Error:" * ]]; then
334+ local trimmed=" ${detail_line# " ${detail_line%% [![:space:]]* } " } "
335+ printf " %s\n" " $trimmed "
336+ fi
337+ done <<< " $clean_line"
338+ printf " ...\n"
339+ ;;
340+ skipped)
341+ local skip_name=" ${test_name%% * } "
342+ local skip_reason=" ${test_name# " $skip_name " } "
343+ skip_reason=" ${skip_reason# " ${skip_reason%% [![:space:]]* } " } "
344+ if [[ -n " $skip_reason " ]]; then
345+ printf " ok %d - %s # SKIP %s\n" \
346+ " $_BASHUNIT_TOTAL_TESTS_COUNT " " $skip_name " " $skip_reason "
347+ else
348+ printf " ok %d - %s # SKIP\n" \
349+ " $_BASHUNIT_TOTAL_TESTS_COUNT " " $test_name "
350+ fi
351+ ;;
352+ incomplete)
353+ printf " ok %d - %s # TODO incomplete\n" \
354+ " $_BASHUNIT_TOTAL_TESTS_COUNT " " $test_name "
355+ ;;
356+ snapshot)
357+ printf " ok %d - %s # snapshot\n" \
358+ " $_BASHUNIT_TOTAL_TESTS_COUNT " " $test_name "
359+ ;;
360+ * )
361+ printf " not ok %d - %s\n" \
362+ " $_BASHUNIT_TOTAL_TESTS_COUNT " " $test_name "
363+ ;;
364+ esac
365+ }
0 commit comments