@matheusbsbs / matheus-bagliano / commits / d998bd4ab6
Fork 0

test-lib: Make the test_external_* functions TAP-aware

Before TAP we just ran the Perl test and assumed that it failed if nothing was printed on STDERR. Continue doing that, but introduce a `test_external_has_tap' variable which tests can set to indicate that they're outputting TAP. If it's set we won't output a test plan, but trust the external test to do so. That way we can make external tests work with a TAP harness, but still maintain compatibility with test-lib's own way of tracking tests through the test-results directory. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Jun 24, 2010 at 17:44 UTC d998bd4ab6714051ad122f89489ddbca2bb3367b
3 files changed +53 -12
t/t9700-perl-git.sh
+3
@@ -46,6 +46,9 @@ test_expect_success \
46 git config --add test.int 2k
47 '
48
49 +# The external test will outputs its own plan
50 +test_external_has_tap=1
51 +
52 test_external_without_stderr \
53 'Perl API' \
54 "$PERL_PATH" "$TEST_DIRECTORY"/t9700/test.pl
t/t9700/test.pl
+11
@@ -7,6 +7,13 @@ use strict;
7
8 use Test::More qw(no_plan);
9
10 +BEGIN {
11 + # t9700-perl-git.sh kicks off our testing, so we have to go from
12 + # there.
13 + $Test::Builder::Test->{Curr_Test} = 1;
14 + $Test::Builder::Test->{No_Ending} = 1;
15 +}
16 +
17 use Cwd;
18 use File::Basename;
19
@@ -105,3 +112,7 @@ my $last_commit = $r2->command_oneline(qw(rev-parse --verify HEAD));
112 like($last_commit, qr/^[0-9a-fA-F]{40}$/, 'rev-parse returned hash');
113 my $dir_commit = $r2->command_oneline('log', '-n1', '--pretty=format:%H', '.');
114 isnt($last_commit, $dir_commit, 'log . does not show last commit');
115 +
116 +printf "1..%d\n", $Test::Builder::Test->{Curr_Test};
117 +
118 +exit($Test::Builder::Test->{Is_Passing} ? 0 : 1);
t/test-lib.sh
+39 -12
@@ -206,6 +206,8 @@ test_fixed=0
206 test_broken=0
207 test_success=0
208
209 +test_external_has_tap=0
210 +
211 die () {
212 code=$?
213 if test -n "$GIT_EXIT_OK"
@@ -456,7 +458,7 @@ test_expect_code () {
458 # test_external runs external test scripts that provide continuous
459 # test output about their progress, and succeeds/fails on
460 # zero/non-zero exit code. It outputs the test output on stdout even
459 -# in non-verbose mode, and announces the external script with "* run
461 +# in non-verbose mode, and announces the external script with "# run
462 # <n>: ..." before running it. When providing relative paths, keep in
463 # mind that all scripts run in "trash directory".
464 # Usage: test_external description command arguments...
@@ -471,7 +473,7 @@ test_external () {
473 then
474 # Announce the script to reduce confusion about the
475 # test output that follows.
474 - say_color "" " run $test_count: $descr ($*)"
476 + say_color "" "# run $test_count: $descr ($*)"
477 # Export TEST_DIRECTORY, TRASH_DIRECTORY and GIT_TEST_LONG
478 # to be able to use them in script
479 export TEST_DIRECTORY TRASH_DIRECTORY GIT_TEST_LONG
@@ -481,9 +483,19 @@ test_external () {
483 "$@" 2>&4
484 if [ "$?" = 0 ]
485 then
484 - test_ok_ "$descr"
486 + if test $test_external_has_tap -eq 0; then
487 + test_ok_ "$descr"
488 + else
489 + say_color "" "# test_external test $descr was ok"
490 + test_success=$(($test_success + 1))
491 + fi
492 else
486 - test_failure_ "$descr" "$@"
493 + if test $test_external_has_tap -eq 0; then
494 + test_failure_ "$descr" "$@"
495 + else
496 + say_color error "# test_external test $descr failed: $@"
497 + test_failure=$(($test_failure + 1))
498 + fi
499 fi
500 fi
501 }
@@ -499,19 +511,30 @@ test_external_without_stderr () {
511 [ -f "$stderr" ] || error "Internal error: $stderr disappeared."
512 descr="no stderr: $1"
513 shift
502 - say >&3 "expecting no stderr from previous command"
514 + say >&3 "# expecting no stderr from previous command"
515 if [ ! -s "$stderr" ]; then
516 rm "$stderr"
505 - test_ok_ "$descr"
517 +
518 + if test $test_external_has_tap -eq 0; then
519 + test_ok_ "$descr"
520 + else
521 + say_color "" "# test_external_without_stderr test $descr was ok"
522 + test_success=$(($test_success + 1))
523 + fi
524 else
525 if [ "$verbose" = t ]; then
508 - output=`echo; echo Stderr is:; cat "$stderr"`
526 + output=`echo; echo "# Stderr is:"; cat "$stderr"`
527 else
528 output=
529 fi
530 # rm first in case test_failure exits.
531 rm "$stderr"
514 - test_failure_ "$descr" "$@" "$output"
532 + if test $test_external_has_tap -eq 0; then
533 + test_failure_ "$descr" "$@" "$output"
534 + else
535 + say_color error "# test_external_without_stderr test $descr failed: $@: $output"
536 + test_failure=$(($test_failure + 1))
537 + fi
538 fi
539 }
540
@@ -634,8 +657,10 @@ test_done () {
657 # Maybe print SKIP message
658 [ -z "$skip_all" ] || skip_all=" # SKIP $skip_all"
659
637 - say_color pass "# passed all $msg"
638 - say "1..$test_count$skip_all"
660 + if test $test_external_has_tap -eq 0; then
661 + say_color pass "# passed all $msg"
662 + say "1..$test_count$skip_all"
663 + fi
664
665 test -d "$remove_trash" &&
666 cd "$(dirname "$remove_trash")" &&
@@ -644,8 +669,10 @@ test_done () {
669 exit 0 ;;
670
671 *)
647 - say_color error "# failed $test_failure among $msg"
648 - say "1..$test_count"
672 + if test $test_external_has_tap -eq 0; then
673 + say_color error "# failed $test_failure among $msg"
674 + say "1..$test_count"
675 + fi
676
677 exit 1 ;;
678