[network-manager-openvpn/th/ovpn-import-bgo761285: 3/13] tests: improve FAIL() macro



commit f163553de86bd58484535a8aa787a3d9efb02305
Author: Thomas Haller <thaller redhat com>
Date:   Thu Jan 28 22:34:37 2016 +0100

    tests: improve FAIL() macro
    
    exit(1) doesn't even break in debugger...

 shared/nm-test-utils.h |   27 +++++++++------------------
 1 files changed, 9 insertions(+), 18 deletions(-)
---
diff --git a/shared/nm-test-utils.h b/shared/nm-test-utils.h
index 840e25f..c91fa96 100644
--- a/shared/nm-test-utils.h
+++ b/shared/nm-test-utils.h
@@ -26,26 +26,17 @@
 #include <unistd.h>
 #include <stdarg.h>
 
-static void
-FAIL(const char *test_name, const char *fmt, ...)
-{
-       va_list args;
-       char buf[500];
-
-       snprintf (buf, 500, "FAIL: (%s) %s\n", test_name, fmt);
-
-       va_start (args, fmt);
-       vfprintf (stderr, buf, args);
-       va_end (args);
-       _exit (1);
-}
+#define FAIL(test_name, fmt, ...) \
+    G_STMT_START { \
+        g_error ("%s:%d: FAIL[%s]: " fmt, __FILE__, __LINE__, test_name, ## __VA_ARGS__); \
+    } G_STMT_END
 
 #define ASSERT(x, test_name, fmt, ...) \
-{ \
-       if (!(x)) { \
-               FAIL (test_name, fmt, ## __VA_ARGS__); \
-       } \
-}
+    G_STMT_START { \
+        if (!(x)) { \
+            FAIL (test_name, fmt, ## __VA_ARGS__); \
+        } \
+    } G_STMT_END
 
 #endif /* NM_TEST_HELPERS_H */
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]