selftest: show values when ASSERT_STREQ fails
Rework ASSERT_STREQ so that it prints the actual and expected values to stderr when it fails (by moving it to a helper function). gcc/ChangeLog: * 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. From-SVN: r237404
This commit is contained in:
parent
a73786e39f
commit
755fa6662d
|
@ -1,3 +1,11 @@
|
|||
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
|
||||
|
|
|
@ -44,4 +44,36 @@ selftest::fail (const char *file, int line, const char *msg)
|
|||
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 */
|
||||
|
|
|
@ -39,6 +39,17 @@ extern void pass (const char *file, int line, const char *msg);
|
|||
|
||||
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 ();
|
||||
|
@ -123,15 +134,10 @@ extern int num_passes;
|
|||
::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,
|
||||
|
|
Loading…
Reference in New Issue