diff options
author | unknown <mats@mysql.com> | 2006-04-06 17:18:12 +0200 |
---|---|---|
committer | unknown <mats@mysql.com> | 2006-04-06 17:18:12 +0200 |
commit | 3f9e35d3f350768a8d237bfd369adf63f565f81c (patch) | |
tree | 921b8b2e75695922185e05e1e19a3d6eee2e5e41 /unittest/mytap/tap.c | |
parent | b0d2b6588be8b5c1854b6e0311fcbd42f97b9c18 (diff) | |
download | mariadb-git-3f9e35d3f350768a8d237bfd369adf63f565f81c.tar.gz |
WL#3206 (Adding unit tests):
Moving mytap library into unittest/
Adding 'test' target to make and run unit tests.
Minor fixes.
unittest/mytap/Doxyfile:
mvdir
unittest/mytap/t/basic.t.c:
mvdir
unittest/mytap/tap.c:
mvdir
unittest/mytap/tap.h:
mvdir
Makefile.am:
Correcting after moving mytap/
configure.in:
Correcting after moving mytap/
unittest/Makefile.am:
Adding 'test' target to build and execute unit tests.
unittest/examples/Makefile.am:
Correcting after moving mytap/
unittest/mysys/Makefile.am:
Correcting after moving mytap/
unittest/mysys/bitmap.t.c:
Adding copyright notice.
unittest/mytap/Makefile.am:
Correcting after moving mytap/
unittest/mytap/t/Makefile.am:
Correcting after moving mytap/
unittest/mysys/base64.t.c:
New BitKeeper file ``unittest/mysys/base64.t.c''
Diffstat (limited to 'unittest/mytap/tap.c')
-rw-r--r-- | unittest/mytap/tap.c | 171 |
1 files changed, 171 insertions, 0 deletions
diff --git a/unittest/mytap/tap.c b/unittest/mytap/tap.c new file mode 100644 index 00000000000..9540c0322d0 --- /dev/null +++ b/unittest/mytap/tap.c @@ -0,0 +1,171 @@ + +#include "tap.h" + +#include <stdlib.h> +#include <stdarg.h> +#include <stdio.h> +#include <string.h> + +/** + Test data structure. + + Data structure containing all information about the test suite. + */ +static TEST_DATA g_test = { 0 }; + +/** + Output stream for test report message. + + The macro is just a temporary solution. + */ +#define tapout stdout + +/** + Emit a TAP result and optionally a description. + + @param pass 'true' if test passed, 'false' otherwise + @param fmt Description of test in printf() format. + @param ap Vararg list for the description string above. + */ +static int +emit_tap(int pass, char const *fmt, va_list ap) +{ + fprintf(tapout, "%sok %d%s", + pass ? "" : "not ", + ++g_test.last, + (fmt && *fmt) ? " - " : ""); + if (fmt && *fmt) + vfprintf(tapout, fmt, ap); +} + + +static int +emit_dir(const char *dir, const char *exp) +{ + fprintf(tapout, " # %s %s", dir, exp); +} + + +static int +emit_endl() +{ + fprintf(tapout, "\n"); +} + +void +diag(char const *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + fprintf(tapout, "# "); + vfprintf(tapout, fmt, ap); + fprintf(tapout, "\n"); + va_end(ap); +} + + +void +plan(int const count) +{ + g_test.plan= count; + switch (count) + { + case NO_PLAN: + case SKIP_ALL: + break; + default: + if (plan > 0) + fprintf(tapout, "1..%d\n", count); + break; + } +} + + +void +skip_all(char const *reason, ...) +{ + va_list ap; + va_start(ap, reason); + fprintf(tapout, "1..0 # skip "); + vfprintf(tapout, reason, ap); + va_end(ap); + exit(0); +} + +void +ok(int const pass, char const *fmt, ...) +{ + if (!pass && *g_test.todo == '\0') + ++g_test.failed; + + va_list ap; + va_start(ap, fmt); + emit_tap(pass, fmt, ap); + va_end(ap); + if (*g_test.todo != '\0') + emit_dir("TODO", g_test.todo); + emit_endl(); +} + + +void +skip(int how_many, char const *fmt, ...) +{ + char reason[80]; + if (fmt && *fmt) + { + va_list ap; + va_start(ap, fmt); + vsnprintf(reason, sizeof(reason), fmt, ap); + va_end(ap); + } + else + reason[0] = '\0'; + + while (how_many-- > 0) + { + va_list ap; + emit_tap(1, NULL, ap); + emit_dir("SKIP", reason); + emit_endl(); + } +} + +void +todo_start(char const *message, ...) +{ + va_list ap; + va_start(ap, message); + vsnprintf(g_test.todo, sizeof(g_test.todo), message, ap); + va_end(ap); +} + +void +todo_end() +{ + *g_test.todo = '\0'; +} + +int exit_status() { + /* + If there were no plan, we write one last instead. + */ + if (g_test.plan == NO_PLAN) + plan(g_test.last); + + if (g_test.plan != g_test.last) + { + diag("%d tests planned but only %d executed", + g_test.plan, g_test.last); + return EXIT_FAILURE; + } + + if (g_test.failed > 0) + { + diag("Failed %d tests!", g_test.failed); + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} + |