rewrite: update default dumb and smart prefixes
[elinks/elinks-j605.git] / src / util / test.h
blobcdb1b403b29381cedd64ea9bc792993c00e2db6c
1 /* Test library */
3 #ifndef EL__UTIL_TEST_H
4 #define EL__UTIL_TEST_H
6 #include <stdlib.h>
8 static inline void
9 #if (__GNUC__ == 2 && __GNUC_MINOR__ >= 5) || __GNUC__ > 2
10 __attribute__((noreturn))
11 #endif
12 die(const char *msg, ...)
14 va_list args;
16 if (msg) {
17 va_start(args, msg);
18 vfprintf(stderr, msg, args);
19 fputs("\n", stderr);
20 va_end(args);
23 exit(EXIT_FAILURE);
26 static inline int
27 get_test_opt(char **argref, const char *name, int *argi, int argc, char *argv[],
28 const char *expect_msg)
30 char *arg = *argref;
31 int namelen = strlen(name);
33 if (strncmp(arg, name, namelen))
34 return 0;
36 arg += namelen;
37 if (*arg == '=') {
38 (*argref) = arg + 1;
40 } else if (!*arg) {
41 (*argi)++;
42 if ((*argi) >= argc)
43 die("--%s expects %s", name, expect_msg);
44 (*argref) = argv[(*argi)];
46 } else {
47 return 0;
50 return 1;
53 #endif