tweaks from feedback - thanks
[ccan] / ccan / xstring / test / run2.c
1 #include <ccan/failtest/failtest_override.h>
2 #include <ccan/failtest/failtest.h>
3 #include <ccan/xstring/xstring.h>
4 /* Include the C files directly. */
5 #include <ccan/xstring/xstring.c>
6 #include <ccan/tap/tap.h>
7
8 unsigned last_fail_line;
9
10 static enum failtest_result once_only(struct tlist_calls *history)
11 {
12         const struct failtest_call *tail = tlist_tail(history, list);
13
14         if (tail->line == last_fail_line)
15                 return FAIL_DONT_FAIL;
16
17         last_fail_line = tail->line;
18         return FAIL_OK;
19 }
20
21 int main(int argc, char *argv[])
22 {
23         failtest_init(argc, argv);
24         failtest_hook = once_only;
25         plan_tests(3);
26
27         xstring *x;
28
29         ok1((x = xstrNew(100)) != NULL); // fail first malloc
30         if (x) xstrFree(x);
31
32         ok1((x = xstrNew(100)) != NULL); // fail second malloc
33         if (x) xstrFree(x);
34
35         ok1((x = xstrNew(0)) == NULL && errno == EINVAL);
36
37         failtest_exit(exit_status());
38 }