merged limit and flag checking
[nobug.git] / test_nobug.c
blobdff88387d17e4bd91e15d053941b382cbfef5adb
1 #include <stdlib.h>
3 #include "nobug.h"
5 struct foo
7 char b;
8 struct foo* bar;
9 };
11 void foo_invariant (struct foo* self, int depth, const char* file, int line)
13 if (!depth) return;
15 INVARIANT_ASSERT(self->b != 7);
17 if (self->bar)
18 foo_invariant (self->bar, depth-1, file, line);
21 void foo_dump (struct foo* self, int depth, const char* file, int line)
23 if (!depth) return;
25 DUMP_LOG("dump b is %d", self->b);
27 if (self->bar)
28 foo_dump (self->bar, depth-1, file, line);
31 NOBUG_DEFINE_FLAG(test);
33 int main(int argc, char* argv[])
35 int c = 0;
37 NOBUG_INIT_FLAG(test);
39 if (argc > 1)
40 c = atoi(argv[1]);
42 fprintf (stderr, "testing %d\n", c);
44 UNCHECKED;
46 REQUIRE(c != 1);
47 REQUIRE(c != 2, "require %d failed", c);
49 ENSURE(c != 3);
50 ENSURE(c != 4, "ensure %d failed", c);
52 ASSERT(c != 5, "assert5");
53 ASSERT(c != 6, "assert", "assert %d failed", c);
55 struct foo f;
57 f.b = c;
58 f.bar = NULL;
60 INVARIANT(foo, &f, 2);
62 ERROR(test, "logging");
63 ERROR(test, "logging %d", c);
65 WARN_IF(c==8, test, "logging = 8");
66 TRACE_IF(c==9, test, "logging if %d=9", c);
68 DUMP(foo, &f, 2);
69 DUMP_IF(c==10, foo, &f, 2);
71 if (c==11)
72 UNIMPLEMENTED("this is unimplemented");
74 if (c==12)
75 PLANNED("this is planned");
77 if (c==13)
78 BUG("here is a bug");
80 if (c==14)
81 TODO("something todo");
83 if (c==15)
85 BACKTRACE;
88 return 0;