Add an assert for UTEST that takes a format string
authorBarret Rhoden <brho@cs.berkeley.edu>
Wed, 25 Nov 2015 22:39:07 +0000 (17:39 -0500)
committerBarret Rhoden <brho@cs.berkeley.edu>
Mon, 30 Nov 2015 21:07:36 +0000 (16:07 -0500)
UT_ASSERT_M() just prints the message verbatim.  Its va_args are cleanup
routines.  UT_ASSERT_FMT() takes a format string, and its va_args is the
values for the format string.

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
user/utest/include/utest.h

index 646e492..ceddcb6 100644 (file)
@@ -32,6 +32,19 @@ __BEGIN_DECLS
                }                                                                        \
        } while (0)
 
+
+/* If 'test' fails, Sets an assert message, which can be a format string, and
+ * returns false. */
+#define UT_ASSERT_FMT(message, test, ...)                                      \
+       do {                                                                       \
+               if (!(test)) {                                                         \
+                       char fmt[] = "Assertion failure in %s() at %s:%d: " #message;      \
+                       sprintf(utest_msg, fmt, __func__, __FILE__, __LINE__,              \
+                               ##__VA_ARGS__);                                            \
+                       return false;                                                      \
+               }                                                                      \
+       } while (0)
+
 /*
  * Structs and macros for registering test cases.
  */