diff options
author | John Hawthorn <john.hawthorn@gmail.com> | 2014-09-27 14:55:00 -0700 |
---|---|---|
committer | John Hawthorn <john.hawthorn@gmail.com> | 2014-09-27 16:50:08 -0700 |
commit | 78bf67c0d30cbd121a34c9fee5def678f0c027e7 (patch) | |
tree | 9ad2a18d1dc7f0a7f39ca93372fed33839962adc /fzytest.c | |
parent | 0b6104d6ddd3f7b859c15cdab5f7a512708e84ee (diff) |
Raise SIGTRAP on all assertion failures
Makes it easy to run tests w/ gdb for debugging
Diffstat (limited to 'fzytest.c')
-rw-r--r-- | fzytest.c | 11 |
1 files changed, 10 insertions, 1 deletions
@@ -1,12 +1,13 @@ #include <stdio.h> #include <string.h> +#include <signal.h> #include "match.h" #include "choices.h" int testsrun = 0, testsfailed = 0, assertionsrun = 0; -#define assert(x) if(++assertionsrun && !(x)){fprintf(stderr, "test \"%s\" failed\n assert(%s) was false\n at %s:%i\n\n", __func__, #x, __FILE__ ,__LINE__);testsfailed++;return;} +#define assert(x) if(++assertionsrun && !(x)){fprintf(stderr, "test \"%s\" failed\n assert(%s) was false\n at %s:%i\n\n", __func__, #x, __FILE__ ,__LINE__);raise(SIGTRAP);testsfailed++;return;} #define assert_streq(a, b) assert(!strcmp(a, b)) @@ -216,10 +217,18 @@ void summary(){ printf("%i tests, %i assertions, %i failures\n", testsrun, assertionsrun, testsfailed); } +static void ignore_signal(int signum){ + (void) signum; +} + int main(int argc, char *argv[]){ (void) argc; (void) argv; + /* We raise sigtrap on all assertion failures. + * If we have no debugger running, we should ignore it */ + signal(SIGTRAP, ignore_signal); + runtest(test_match); runtest(test_scoring); runtest(test_positions_1); |