+2016-06-13 David Malcolm <dmalcolm@redhat.com>
+
+ * selftest.c (selftest::fail_formatted): New function.
+ (selftest::assert_streq): New function.
+ * selftest.h (selftests::fail_formatted): New decl.
+ (selftest::assert_streq): New decl.
+ (ASSERT_STREQ): Reimplement in terms of selftest::assert_streq.
+
2016-06-13 Jeff Law <law@redhat.com>
PR tree-optimization/71403
abort ();
}
+/* As "fail", but using printf-style formatted output. */
+
+void
+selftest::fail_formatted (const char *file, int line, const char *fmt, ...)
+{
+ va_list ap;
+
+ fprintf (stderr, "%s:%i: FAIL: ", file, line);
+ /* TODO: add calling function name as well? */
+ va_start (ap, fmt);
+ vfprintf (stderr, fmt, ap);
+ va_end (ap);
+ fprintf (stderr, "\n");
+ abort ();
+}
+
+/* Implementation detail of ASSERT_STREQ. */
+
+void
+selftest::assert_streq (const char *file, int line,
+ const char *desc_expected, const char *desc_actual,
+ const char *val_expected, const char *val_actual)
+{
+ if (0 == strcmp (val_expected, val_actual))
+ ::selftest::pass (file, line, "ASSERT_STREQ");
+ else
+ ::selftest::fail_formatted
+ (file, line, "ASSERT_STREQ (%s, %s) expected=\"%s\" actual=\"%s\"",
+ desc_expected, desc_actual, val_expected, val_actual);
+}
+
+
#endif /* #if CHECKING_P */
extern void fail (const char *file, int line, const char *msg);
+/* As "fail", but using printf-style formatted output. */
+
+extern void fail_formatted (const char *file, int line, const char *fmt, ...)
+ ATTRIBUTE_PRINTF_3;
+
+/* Implementation detail of ASSERT_STREQ. */
+
+extern void assert_streq (const char *file, int line,
+ const char *desc_expected, const char *desc_actual,
+ const char *val_expected, const char *val_actual);
+
/* Declarations for specific families of tests (by source file), in
alphabetical order. */
extern void bitmap_c_tests ();
::selftest::pass if they are equal,
::selftest::fail if they are non-equal. */
-#define ASSERT_STREQ(EXPECTED, ACTUAL) \
- SELFTEST_BEGIN_STMT \
- const char *desc = "ASSERT_STREQ (" #EXPECTED ", " #ACTUAL ")"; \
- const char *expected_ = (EXPECTED); \
- const char *actual_ = (ACTUAL); \
- if (0 == strcmp (expected_, actual_)) \
- ::selftest::pass (__FILE__, __LINE__, desc); \
- else \
- ::selftest::fail (__FILE__, __LINE__, desc); \
+#define ASSERT_STREQ(EXPECTED, ACTUAL) \
+ SELFTEST_BEGIN_STMT \
+ ::selftest::assert_streq (__FILE__, __LINE__, #EXPECTED, #ACTUAL, \
+ (EXPECTED), (ACTUAL)); \
SELFTEST_END_STMT
/* Evaluate PRED1 (VAL1), calling ::selftest::pass if it is true,