Skip to content

Commit e939e15

Browse files
Thomas Rastgitster
authored andcommitted
test-lib: allow prefixing a custom string before "ok N" etc.
This is not really meant for external use, and thus not documented. It allows the next commit to neatly distinguish between sub-tests and the main run. The format is intentionally not valid TAP. The use in the next commit would not result in anything valid either way, and it seems better to make it obvious. Signed-off-by: Thomas Rast <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5dfc368 commit e939e15

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

t/test-lib.sh

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ do
209209
--root=*)
210210
root=$(expr "z$1" : 'z[^=]*=\(.*\)')
211211
shift ;;
212+
--statusprefix=*)
213+
statusprefix=$(expr "z$1" : 'z[^=]*=\(.*\)')
214+
shift ;;
212215
*)
213216
echo "error: unknown test option '$1'" >&2; exit 1 ;;
214217
esac
@@ -316,25 +319,25 @@ trap 'die' EXIT
316319

317320
test_ok_ () {
318321
test_success=$(($test_success + 1))
319-
say_color "" "ok $test_count - $@"
322+
say_color "" "${statusprefix}ok $test_count - $@"
320323
}
321324

322325
test_failure_ () {
323326
test_failure=$(($test_failure + 1))
324-
say_color error "not ok $test_count - $1"
327+
say_color error "${statusprefix}not ok $test_count - $1"
325328
shift
326329
echo "$@" | sed -e 's/^/# /'
327330
test "$immediate" = "" || { GIT_EXIT_OK=t; exit 1; }
328331
}
329332

330333
test_known_broken_ok_ () {
331334
test_fixed=$(($test_fixed+1))
332-
say_color error "ok $test_count - $@ # TODO known breakage vanished"
335+
say_color error "${statusprefix}ok $test_count - $@ # TODO known breakage vanished"
333336
}
334337

335338
test_known_broken_failure_ () {
336339
test_broken=$(($test_broken+1))
337-
say_color warn "not ok $test_count - $@ # TODO known breakage"
340+
say_color warn "${statusprefix}not ok $test_count - $@ # TODO known breakage"
338341
}
339342

340343
test_debug () {
@@ -458,8 +461,8 @@ test_skip () {
458461
of_prereq=" of $test_prereq"
459462
fi
460463

461-
say_color skip >&3 "skipping test: $@"
462-
say_color skip "ok $test_count # skip $1 (missing $missing_prereq${of_prereq})"
464+
say_color skip >&3 "${statusprefix}skipping test: $@"
465+
say_color skip "${statusprefix}ok $test_count # skip $1 (missing $missing_prereq${of_prereq})"
463466
: true
464467
;;
465468
*)
@@ -497,11 +500,11 @@ test_done () {
497500

498501
if test "$test_fixed" != 0
499502
then
500-
say_color error "# $test_fixed known breakage(s) vanished; please update test(s)"
503+
say_color error "${statusprefix}# $test_fixed known breakage(s) vanished; please update test(s)"
501504
fi
502505
if test "$test_broken" != 0
503506
then
504-
say_color warn "# still have $test_broken known breakage(s)"
507+
say_color warn "${statusprefix}# still have $test_broken known breakage(s)"
505508
fi
506509
if test "$test_broken" != 0 || test "$test_fixed" != 0
507510
then
@@ -524,9 +527,9 @@ test_done () {
524527
then
525528
if test $test_remaining -gt 0
526529
then
527-
say_color pass "# passed all $msg"
530+
say_color pass "${statusprefix}# passed all $msg"
528531
fi
529-
say "1..$test_count$skip_all"
532+
say "${statusprefix}1..$test_count$skip_all"
530533
fi
531534

532535
test -d "$remove_trash" &&
@@ -540,8 +543,8 @@ test_done () {
540543
*)
541544
if test $test_external_has_tap -eq 0
542545
then
543-
say_color error "# failed $test_failure among $msg"
544-
say "1..$test_count"
546+
say_color error "${statusprefix}# failed $test_failure among $msg"
547+
say "${statusprefix}1..$test_count"
545548
fi
546549

547550
exit 1 ;;

0 commit comments

Comments
 (0)