Commit 0220e4ff authored by unknown's avatar unknown

mytap-changes.patch


unittest/Makefile.am:
  Import patch mytap-changes.patch
unittest/README.txt:
  Import patch mytap-changes.patch
unittest/examples/Makefile.am:
  Import patch mytap-changes.patch
unittest/mytap/tap.c:
  Import patch mytap-changes.patch
unittest/mytap/tap.h:
  Import patch mytap-changes.patch
parent 9cb377f9
...@@ -6,10 +6,9 @@ CLEANFILES = unit ...@@ -6,10 +6,9 @@ CLEANFILES = unit
unittests = mytap mysys unittests = mytap mysys
test: unit test:
./unit run $(unittests) perl unit.pl run $(unittests)
unit: $(srcdir)/unit.pl unit: $(srcdir)/unit.pl
cp $(srcdir)/unit.pl $@ install $(srcdir)/unit.pl $@
chmod 700 $@
...@@ -9,7 +9,9 @@ mytap Source for the MyTAP library ...@@ -9,7 +9,9 @@ mytap Source for the MyTAP library
mysys Tests for mysys components mysys Tests for mysys components
bitmap-t.c Unit test for MY_BITMAP bitmap-t.c Unit test for MY_BITMAP
base64-t.c Unit test for base64 encoding functions base64-t.c Unit test for base64 encoding functions
examples Example unit tests examples Example unit tests.
core-t.c Example of raising a signal in the middle of the test
THIS TEST WILL STOP ALL FURTHER TESTING!
simple-t.c Example of a standard TAP unit test simple-t.c Example of a standard TAP unit test
skip-t.c Example where some test points are skipped skip-t.c Example where some test points are skipped
skip_all-t.c Example of a test where the entire test is skipped skip_all-t.c Example of a test where the entire test is skipped
...@@ -24,6 +26,9 @@ To make and execute all unit tests in the directory: ...@@ -24,6 +26,9 @@ To make and execute all unit tests in the directory:
make test make test
Observe that the tests in the examples/ directory are just various
examples of tests and are not expected to pass.
Adding unit tests Adding unit tests
----------------- -----------------
......
...@@ -5,5 +5,5 @@ AM_LDFLAGS = -L$(top_builddir)/unittest/mytap ...@@ -5,5 +5,5 @@ 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 noinst_PROGRAMS = simple-t skip-t todo-t skip_all-t no_plan-t core-t
...@@ -20,10 +20,13 @@ ...@@ -20,10 +20,13 @@
#include "tap.h" #include "tap.h"
#include "my_config.h"
#include <stdlib.h> #include <stdlib.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <signal.h>
/** /**
Test data structure. Test data structure.
...@@ -70,7 +73,7 @@ emit_tap(int pass, char const *fmt, va_list ap) ...@@ -70,7 +73,7 @@ emit_tap(int pass, char const *fmt, va_list ap)
/** /**
Emit a TAP directive. Emit a TAP directive.
TAP directives are comments after a have the form TAP directives are comments after that have the form:
@code @code
ok 1 # skip reason for skipping ok 1 # skip reason for skipping
...@@ -96,6 +99,25 @@ emit_endl() ...@@ -96,6 +99,25 @@ emit_endl()
fprintf(tapout, "\n"); fprintf(tapout, "\n");
} }
static void
handle_core_signal(int signo)
{
BAIL_OUT("Signal %d thrown", signo);
}
void
BAIL_OUT(char const *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
fprintf(tapout, "Bail out! ");
vfprintf(tapout, fmt, ap);
emit_endl();
va_end(ap);
exit(255);
}
void void
diag(char const *fmt, ...) diag(char const *fmt, ...)
{ {
...@@ -103,14 +125,38 @@ diag(char const *fmt, ...) ...@@ -103,14 +125,38 @@ diag(char const *fmt, ...)
va_start(ap, fmt); va_start(ap, fmt);
fprintf(tapout, "# "); fprintf(tapout, "# ");
vfprintf(tapout, fmt, ap); vfprintf(tapout, fmt, ap);
fprintf(tapout, "\n"); emit_endl();
va_end(ap); va_end(ap);
} }
typedef struct signal_entry {
int signo;
void (*handler)(int);
} signal_entry;
static signal_entry install_signal[]= {
{ SIGQUIT, handle_core_signal },
{ SIGILL, handle_core_signal },
{ SIGABRT, handle_core_signal },
{ SIGFPE, handle_core_signal },
{ SIGSEGV, handle_core_signal },
{ SIGBUS, handle_core_signal },
{ SIGXCPU, handle_core_signal },
{ SIGXFSZ, handle_core_signal },
{ SIGSYS, handle_core_signal },
{ SIGTRAP, handle_core_signal }
};
void void
plan(int const count) plan(int const count)
{ {
/*
Install signal handler
*/
size_t i;
for (i= 0; i < sizeof(install_signal)/sizeof(*install_signal); ++i)
signal(install_signal[i].signo, install_signal[i].handler);
g_test.plan= count; g_test.plan= count;
switch (count) switch (count)
{ {
......
...@@ -21,8 +21,6 @@ ...@@ -21,8 +21,6 @@
#ifndef TAP_H #ifndef TAP_H
#define TAP_H #define TAP_H
#include "my_global.h"
/* /*
@defgroup MyTAP MySQL support for performing unit tests according to TAP. @defgroup MyTAP MySQL support for performing unit tests according to TAP.
...@@ -67,6 +65,10 @@ extern "C" { ...@@ -67,6 +65,10 @@ extern "C" {
it was called with <code>NO_PLAN</code>, i.e., the test plan will it was called with <code>NO_PLAN</code>, i.e., 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
that generate a core, so if you want to override these signals, do
it <em>after</em> you have called the plan() function.
@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 count);
...@@ -130,10 +132,9 @@ void skip(int how_many, char const *reason, ...) ...@@ -130,10 +132,9 @@ void skip(int how_many, char const *reason, ...)
for (i = 0 ; i < 2 ; ++i) for (i = 0 ; i < 2 ; ++i)
ok(duck[i] == paddling, "is duck %d paddling?", i); ok(duck[i] == paddling, "is duck %d paddling?", i);
} }
@endcode
@see skip @see skip
@endcode
*/ */
#define SKIP_BLOCK_IF(SKIP_IF_TRUE, COUNT, REASON) \ #define SKIP_BLOCK_IF(SKIP_IF_TRUE, COUNT, REASON) \
if (SKIP_IF_TRUE) skip((COUNT),(REASON)); else if (SKIP_IF_TRUE) skip((COUNT),(REASON)); else
...@@ -146,6 +147,24 @@ void skip(int how_many, char const *reason, ...) ...@@ -146,6 +147,24 @@ void skip(int how_many, char const *reason, ...)
void diag(char const *fmt, ...) void diag(char const *fmt, ...)
__attribute__((format(printf,1,2))); __attribute__((format(printf,1,2)));
/**
Print a bail out message.
A bail out message can be issued when no further testing can be
done, e.g., when there are missing dependencies.
The test will exit with status 255. This function does not return.
@note A bail out message is printed if a signal that generates a
core is raised.
@param fmt Bail out message in printf() format.
*/
void BAIL_OUT(char const *fmt, ...)
__attribute__((noreturn, format(printf,1,2)));
/** /**
Print summary report and return exit status. Print summary report and return exit status.
......
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