mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-10-04 20:59:21 +02:00
gtestutils: Add a new g_assert_no_errno() test macro
This is for use in testing POSIX-style functions like `rmdir()`, which return an integer < 0 on failure, and return their error information in `errno`. The new macro prints `errno` and `g_strerror (errno)` on failure. Includes a unit test. Signed-off-by: Philip Withnall <withnall@endlessm.com>
This commit is contained in:
@@ -27,6 +27,7 @@
|
||||
#include <glib/gstring.h>
|
||||
#include <glib/gerror.h>
|
||||
#include <glib/gslist.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
@@ -110,6 +111,20 @@ typedef void (*GTestFixtureFunc) (gpointer fixture,
|
||||
} \
|
||||
} \
|
||||
G_STMT_END
|
||||
#define g_assert_no_errno(expr) G_STMT_START { \
|
||||
int __ret, __errsv; \
|
||||
errno = 0; \
|
||||
__ret = expr; \
|
||||
__errsv = errno; \
|
||||
if (__ret < 0) \
|
||||
{ \
|
||||
gchar *__msg; \
|
||||
__msg = g_strdup_printf ("assertion failed (" #expr " >= 0): errno %i: %s", __errsv, g_strerror (__errsv)); \
|
||||
g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, __msg); \
|
||||
g_free (__msg); \
|
||||
} \
|
||||
} G_STMT_END \
|
||||
GLIB_AVAILABLE_MACRO_IN_2_66
|
||||
#define g_assert_no_error(err) G_STMT_START { \
|
||||
if (err) \
|
||||
g_assertion_message_error (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
|
||||
|
Reference in New Issue
Block a user