removed NOBUG_NAMESPACE in favor of new flag based logging
[nobug.git] / test_nobug.c
blob9d8f30558b0a4a7f0862fe564b33b1003ed039db
1 #include <stdlib.h>
3 #include "nobug.h"
6 struct foo
8 char b;
9 struct foo* bar;
12 void foo_invariant (struct foo* self, int depth, const char* file, int line)
14 if (!depth) return;
16 INVARIANT_ASSERT(self->b != 7);
18 if (self->bar)
19 foo_invariant (self->bar, depth-1, file, line);
22 void foo_dump (struct foo* self, int depth, const char* file, int line)
24 if (!depth) return;
26 DUMP_LOG("dump b is %d", self->b);
28 if (self->bar)
29 foo_dump (self->bar, depth-1, file, line);
32 NOBUG_DEFINE_FLAG(test);
34 int main(int argc, char* argv[])
36 int c = 0;
38 NOBUG_INIT_FLAG(test);
40 if (argc > 1)
41 c = atoi(argv[1]);
43 fprintf (stderr, "testing %d\n", c);
45 UNCHECKED;
47 REQUIRE(c != 1);
48 REQUIRE(c != 2, "require %d failed", c);
50 ENSURE(c != 3);
51 ENSURE(c != 4, "ensure %d failed", c);
53 ASSERT(c != 5, "assert5");
54 ASSERT(c != 6, "assert", "assert %d failed", c);
56 struct foo f;
58 f.b = c;
59 f.bar = NULL;
61 INVARIANT(foo, &f, 2);
63 ERROR(test, "logging");
64 ERROR(test, "logging %d", c);
66 WARNIF(c==8, test, "logging = 8");
67 TRACEIF(c==9, test, "logging if %d=9", c);
69 DUMP(foo, &f, 2);
70 DUMPIF(c==10, foo, &f, 2);
72 if (c==11)
73 UNIMPLEMENTED("this is unimplemented");
75 if (c==12)
76 PLANNED("this is planned");
78 if (c==13)
79 BUG("here is a bug");
81 if (c==14)
82 TODO("something todo");
84 if (c==15)
86 BACKTRACE;
89 return 0;