diff --git a/src/dom/test/dom-select.c b/src/dom/test/dom-select.c index e4cc6f238..1da1cbfe8 100644 --- a/src/dom/test/dom-select.c +++ b/src/dom/test/dom-select.c @@ -15,21 +15,7 @@ #include "dom/select.h" #include "dom/sgml/parser.h" #include "dom/stack.h" - - -void die(const char *msg, ...) -{ - va_list args; - - if (msg) { - va_start(args, msg); - vfprintf(stderr, msg, args); - fputs("\n", stderr); - va_end(args); - } - - exit(!!NULL); -} +#include "util/test.h" int main(int argc, char *argv[]) diff --git a/src/dom/test/sgml-parser.c b/src/dom/test/sgml-parser.c index 5446ccd7a..3eca7f1b3 100644 --- a/src/dom/test/sgml-parser.c +++ b/src/dom/test/sgml-parser.c @@ -16,6 +16,7 @@ #include "dom/sgml/dump.h" #include "dom/sgml/parser.h" #include "dom/stack.h" +#include "util/test.h" unsigned int number_of_lines = 0; @@ -242,21 +243,6 @@ sgml_error_function(struct sgml_parser *parser, struct dom_string *string, return DOM_CODE_OK; } -static void -die(const char *msg, ...) -{ - va_list args; - - if (msg) { - va_start(args, msg); - vfprintf(stderr, msg, args); - fputs("\n", stderr); - va_end(args); - } - - exit(!!NULL); -} - static int get_opt(char **argref, const char *name, int *argi, int argc, char *argv[], const char *expect_msg) diff --git a/src/mime/backend/mailcap.c b/src/mime/backend/mailcap.c index 1ca637a61..e7b14d611 100644 --- a/src/mime/backend/mailcap.c +++ b/src/mime/backend/mailcap.c @@ -678,6 +678,9 @@ struct module mailcap_mime_module = struct_module( ); #ifdef TEST_MAILCAP + +#include "util/test.h" + /* Some ugly shortcuts for getting defined symbols to work. */ int default_mime_backend, install_signal_handler, @@ -685,20 +688,6 @@ int default_mime_backend, program; LIST_OF(struct terminal) terminals; -void die(const char *msg, ...) -{ - va_list args; - - if (msg) { - va_start(args, msg); - vfprintf(stderr, msg, args); - fputs("\n", stderr); - va_end(args); - } - - exit(1); -} - int main(int argc, char *argv[]) { diff --git a/src/protocol/ftp/ftp-parser.c b/src/protocol/ftp/ftp-parser.c index 197466a59..dbdb677b7 100644 --- a/src/protocol/ftp/ftp-parser.c +++ b/src/protocol/ftp/ftp-parser.c @@ -13,21 +13,7 @@ #include "osdep/stat.h" #include "protocol/ftp/parse.h" - - -void die(const char *msg, ...) -{ - va_list args; - - if (msg) { - va_start(args, msg); - vfprintf(stderr, msg, args); - fputs("\n", stderr); - va_end(args); - } - - exit(!!NULL); -} +#include "util/test.h" int main(int argc, char *argv[]) diff --git a/src/protocol/test/stub.c b/src/protocol/test/stub.c index 4ed9b6724..8b66e34a1 100644 --- a/src/protocol/test/stub.c +++ b/src/protocol/test/stub.c @@ -13,6 +13,7 @@ #include "main/module.h" #include "protocol/user.h" #include "session/session.h" +#include "util/test.h" #define STUB_MODULE(name) \ struct module name = struct_module( \ @@ -38,21 +39,6 @@ STUB_MODULE(smb_protocol_module); STUB_MODULE(uri_rewrite_module); STUB_MODULE(user_protocol_module); -static void -die(const char *msg, ...) -{ - va_list args; - - if (msg) { - va_start(args, msg); - vfprintf(stderr, msg, args); - fputs("\n", stderr); - va_end(args); - } - - exit(!!NULL); -} - static void stub_called(const unsigned char *fun) { diff --git a/src/util/test.h b/src/util/test.h new file mode 100644 index 000000000..bef09c963 --- /dev/null +++ b/src/util/test.h @@ -0,0 +1,23 @@ +/* Test library */ + +#ifndef EL__UTIL_TEST_H +#define EL__UTIL_TEST_H + +#include + +static inline void +die(const char *msg, ...) +{ + va_list args; + + if (msg) { + va_start(args, msg); + vfprintf(stderr, msg, args); + fputs("\n", stderr); + va_end(args); + } + + exit(EXIT_FAILURE); +} + +#endif