Commit a24df71e authored by Tor Didriksen's avatar Tor Didriksen

Backport of 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/Makefile.am:
  Omit core-t, since it will always fail.
unittest/examples/no_plan-t.c:
  Comment that we recommend calling plan(NO_PLAN)
unittest/mytap/tap.c:
  Use the named constant NO_PLAN
  Flush all output.
unittest/mytap/tap.h:
  Change documentation for the plan() function.
parent 34ceaa6a
...@@ -20,7 +20,8 @@ AM_LDFLAGS = -L$(top_builddir)/unittest/mytap ...@@ -20,7 +20,8 @@ AM_LDFLAGS = -L$(top_builddir)/unittest/mytap
LDADD = -lmytap LDADD = -lmytap
noinst_PROGRAMS = simple-t skip-t todo-t skip_all-t no_plan-t core-t # We omit core-t here, since it will always fail.
noinst_PROGRAMS = simple-t skip-t todo-t skip_all-t no_plan-t
# Don't update the files from bitkeeper # Don't update the files from bitkeeper
%::SCCS/s.% %::SCCS/s.%
/* 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 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 it under the terms of the GNU General Public License as published by
...@@ -20,14 +20,19 @@ ...@@ -20,14 +20,19 @@
/* /*
Sometimes, the number of tests is not known beforehand. In those Sometimes, the number of tests is not known beforehand. In those
cases, the plan can be omitted and will instead be written at the cases, you should invoke plan(NO_PLAN).
end of the test (inside exit_status()). 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 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 are going to run will help you catch that offending case when some
tests are skipped for an unknown reason. tests are skipped for an unknown reason.
*/ */
int main() { 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, " "); ok(1, " ");
ok(1, " "); ok(1, " ");
......
/* 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 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 it under the terms of the GNU General Public License as published by
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
@ingroup MyTAP_Internal @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. Output stream for test report message.
...@@ -74,6 +74,7 @@ vemit_tap(int pass, char const *fmt, va_list ap) ...@@ -74,6 +74,7 @@ vemit_tap(int pass, char const *fmt, va_list ap)
(fmt && *fmt) ? " - " : ""); (fmt && *fmt) ? " - " : "");
if (fmt && *fmt) if (fmt && *fmt)
vfprintf(tapout, fmt, ap); vfprintf(tapout, fmt, ap);
fflush(tapout);
} }
...@@ -96,6 +97,7 @@ static void ...@@ -96,6 +97,7 @@ static void
emit_dir(const char *dir, const char *why) emit_dir(const char *dir, const char *why)
{ {
fprintf(tapout, " # %s %s", dir, why); fprintf(tapout, " # %s %s", dir, why);
fflush(tapout);
} }
...@@ -108,6 +110,7 @@ static void ...@@ -108,6 +110,7 @@ static void
emit_endl() emit_endl()
{ {
fprintf(tapout, "\n"); fprintf(tapout, "\n");
fflush(tapout);
} }
static void static void
...@@ -183,7 +186,10 @@ plan(int const count) ...@@ -183,7 +186,10 @@ plan(int const count)
break; break;
default: default:
if (count > 0) if (count > 0)
{
fprintf(tapout, "1..%d\n", count); fprintf(tapout, "1..%d\n", count);
fflush(tapout);
}
break; break;
} }
} }
...@@ -196,6 +202,7 @@ skip_all(char const *reason, ...) ...@@ -196,6 +202,7 @@ skip_all(char const *reason, ...)
va_start(ap, reason); va_start(ap, reason);
fprintf(tapout, "1..0 # skip "); fprintf(tapout, "1..0 # skip ");
vfprintf(tapout, reason, ap); vfprintf(tapout, reason, ap);
fflush(tapout);
va_end(ap); va_end(ap);
exit(0); exit(0);
} }
...@@ -218,7 +225,7 @@ ok(int const pass, char const *fmt, ...) ...@@ -218,7 +225,7 @@ ok(int const pass, char const *fmt, ...)
void void
skip(int how_many, char const *const fmt, ...) skip(int how_many, char const *fmt, ...)
{ {
char reason[80]; char reason[80];
if (fmt && *fmt) if (fmt && *fmt)
......
/* 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 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 it under the terms of the GNU General Public License as published by
...@@ -72,10 +72,9 @@ extern "C" { ...@@ -72,10 +72,9 @@ extern "C" {
/** /**
Set number of tests that is planned to execute. Set number of tests that is planned to execute.
The function also accepts the predefined constant The function also accepts the predefined constant <code>NO_PLAN</code>.
<code>NO_PLAN</code>. If the function is not called, it is as if If invoked with this constant -- or not invoked at all --
it was called with <code>NO_PLAN</code>, i.e., the test plan will the test plan will be printed after all the test lines.
be printed after all the test lines.
The plan() function will install signal handlers for all signals The plan() function will install signal handlers for all signals
that generate a core, so if you want to override these signals, do that generate a core, so if you want to override these signals, do
...@@ -84,7 +83,7 @@ extern "C" { ...@@ -84,7 +83,7 @@ extern "C" {
@param count The planned number of tests to run. @param count The planned number of tests to run.
*/ */
void plan(int count); void plan(int const count);
/** /**
...@@ -103,7 +102,7 @@ void plan(int count); ...@@ -103,7 +102,7 @@ void plan(int count);
which case nothing is printed. which case nothing is printed.
*/ */
void ok(int pass, char const *fmt, ...) void ok(int const pass, char const *fmt, ...)
__attribute__((format(printf,2,3))); __attribute__((format(printf,2,3)));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment