diff options
author | David Malcolm <dmalcolm@redhat.com> | 2016-06-13 21:04:07 +0000 |
---|---|---|
committer | David Malcolm <dmalcolm@gcc.gnu.org> | 2016-06-13 21:04:07 +0000 |
commit | 09765e3a0a8be2f7bca694a1171ecf050f5400d1 (patch) | |
tree | a7dc6a7feb0754dac0ba89c788d492dc8864951a /gcc/selftest.c | |
parent | 0dda258b6f3194849dc9a47aa9417d7ce942a3ec (diff) | |
download | gcc-09765e3a0a8be2f7bca694a1171ecf050f5400d1.zip gcc-09765e3a0a8be2f7bca694a1171ecf050f5400d1.tar.gz gcc-09765e3a0a8be2f7bca694a1171ecf050f5400d1.tar.bz2 |
selftests: improve reported failure locations
This patch introduce a selftest::location struct to wrap up __FILE__
and __LINE__ information (and __FUNCTION__) throughout the selftests,
allowing location information to be passed around.
It updates the helper functions in pretty-print.c to pass through
the precise location of each test, so that if a failure occurs, the
correct line number is printed, rather than a line within a helper
function.
gcc/ChangeLog:
* input.c (test_reading_source_line): Use SELFTEST_LOCATION.
* pretty-print.c (assert_pp_format_va): Add location param and use
it with ASSERT_STREQ_AT.
(assert_pp_format): Add location param and pass it to
assert_pp_format_va.
(assert_pp_format_colored): Likewise.
(ASSERT_PP_FORMAT_1): New.
(ASSERT_PP_FORMAT_2): New.
(ASSERT_PP_FORMAT_3): New.
(test_pp_format): Provide SELFTEST_LOCATION throughout, either
explicitly, or implicitly via the above macros.
* selftest.c (selftest::pass): Use a selftest::location rather
than file and line.
(selftest::fail): Likewise. Print the function name.
(selftest::fail_formatted): Likewise.
(selftest::assert_streq): Use a selftest::location rather than
file and line.
* selftest.h (selftest::location): New struct.
(SELFTEST_LOCATION): New macro.
(selftest::pass): Accept a const location & rather than file
and line.
(selftest::fail): Likewise.
(selftest::fail_formatted): Likewise.
(selftest::assert_streq): Likewise.
(ASSERT_TRUE): Update for above changes, using SELFTEST_LOCATION.
(ASSERT_FALSE): Likewise.
(ASSERT_EQ): Likewise.
(ASSERT_NE): Likewise.
(ASSERT_STREQ): Likewise.
(ASSERT_PRED1): Likewise.
(ASSERT_STREQ_AT): New macro.
From-SVN: r237410
Diffstat (limited to 'gcc/selftest.c')
-rw-r--r-- | gcc/selftest.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/gcc/selftest.c b/gcc/selftest.c index e5332db..ed6e517 100644 --- a/gcc/selftest.c +++ b/gcc/selftest.c @@ -29,7 +29,7 @@ int selftest::num_passes; /* Record the successful outcome of some aspect of a test. */ void -selftest::pass (const char */*file*/, int /*line*/, const char */*msg*/) +selftest::pass (const location &/*loc*/, const char */*msg*/) { num_passes++; } @@ -37,22 +37,22 @@ selftest::pass (const char */*file*/, int /*line*/, const char */*msg*/) /* Report the failed outcome of some aspect of a test and abort. */ void -selftest::fail (const char *file, int line, const char *msg) +selftest::fail (const location &loc, const char *msg) { - fprintf (stderr,"%s:%i: FAIL: %s\n", file, line, msg); - /* TODO: add calling function name as well? */ + fprintf (stderr,"%s:%i: %s: FAIL: %s\n", loc.m_file, loc.m_line, + loc.m_function, msg); abort (); } /* As "fail", but using printf-style formatted output. */ void -selftest::fail_formatted (const char *file, int line, const char *fmt, ...) +selftest::fail_formatted (const location &loc, const char *fmt, ...) { va_list ap; - fprintf (stderr, "%s:%i: FAIL: ", file, line); - /* TODO: add calling function name as well? */ + fprintf (stderr, "%s:%i: %s: FAIL: ", loc.m_file, loc.m_line, + loc.m_function); va_start (ap, fmt); vfprintf (stderr, fmt, ap); va_end (ap); @@ -63,15 +63,15 @@ selftest::fail_formatted (const char *file, int line, const char *fmt, ...) /* Implementation detail of ASSERT_STREQ. */ void -selftest::assert_streq (const char *file, int line, +selftest::assert_streq (const location &loc, 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"); + ::selftest::pass (loc, "ASSERT_STREQ"); else ::selftest::fail_formatted - (file, line, "ASSERT_STREQ (%s, %s) expected=\"%s\" actual=\"%s\"", + (loc, "ASSERT_STREQ (%s, %s) expected=\"%s\" actual=\"%s\"", desc_expected, desc_actual, val_expected, val_actual); } |