diff options
Diffstat (limited to 'common/test.c')
-rw-r--r-- | common/test.c | 121 |
1 files changed, 106 insertions, 15 deletions
diff --git a/common/test.c b/common/test.c index e917701..18cb501 100644 --- a/common/test.c +++ b/common/test.c @@ -89,6 +89,34 @@ struct { jmp_buf jump; } gl = { NULL, NULL, 0, }; +static void +print_diagnostics (const char *filename, + int line, + const char *function, + char *output) +{ + const char *pos; + char *from; + char *next; + + for (from = output; from != NULL; ) { + next = strchr (from, '\n'); + if (next) { + next[0] = '\0'; + next += 1; + } + + printf ("# %s\n", from); + from = next; + } + + pos = strrchr (filename, '/'); + if (pos != NULL && pos[1] != '\0') + filename = pos + 1; + + printf ("# in %s() at %s:%d\n", function, filename, line); +} + void p11_test_fail (const char *filename, int line, @@ -96,10 +124,7 @@ p11_test_fail (const char *filename, const char *message, ...) { - const char *pos; char *output; - char *from; - char *next; va_list va; assert (gl.last != NULL); @@ -113,23 +138,89 @@ p11_test_fail (const char *filename, assert (0 && "vasprintf() failed"); va_end (va); - for (from = output; from != NULL; ) { - next = strchr (from, '\n'); - if (next) { - next[0] = '\0'; - next += 1; - } + print_diagnostics (filename, line, function, output); + free (output); - printf ("# %s\n", from); - from = next; + /* Let coverity know we're not supposed to return from here */ +#ifdef __COVERITY__ + abort(); +#endif + + longjmp (gl.jump, 1); +} + +void +p11_test_skip (const char *filename, + int line, + const char *function, + const char *message, + ...) +{ + char *output; + char *pos; + va_list va; + + assert (gl.last != NULL); + assert (gl.last->type == TEST); + gl.last->x.test.failed = 1; + + printf ("ok %d %s", gl.number, gl.last->x.test.name); + + va_start (va, message); + if (vasprintf (&output, message, va) < 0) + assert (0 && "vasprintf() failed"); + va_end (va); + + pos = strchr (output, '\n'); + if (pos) { + *pos = '\0'; + pos++; } + printf (" # SKIP %s\n", output); - pos = strrchr (filename, '/'); - if (pos != NULL && pos[1] != '\0') - filename = pos + 1; + if (pos) + print_diagnostics (filename, line, function, pos); + free (output); - printf ("# in %s() at %s:%d\n", function, filename, line); + /* Let coverity know we're not supposed to return from here */ +#ifdef __COVERITY__ + abort(); +#endif + + longjmp (gl.jump, 1); +} + +void +p11_test_todo (const char *filename, + int line, + const char *function, + const char *message, + ...) +{ + char *output; + char *pos; + va_list va; + + assert (gl.last != NULL); + assert (gl.last->type == TEST); + gl.last->x.test.failed = 1; + + printf ("not ok %d %s", gl.number, gl.last->x.test.name); + + va_start (va, message); + if (vasprintf (&output, message, va) < 0) + assert (0 && "vasprintf() failed"); + va_end (va); + + pos = strchr (output, '\n'); + if (pos) { + *pos = '\0'; + pos++; + } + printf (" # TODO %s\n", output); + if (pos) + print_diagnostics (filename, line, function, pos); free (output); /* Let coverity know we're not supposed to return from here */ |