]> git.ozlabs.org Git - ccan/blob - ccan_tools/libtap/src/tap.h
Fix talloc's use of PRINTF_ATTRIBUTE clash.
[ccan] / ccan_tools / libtap / src / tap.h
1 /*-
2  * Copyright (c) 2004 Nik Clayton
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  */
26
27 #if (!defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L) && !defined(__GNUC__)
28 # error "Needs gcc or C99 compiler for variadic macros."
29 #else
30
31 # define ok(e, ...) ((e) ?                                              \
32                      _gen_result(1, __func__, __FILE__, __LINE__,       \
33                                  __VA_ARGS__) :                         \
34                      _gen_result(0, __func__, __FILE__, __LINE__,       \
35                                  __VA_ARGS__))
36
37 # define ok1(e) ((e) ?                                                  \
38                  _gen_result(1, __func__, __FILE__, __LINE__, "%s", #e) : \
39                  _gen_result(0, __func__, __FILE__, __LINE__, "%s", #e))
40
41 # define pass(...) ok(1, __VA_ARGS__)
42 # define fail(...) ok(0, __VA_ARGS__)
43
44 # define skip_if(cond, n, ...)                          \
45         if (cond) skip((n), __VA_ARGS__);               \
46         else
47
48 # define skip_start(test, n, ...)                       \
49         do {                                            \
50                 if((test)) {                            \
51                         skip(n,  __VA_ARGS__);          \
52                         continue;                       \
53                 }
54
55 # define skip_end } while(0)
56
57 #ifndef PRINTF_ATTRIBUTE
58 #ifdef __GNUC__
59 #define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (__printf__, a1, a2)))
60 #else
61 #define PRINTF_ATTRIBUTE(a1, a2)
62 #endif
63 #endif
64
65 unsigned int _gen_result(int, const char *, char *, unsigned int, char *, ...)
66         PRINTF_ATTRIBUTE(5, 6);
67
68 void plan_no_plan(void);
69 void plan_skip_all(char *);
70 void plan_tests(unsigned int);
71
72 void diag(char *, ...) PRINTF_ATTRIBUTE(1, 2);
73
74 void skip(unsigned int, char *, ...) PRINTF_ATTRIBUTE(2, 3);
75
76 void todo_start(char *, ...) PRINTF_ATTRIBUTE(1, 2);
77 void todo_end(void);
78
79 int exit_status(void);
80 #endif /* C99 or gcc */