提交 d998bd4a 编写于 作者: Æ Ævar Arnfjörð Bjarmason 提交者: Junio C Hamano

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: NÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 5099b99d
...@@ -46,6 +46,9 @@ test_expect_success \ ...@@ -46,6 +46,9 @@ test_expect_success \
git config --add test.int 2k git config --add test.int 2k
' '
# The external test will outputs its own plan
test_external_has_tap=1
test_external_without_stderr \ test_external_without_stderr \
'Perl API' \ 'Perl API' \
"$PERL_PATH" "$TEST_DIRECTORY"/t9700/test.pl "$PERL_PATH" "$TEST_DIRECTORY"/t9700/test.pl
......
...@@ -7,6 +7,13 @@ ...@@ -7,6 +7,13 @@
use Test::More qw(no_plan); use Test::More qw(no_plan);
BEGIN {
# t9700-perl-git.sh kicks off our testing, so we have to go from
# there.
$Test::Builder::Test->{Curr_Test} = 1;
$Test::Builder::Test->{No_Ending} = 1;
}
use Cwd; use Cwd;
use File::Basename; use File::Basename;
...@@ -105,3 +112,7 @@ ...@@ -105,3 +112,7 @@
like($last_commit, qr/^[0-9a-fA-F]{40}$/, 'rev-parse returned hash'); like($last_commit, qr/^[0-9a-fA-F]{40}$/, 'rev-parse returned hash');
my $dir_commit = $r2->command_oneline('log', '-n1', '--pretty=format:%H', '.'); my $dir_commit = $r2->command_oneline('log', '-n1', '--pretty=format:%H', '.');
isnt($last_commit, $dir_commit, 'log . does not show last commit'); isnt($last_commit, $dir_commit, 'log . does not show last commit');
printf "1..%d\n", $Test::Builder::Test->{Curr_Test};
exit($Test::Builder::Test->{Is_Passing} ? 0 : 1);
...@@ -206,6 +206,8 @@ test_fixed=0 ...@@ -206,6 +206,8 @@ test_fixed=0
test_broken=0 test_broken=0
test_success=0 test_success=0
test_external_has_tap=0
die () { die () {
code=$? code=$?
if test -n "$GIT_EXIT_OK" if test -n "$GIT_EXIT_OK"
...@@ -456,7 +458,7 @@ test_expect_code () { ...@@ -456,7 +458,7 @@ test_expect_code () {
# test_external runs external test scripts that provide continuous # test_external runs external test scripts that provide continuous
# test output about their progress, and succeeds/fails on # test output about their progress, and succeeds/fails on
# zero/non-zero exit code. It outputs the test output on stdout even # zero/non-zero exit code. It outputs the test output on stdout even
# in non-verbose mode, and announces the external script with "* run # in non-verbose mode, and announces the external script with "# run
# <n>: ..." before running it. When providing relative paths, keep in # <n>: ..." before running it. When providing relative paths, keep in
# mind that all scripts run in "trash directory". # mind that all scripts run in "trash directory".
# Usage: test_external description command arguments... # Usage: test_external description command arguments...
...@@ -471,7 +473,7 @@ test_external () { ...@@ -471,7 +473,7 @@ test_external () {
then then
# Announce the script to reduce confusion about the # Announce the script to reduce confusion about the
# test output that follows. # test output that follows.
say_color "" " run $test_count: $descr ($*)" say_color "" "# run $test_count: $descr ($*)"
# Export TEST_DIRECTORY, TRASH_DIRECTORY and GIT_TEST_LONG # Export TEST_DIRECTORY, TRASH_DIRECTORY and GIT_TEST_LONG
# to be able to use them in script # to be able to use them in script
export TEST_DIRECTORY TRASH_DIRECTORY GIT_TEST_LONG export TEST_DIRECTORY TRASH_DIRECTORY GIT_TEST_LONG
...@@ -481,9 +483,19 @@ test_external () { ...@@ -481,9 +483,19 @@ test_external () {
"$@" 2>&4 "$@" 2>&4
if [ "$?" = 0 ] if [ "$?" = 0 ]
then then
test_ok_ "$descr" if test $test_external_has_tap -eq 0; then
test_ok_ "$descr"
else
say_color "" "# test_external test $descr was ok"
test_success=$(($test_success + 1))
fi
else else
test_failure_ "$descr" "$@" if test $test_external_has_tap -eq 0; then
test_failure_ "$descr" "$@"
else
say_color error "# test_external test $descr failed: $@"
test_failure=$(($test_failure + 1))
fi
fi fi
fi fi
} }
...@@ -499,19 +511,30 @@ test_external_without_stderr () { ...@@ -499,19 +511,30 @@ test_external_without_stderr () {
[ -f "$stderr" ] || error "Internal error: $stderr disappeared." [ -f "$stderr" ] || error "Internal error: $stderr disappeared."
descr="no stderr: $1" descr="no stderr: $1"
shift shift
say >&3 "expecting no stderr from previous command" say >&3 "# expecting no stderr from previous command"
if [ ! -s "$stderr" ]; then if [ ! -s "$stderr" ]; then
rm "$stderr" rm "$stderr"
test_ok_ "$descr"
if test $test_external_has_tap -eq 0; then
test_ok_ "$descr"
else
say_color "" "# test_external_without_stderr test $descr was ok"
test_success=$(($test_success + 1))
fi
else else
if [ "$verbose" = t ]; then if [ "$verbose" = t ]; then
output=`echo; echo Stderr is:; cat "$stderr"` output=`echo; echo "# Stderr is:"; cat "$stderr"`
else else
output= output=
fi fi
# rm first in case test_failure exits. # rm first in case test_failure exits.
rm "$stderr" rm "$stderr"
test_failure_ "$descr" "$@" "$output" if test $test_external_has_tap -eq 0; then
test_failure_ "$descr" "$@" "$output"
else
say_color error "# test_external_without_stderr test $descr failed: $@: $output"
test_failure=$(($test_failure + 1))
fi
fi fi
} }
...@@ -634,8 +657,10 @@ test_done () { ...@@ -634,8 +657,10 @@ test_done () {
# Maybe print SKIP message # Maybe print SKIP message
[ -z "$skip_all" ] || skip_all=" # SKIP $skip_all" [ -z "$skip_all" ] || skip_all=" # SKIP $skip_all"
say_color pass "# passed all $msg" if test $test_external_has_tap -eq 0; then
say "1..$test_count$skip_all" say_color pass "# passed all $msg"
say "1..$test_count$skip_all"
fi
test -d "$remove_trash" && test -d "$remove_trash" &&
cd "$(dirname "$remove_trash")" && cd "$(dirname "$remove_trash")" &&
...@@ -644,8 +669,10 @@ test_done () { ...@@ -644,8 +669,10 @@ test_done () {
exit 0 ;; exit 0 ;;
*) *)
say_color error "# failed $test_failure among $msg" if test $test_external_has_tap -eq 0; then
say "1..$test_count" say_color error "# failed $test_failure among $msg"
say "1..$test_count"
fi
exit 1 ;; exit 1 ;;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册