#ifdef should be #if
[nobug.git] / test_nobug.c
blob6df38b79ef541afa2840bd0516d7ebc62f9393ff
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, const char* func)
13 if (!depth) return;
15 INVARIANT_ASSERT(self->b != 7);
17 if (self->bar)
18 foo_invariant (self->bar, depth-1, file, line, func);
21 void nobug_foo_dump (const struct foo* self, const int depth, const char* file, const int line, const char* func)
23 if (self && depth)
25 DUMP_LOG("dump b is %d", self->b);
27 nobug_foo_dump (self->bar, depth-1, file, line, func);
31 NOBUG_DEFINE_FLAG(all);
32 NOBUG_DEFINE_FLAG_PARENT(test, all);
34 int main(int argc, char* argv[])
36 int c = 0;
38 NOBUG_INIT_FLAG(test);
40 TRACE(test);
43 if (argc > 1)
44 c = atoi(argv[1]);
46 fprintf (stderr, "testing %d\n", c);
48 UNCHECKED;
50 REQUIRE(c != 1);
51 REQUIRE(c != 2, "require %d failed", c);
53 ENSURE(c != 3);
54 ENSURE(c != 4, "ensure %d failed", c);
56 ASSERT(c != 5, "assert5");
57 ASSERT(c != 6, "assert", "assert %d failed", c);
59 struct foo f;
61 f.b = c;
62 f.bar = NULL;
64 INVARIANT(foo, &f, 2);
66 ERROR(test, "logging");
67 ERROR(test, "logging %d", c);
69 WARN_IF(c==8, test, "logging = 8");
70 TRACE_IF(c==9, test, "logging if %d=9", c);
72 DUMP(test, foo, &f, 2);
73 DUMP_IF(c==10, test, foo, &f, 2);
75 if (c==11)
76 UNIMPLEMENTED("this is unimplemented");
78 if (c==12)
79 PLANNED("this is planned");
81 if (c==13)
82 FIXME("here is a bug");
84 if (c==14)
85 TODO("something todo");
87 if (c==15)
89 BACKTRACE;
92 return 0;