take: add labels when CCAN_TAKE_DEBUG set, return in taken_any().
[ccan] / ccan / take / test / run-debug.c
1 #include <stdlib.h>
2 #include <stdbool.h>
3
4 #define CCAN_TAKE_DEBUG 1
5 #include <ccan/take/take.h>
6 #include <ccan/take/take.c>
7 #include <ccan/tap/tap.h>
8
9 int main(void)
10 {
11         const char *p = "hi";
12
13         plan_tests(14);
14
15         /* We can take NULL. */
16         ok1(take(NULL) == NULL);
17         ok1(is_taken(NULL));
18         ok1(strstr(taken_any(), "run-debug.c:16:"));
19         ok1(taken(NULL)); /* Undoes take() */
20         ok1(!is_taken(NULL));
21         ok1(!taken(NULL));
22         ok1(!taken_any());
23
24         /* We can take a real pointer. */
25         ok1(take(p) == p);
26         ok1(is_taken(p));
27         ok1(strends(taken_any(), "run-debug.c:25:p"));
28         ok1(taken(p)); /* Undoes take() */
29         ok1(!is_taken(p));
30         ok1(!taken(p));
31         ok1(!taken_any());
32
33         return exit_status();
34 }