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 <trast@inf.ethz.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Thomas Rast committed
Jun 23, 2013 at 20:12 UTC
e939e15d241e942662b9f88f6127ab470ab0a0b9
1 file changed
+15
-12
t/test-lib.sh
+15
-12
@@ -209,6 +209,9 @@ do
209
--root=*)
210
root=$(expr "z$1" : 'z[^=]*=\(.*\)')
211
shift ;;
212
+ --statusprefix=*)
213
+ statusprefix=$(expr "z$1" : 'z[^=]*=\(.*\)')
214
+ shift ;;
215
*)
216
echo "error: unknown test option '$1'" >&2; exit 1 ;;
217
esac
@@ -316,12 +319,12 @@ trap 'die' EXIT
319
320
test_ok_ () {
321
test_success=$(($test_success + 1))
319
- say_color "" "ok $test_count - $@"
322
+ say_color "" "${statusprefix}ok $test_count - $@"
323
}
324
325
test_failure_ () {
326
test_failure=$(($test_failure + 1))
324
- say_color error "not ok $test_count - $1"
327
+ say_color error "${statusprefix}not ok $test_count - $1"
328
shift
329
echo "$@" | sed -e 's/^/# /'
330
test "$immediate" = "" || { GIT_EXIT_OK=t; exit 1; }
@@ -329,12 +332,12 @@ test_failure_ () {
332
333
test_known_broken_ok_ () {
334
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"
336
}
337
338
test_known_broken_failure_ () {
339
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"
341
}
342
343
test_debug () {
@@ -458,8 +461,8 @@ test_skip () {
461
of_prereq=" of $test_prereq"
462
fi
463
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})"
466
: true
467
;;
468
*)
@@ -497,11 +500,11 @@ test_done () {
500
501
if test "$test_fixed" != 0
502
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)"
504
fi
505
if test "$test_broken" != 0
506
then
504
- say_color warn "# still have $test_broken known breakage(s)"
507
+ say_color warn "${statusprefix}# still have $test_broken known breakage(s)"
508
fi
509
if test "$test_broken" != 0 || test "$test_fixed" != 0
510
then
@@ -524,9 +527,9 @@ test_done () {
527
then
528
if test $test_remaining -gt 0
529
then
527
- say_color pass "# passed all $msg"
530
+ say_color pass "${statusprefix}# passed all $msg"
531
fi
529
- say "1..$test_count$skip_all"
532
+ say "${statusprefix}1..$test_count$skip_all"
533
fi
534
535
test -d "$remove_trash" &&
@@ -540,8 +543,8 @@ test_done () {
543
*)
544
if test $test_external_has_tap -eq 0
545
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"
548
fi
549
550
exit 1 ;;