Commit | Line | Data |
---|---|---|
aa968dde YB |
1 | /*- |
2 | * Copyright (c) 2004 Nik Clayton | |
01c5442b | 3 | * 2017 Jérémie Galarneau |
aa968dde YB |
4 | * All rights reserved. |
5 | * | |
6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions | |
8 | * are met: | |
9 | * 1. Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | |
11 | * 2. Redistributions in binary form must reproduce the above copyright | |
12 | * notice, this list of conditions and the following disclaimer in the | |
13 | * documentation and/or other materials provided with the distribution. | |
14 | * | |
15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | |
16 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | |
19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
21 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
25 | * SUCH DAMAGE. | |
26 | */ | |
27 | ||
28 | /* '## __VA_ARGS__' is a gcc'ism. C99 doesn't allow the token pasting | |
29 | and requires the caller to add the final comma if they've ommitted | |
30 | the optional arguments */ | |
31 | #ifdef __GNUC__ | |
32 | # define ok(e, test, ...) ((e) ? \ | |
33 | _gen_result(1, __func__, __FILE__, __LINE__, \ | |
34 | test, ## __VA_ARGS__) : \ | |
35 | _gen_result(0, __func__, __FILE__, __LINE__, \ | |
36 | test, ## __VA_ARGS__)) | |
37 | ||
38 | # define ok1(e) ((e) ? \ | |
39 | _gen_result(1, __func__, __FILE__, __LINE__, "%s", #e) : \ | |
40 | _gen_result(0, __func__, __FILE__, __LINE__, "%s", #e)) | |
41 | ||
42 | # define pass(test, ...) ok(1, test, ## __VA_ARGS__); | |
43 | # define fail(test, ...) ok(0, test, ## __VA_ARGS__); | |
44 | ||
45 | # define skip_start(test, n, fmt, ...) \ | |
46 | do { \ | |
47 | if((test)) { \ | |
48 | skip(n, fmt, ## __VA_ARGS__); \ | |
49 | continue; \ | |
50 | } | |
51 | #elif __STDC_VERSION__ >= 199901L /* __GNUC__ */ | |
52 | # define ok(e, ...) ((e) ? \ | |
53 | _gen_result(1, __func__, __FILE__, __LINE__, \ | |
54 | __VA_ARGS__) : \ | |
55 | _gen_result(0, __func__, __FILE__, __LINE__, \ | |
56 | __VA_ARGS__)) | |
57 | ||
58 | # define ok1(e) ((e) ? \ | |
59 | _gen_result(1, __func__, __FILE__, __LINE__, "%s", #e) : \ | |
60 | _gen_result(0, __func__, __FILE__, __LINE__, "%s", #e)) | |
61 | ||
62 | # define pass(...) ok(1, __VA_ARGS__); | |
63 | # define fail(...) ok(0, __VA_ARGS__); | |
64 | ||
65 | # define skip_start(test, n, ...) \ | |
66 | do { \ | |
67 | if((test)) { \ | |
68 | skip(n, __VA_ARGS__); \ | |
69 | continue; \ | |
70 | } | |
71 | #else /* __STDC_VERSION__ */ | |
72 | # error "Needs gcc or C99 compiler for variadic macros." | |
73 | #endif /* __STDC_VERSION__ */ | |
74 | ||
75 | #define skip_end() } while(0); | |
76 | ||
830153f4 SM |
77 | #ifdef __MINGW_PRINTF_FORMAT |
78 | # define PRINT_FORMAT __MINGW_PRINTF_FORMAT | |
79 | #else | |
80 | # define PRINT_FORMAT printf | |
81 | #endif | |
82 | ||
83 | __attribute__((format(PRINT_FORMAT, 5, 6))) | |
5eddd0b3 | 84 | unsigned int _gen_result(int, const char *, const char *, unsigned int, const char *, ...); |
aa968dde YB |
85 | |
86 | int plan_no_plan(void); | |
5eddd0b3 | 87 | int plan_skip_all(const char *); |
aa968dde YB |
88 | int plan_tests(unsigned int); |
89 | ||
830153f4 | 90 | __attribute__((format(PRINT_FORMAT, 1, 2))) |
5eddd0b3 | 91 | unsigned int diag(const char *, ...); |
01c5442b | 92 | void diag_multiline(const char *); |
aa968dde | 93 | |
830153f4 | 94 | __attribute__((format(PRINT_FORMAT, 2, 3))) |
5eddd0b3 | 95 | int skip(unsigned int, const char *, ...); |
aa968dde | 96 | |
830153f4 | 97 | __attribute__((format(PRINT_FORMAT, 1, 2))) |
5eddd0b3 | 98 | void todo_start(const char *, ...); |
aa968dde YB |
99 | void todo_end(void); |
100 | ||
101 | int exit_status(void); |