1
/* Copyright (C) 2006 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
Library for providing TAP support for testing C and C++ was written
17
by Mats Kindahl <mats@mysql.com>.
23
#include "my_global.h"
26
@defgroup MyTAP MySQL support for performing unit tests according to
27
the Test Anything Protocol (TAP).
35
@ingroup MyTAP_Internal
37
@internal We are using the "typedef struct X { ... } X" idiom to
38
create class/struct X both in C and C++.
41
typedef struct TEST_DATA {
43
Number of tests that is planned to execute.
45
Can be zero (<code>NO_PLAN</code>) meaning that the plan string
46
will be printed at the end of test instead.
50
/** Number of last test that was done or skipped. */
53
/** Number of tests that failed. */
65
@defgroup MyTAP_API MyTAP API
67
MySQL support for performing unit tests according to TAP.
73
Set number of tests that is planned to execute.
75
The function also accepts the predefined constant
76
<code>NO_PLAN</code>. If the function is not called, it is as if
77
it was called with <code>NO_PLAN</code>, i.e., the test plan will
78
be printed after all the test lines.
80
The plan() function will install signal handlers for all signals
81
that generate a core, so if you want to override these signals, do
82
it <em>after</em> you have called the plan() function.
84
@param count The planned number of tests to run.
87
void plan(int const count);
91
Report test result as a TAP line.
93
Function used to write status of an individual test. Call this
94
function in the following manner:
98
"%d ducks did not paddle", ducks - paddling);
101
@param pass Zero if the test failed, non-zero if it passed.
102
@param fmt Format string in printf() format. NULL is allowed, in
103
which case nothing is printed.
106
void ok(int const pass, char const *fmt, ...)
107
__attribute__((format(printf,2,3)));
111
Skip a determined number of tests.
113
Function to print that <em>how_many</em> tests have been skipped.
114
The reason is printed for each skipped test. Observe that this
115
function does not do the actual skipping for you, it just prints
116
information that tests have been skipped. This function is not
117
usually used, but rather the macro @c SKIP_BLOCK_IF, which does the
120
It shall be used in the following manner:
124
skip(2, "No ducks in the pond");
127
for (i = 0 ; i < 2 ; ++i)
128
ok(duck[i] == paddling, "is duck %d paddling?", i);
134
@param how_many Number of tests that are to be skipped.
135
@param reason A reason for skipping the tests
138
void skip(int how_many, char const *const reason, ...)
139
__attribute__((format(printf,2,3)));
143
Helper macro to skip a block of code. The macro can be used to
144
simplify conditionally skipping a block of code. It is used in the
148
SKIP_BLOCK_IF(ducks == 0, 2, "No ducks in the pond")
151
for (i = 0 ; i < 2 ; ++i)
152
ok(duck[i] == paddling, "is duck %d paddling?", i);
159
#define SKIP_BLOCK_IF(SKIP_IF_TRUE, COUNT, REASON) \
160
if (SKIP_IF_TRUE) skip((COUNT),(REASON)); else
164
Print a diagnostics message.
166
@param fmt Diagnostics message in printf() format.
169
void diag(char const *fmt, ...)
170
__attribute__((format(printf,1,2)));
174
Print a bail out message.
176
A bail out message can be issued when no further testing can be
177
done, e.g., when there are missing dependencies.
179
The test will exit with status 255. This function does not return.
182
BAIL_OUT("Lost connection to server %s", server_name);
185
@note A bail out message is printed if a signal that generates a
188
@param fmt Bail out message in printf() format.
191
void BAIL_OUT(char const *fmt, ...)
192
__attribute__((noreturn, format(printf,1,2)));
196
Print summary report and return exit status.
198
This function will print a summary report of how many tests passed,
199
how many were skipped, and how many remains to do. The function
200
should be called after all tests are executed in the following
204
return exit_status();
207
@returns @c EXIT_SUCCESS if all tests passed, @c EXIT_FAILURE if
208
one or more tests failed.
211
int exit_status(void);
215
Skip entire test suite.
217
To skip the entire test suite, use this function. It will
218
automatically call exit(), so there is no need to have checks
222
void skip_all(char const *reason, ...)
223
__attribute__((noreturn, format(printf, 1, 2)));
227
Start section of tests that are not yet ready.
229
To start a section of tests that are not ready and are expected to
230
fail, use this function and todo_end() in the following manner:
233
todo_start("Not ready yet");
234
ok(is_rocketeering(duck), "Rocket-propelled ducks");
235
ok(is_kamikaze(duck), "Kamikaze ducks");
242
It is not possible to nest todo sections.
244
@param message Message that will be printed before the todo tests.
247
void todo_start(char const *message, ...)
248
__attribute__((format(printf, 1, 2)));
252
End a section of tests that are not yet ready.