#At file:///export/home/didrik/mysqldev-next-mr/next-mr-bf-cmake/ based on revid:marc.alff@stripped
3161 Tor Didriksen 2010-05-04
Bug#53303 mytap tests should always have a plan()
The bug was caused by buffered output. Flushing resolved it.
We still recommend to allways call plan().
Also fix some compile warnings (formal parameter different from declaration)
@ unittest/examples/no_plan-t.c
Always invoke plan()
@ unittest/mytap/tap.c
Use the named constant NO_PLAN
Flush all output.
@ unittest/mytap/tap.h
Change documentation for the plan() function.
modified:
unittest/examples/no_plan-t.c
unittest/mytap/tap.c
unittest/mytap/tap.h
=== modified file 'unittest/examples/no_plan-t.c'
--- a/unittest/examples/no_plan-t.c 2009-11-18 04:29:26 +0000
+++ b/unittest/examples/no_plan-t.c 2010-05-04 06:27:29 +0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2006 MySQL AB
+/* Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -20,14 +20,19 @@
/*
Sometimes, the number of tests is not known beforehand. In those
- cases, the plan can be omitted and will instead be written at the
- end of the test (inside exit_status()).
+ cases, you should invoke plan(NO_PLAN).
+ The plan will be printed at the end of the test (inside exit_status()).
Use this sparingly, it is a last resort: planning how many tests you
are going to run will help you catch that offending case when some
tests are skipped for an unknown reason.
*/
int main() {
+ /*
+ We recommend calling plan(NO_PLAN), but want to verify that
+ omitting the call works as well.
+ plan(NO_PLAN);
+ */
ok(1, " ");
ok(1, " ");
ok(1, " ");
=== modified file 'unittest/mytap/tap.c'
--- a/unittest/mytap/tap.c 2010-04-28 12:43:01 +0000
+++ b/unittest/mytap/tap.c 2010-05-04 06:27:29 +0000
@@ -51,7 +51,7 @@
@ingroup MyTAP_Internal
*/
-static TEST_DATA g_test = { 0, 0, 0, "" };
+static TEST_DATA g_test = { NO_PLAN, 0, 0, "" };
/**
Output stream for test report message.
@@ -85,6 +85,7 @@ vemit_tap(int pass, char const *fmt, va_
(fmt && *fmt) ? " - " : "");
if (fmt && *fmt)
vfprintf(tapout, fmt, ap);
+ fflush(tapout);
}
@@ -107,6 +108,7 @@ static void
emit_dir(const char *dir, const char *why)
{
fprintf(tapout, " # %s %s", dir, why);
+ fflush(tapout);
}
@@ -119,6 +121,7 @@ static void
emit_endl()
{
fprintf(tapout, "\n");
+ fflush(tapout);
}
static void
@@ -189,7 +192,7 @@ static signal_entry install_signal[]= {
int skip_big_tests= 1;
void
-plan(int count)
+plan(int const count)
{
char *config= getenv("MYTAP_CONFIG");
size_t i;
@@ -197,7 +200,6 @@ plan(int count)
if (config)
skip_big_tests= strcmp(config, "big");
- setvbuf(tapout, 0, _IONBF, 0); /* provide output at once */
/*
Install signal handler
*/
@@ -212,7 +214,10 @@ plan(int count)
break;
default:
if (count > 0)
+ {
fprintf(tapout, "1..%d\n", count);
+ fflush(tapout);
+ }
break;
}
}
@@ -225,12 +230,13 @@ skip_all(char const *reason, ...)
va_start(ap, reason);
fprintf(tapout, "1..0 # skip ");
vfprintf(tapout, reason, ap);
+ fflush(tapout);
va_end(ap);
exit(0);
}
void
-ok(int pass, char const *fmt, ...)
+ok(int const pass, char const *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
=== modified file 'unittest/mytap/tap.h'
--- a/unittest/mytap/tap.h 2009-11-18 04:29:26 +0000
+++ b/unittest/mytap/tap.h 2010-05-04 06:27:29 +0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2006 MySQL AB
+/* Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -90,10 +90,9 @@ extern int skip_big_tests;
/**
Set number of tests that is planned to execute.
- The function also accepts the predefined constant
- <code>NO_PLAN</code>. If the function is not called, it is as if
- it was called with <code>NO_PLAN</code>, i.e., the test plan will
- be printed after all the test lines.
+ The function also accepts the predefined constant <code>NO_PLAN</code>.
+ If invoked with this constant -- or not invoked at all --
+ the test plan will be printed after all the test lines.
The plan() function will install signal handlers for all signals
that generate a core, so if you want to override these signals, do
@@ -158,7 +157,7 @@ void ok(int const pass, char const *fmt,
@param reason A reason for skipping the tests
*/
-void skip(int how_many, char const *const reason, ...)
+void skip(int how_many, char const *reason, ...)
__attribute__((format(printf,2,3)));
Attachment: [text/bzr-bundle] bzr/tor.didriksen@sun.com-20100504062729-9tw96o7h03bwmfmh.bundle