aboutsummaryrefslogtreecommitdiff
path: root/gcc/pretty-print.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/pretty-print.c')
-rw-r--r--gcc/pretty-print.c128
1 files changed, 78 insertions, 50 deletions
diff --git a/gcc/pretty-print.c b/gcc/pretty-print.c
index 8febda0..86ae3a5 100644
--- a/gcc/pretty-print.c
+++ b/gcc/pretty-print.c
@@ -1227,8 +1227,8 @@ test_basic_printing ()
prints EXPECTED, assuming that pp_show_color is SHOW_COLOR. */
static void
-assert_pp_format_va (const char *expected, bool show_color, const char *fmt,
- va_list *ap)
+assert_pp_format_va (const location &loc, const char *expected,
+ bool show_color, const char *fmt, va_list *ap)
{
pretty_printer pp;
text_info ti;
@@ -1243,34 +1243,59 @@ assert_pp_format_va (const char *expected, bool show_color, const char *fmt,
pp_show_color (&pp) = show_color;
pp_format (&pp, &ti);
pp_output_formatted_text (&pp);
- ASSERT_STREQ (expected, pp_formatted_text (&pp));
+ ASSERT_STREQ_AT (loc, expected, pp_formatted_text (&pp));
}
/* Verify that pp_format (FMT, ...) followed by pp_output_formatted_text
prints EXPECTED, with show_color disabled. */
static void
-assert_pp_format (const char *expected, const char *fmt, ...)
+assert_pp_format (const location &loc, const char *expected,
+ const char *fmt, ...)
{
va_list ap;
va_start (ap, fmt);
- assert_pp_format_va (expected, false, fmt, &ap);
+ assert_pp_format_va (loc, expected, false, fmt, &ap);
va_end (ap);
}
/* As above, but with colorization enabled. */
static void
-assert_pp_format_colored (const char *expected, const char *fmt, ...)
+assert_pp_format_colored (const location &loc, const char *expected,
+ const char *fmt, ...)
{
va_list ap;
va_start (ap, fmt);
- assert_pp_format_va (expected, true, fmt, &ap);
+ assert_pp_format_va (loc, expected, true, fmt, &ap);
va_end (ap);
}
+/* Helper function for calling testing pp_format,
+ by calling assert_pp_format with various numbers of arguments.
+ These exist mostly to avoid having to write SELFTEST_LOCATION
+ throughout test_pp_format. */
+
+#define ASSERT_PP_FORMAT_1(EXPECTED, FMT, ARG1) \
+ SELFTEST_BEGIN_STMT \
+ assert_pp_format ((SELFTEST_LOCATION), (EXPECTED), (FMT), \
+ (ARG1)); \
+ SELFTEST_END_STMT
+
+#define ASSERT_PP_FORMAT_2(EXPECTED, FMT, ARG1, ARG2) \
+ SELFTEST_BEGIN_STMT \
+ assert_pp_format ((SELFTEST_LOCATION), (EXPECTED), (FMT), \
+ (ARG1), (ARG2)); \
+ SELFTEST_END_STMT
+
+#define ASSERT_PP_FORMAT_3(EXPECTED, FMT, ARG1, ARG2, ARG3) \
+ SELFTEST_BEGIN_STMT \
+ assert_pp_format ((SELFTEST_LOCATION), (EXPECTED), (FMT), \
+ (ARG1), (ARG2), (ARG3)); \
+ SELFTEST_END_STMT
+
/* Verify that pp_format works, for various format codes. */
static void
@@ -1284,68 +1309,71 @@ test_pp_format ()
close_quote = "'";
/* Verify that plain text is passed through unchanged. */
- assert_pp_format ("unformatted", "unformatted");
+ assert_pp_format (SELFTEST_LOCATION, "unformatted", "unformatted");
/* Verify various individual format codes, in the order listed in the
comment for pp_format above. For each code, we append a second
argument with a known bit pattern (0x12345678), to ensure that we
are consuming arguments correctly. */
- assert_pp_format ("-27 12345678", "%d %x", -27, 0x12345678);
- assert_pp_format ("-5 12345678", "%i %x", -5, 0x12345678);
- assert_pp_format ("10 12345678", "%u %x", 10, 0x12345678);
- assert_pp_format ("17 12345678", "%o %x", 15, 0x12345678);
- assert_pp_format ("cafebabe 12345678", "%x %x", 0xcafebabe, 0x12345678);
- assert_pp_format ("-27 12345678", "%ld %x", (long)-27, 0x12345678);
- assert_pp_format ("-5 12345678", "%li %x", (long)-5, 0x12345678);
- assert_pp_format ("10 12345678", "%lu %x", (long)10, 0x12345678);
- assert_pp_format ("17 12345678", "%lo %x", (long)15, 0x12345678);
- assert_pp_format ("cafebabe 12345678", "%lx %x", (long)0xcafebabe,
- 0x12345678);
- assert_pp_format ("-27 12345678", "%lld %x", (long long)-27, 0x12345678);
- assert_pp_format ("-5 12345678", "%lli %x", (long long)-5, 0x12345678);
- assert_pp_format ("10 12345678", "%llu %x", (long long)10, 0x12345678);
- assert_pp_format ("17 12345678", "%llo %x", (long long)15, 0x12345678);
- assert_pp_format ("cafebabe 12345678", "%llx %x", (long long)0xcafebabe,
- 0x12345678);
- assert_pp_format ("-27 12345678", "%wd %x", (HOST_WIDE_INT)-27, 0x12345678);
- assert_pp_format ("-5 12345678", "%wi %x", (HOST_WIDE_INT)-5, 0x12345678);
- assert_pp_format ("10 12345678", "%wu %x", (unsigned HOST_WIDE_INT)10,
- 0x12345678);
- assert_pp_format ("17 12345678", "%wo %x", (HOST_WIDE_INT)15, 0x12345678);
- assert_pp_format ("0xcafebabe 12345678", "%wx %x", (HOST_WIDE_INT)0xcafebabe,
- 0x12345678);
- assert_pp_format ("A 12345678", "%c %x", 'A', 0x12345678);
- assert_pp_format ("hello world 12345678", "%s %x", "hello world",
- 0x12345678);
+ ASSERT_PP_FORMAT_2 ("-27 12345678", "%d %x", -27, 0x12345678);
+ ASSERT_PP_FORMAT_2 ("-5 12345678", "%i %x", -5, 0x12345678);
+ ASSERT_PP_FORMAT_2 ("10 12345678", "%u %x", 10, 0x12345678);
+ ASSERT_PP_FORMAT_2 ("17 12345678", "%o %x", 15, 0x12345678);
+ ASSERT_PP_FORMAT_2 ("cafebabe 12345678", "%x %x", 0xcafebabe, 0x12345678);
+ ASSERT_PP_FORMAT_2 ("-27 12345678", "%ld %x", (long)-27, 0x12345678);
+ ASSERT_PP_FORMAT_2 ("-5 12345678", "%li %x", (long)-5, 0x12345678);
+ ASSERT_PP_FORMAT_2 ("10 12345678", "%lu %x", (long)10, 0x12345678);
+ ASSERT_PP_FORMAT_2 ("17 12345678", "%lo %x", (long)15, 0x12345678);
+ ASSERT_PP_FORMAT_2 ("cafebabe 12345678", "%lx %x", (long)0xcafebabe,
+ 0x12345678);
+ ASSERT_PP_FORMAT_2 ("-27 12345678", "%lld %x", (long long)-27, 0x12345678);
+ ASSERT_PP_FORMAT_2 ("-5 12345678", "%lli %x", (long long)-5, 0x12345678);
+ ASSERT_PP_FORMAT_2 ("10 12345678", "%llu %x", (long long)10, 0x12345678);
+ ASSERT_PP_FORMAT_2 ("17 12345678", "%llo %x", (long long)15, 0x12345678);
+ ASSERT_PP_FORMAT_2 ("cafebabe 12345678", "%llx %x", (long long)0xcafebabe,
+ 0x12345678);
+ ASSERT_PP_FORMAT_2 ("-27 12345678", "%wd %x", (HOST_WIDE_INT)-27, 0x12345678);
+ ASSERT_PP_FORMAT_2 ("-5 12345678", "%wi %x", (HOST_WIDE_INT)-5, 0x12345678);
+ ASSERT_PP_FORMAT_2 ("10 12345678", "%wu %x", (unsigned HOST_WIDE_INT)10,
+ 0x12345678);
+ ASSERT_PP_FORMAT_2 ("17 12345678", "%wo %x", (HOST_WIDE_INT)15, 0x12345678);
+ ASSERT_PP_FORMAT_2 ("0xcafebabe 12345678", "%wx %x", (HOST_WIDE_INT)0xcafebabe,
+ 0x12345678);
+ ASSERT_PP_FORMAT_2 ("A 12345678", "%c %x", 'A', 0x12345678);
+ ASSERT_PP_FORMAT_2 ("hello world 12345678", "%s %x", "hello world",
+ 0x12345678);
/* We can't test for %p; the pointer is printed in an implementation-defined
manner. */
- assert_pp_format ("normal colored normal 12345678",
- "normal %rcolored%R normal %x",
- "error", 0x12345678);
+ ASSERT_PP_FORMAT_2 ("normal colored normal 12345678",
+ "normal %rcolored%R normal %x",
+ "error", 0x12345678);
/* The following assumes an empty value for GCC_COLORS. */
assert_pp_format_colored
- ("normal \33[01;31m\33[Kcolored\33[m\33[K normal 12345678",
+ (SELFTEST_LOCATION,
+ "normal \33[01;31m\33[Kcolored\33[m\33[K normal 12345678",
"normal %rcolored%R normal %x", "error", 0x12345678);
/* TODO:
%m: strerror(text->err_no) - does not consume a value from args_ptr. */
- assert_pp_format ("% 12345678", "%% %x", 0x12345678);
- assert_pp_format ("` 12345678", "%< %x", 0x12345678);
- assert_pp_format ("' 12345678", "%> %x", 0x12345678);
- assert_pp_format ("' 12345678", "%' %x", 0x12345678);
- assert_pp_format ("abc 12345678", "%.*s %x", 3, "abcdef", 0x12345678);
- assert_pp_format ("abc 12345678", "%.3s %x", "abcdef", 0x12345678);
+ ASSERT_PP_FORMAT_1 ("% 12345678", "%% %x", 0x12345678);
+ ASSERT_PP_FORMAT_1 ("` 12345678", "%< %x", 0x12345678);
+ ASSERT_PP_FORMAT_1 ("' 12345678", "%> %x", 0x12345678);
+ ASSERT_PP_FORMAT_1 ("' 12345678", "%' %x", 0x12345678);
+ ASSERT_PP_FORMAT_3 ("abc 12345678", "%.*s %x", 3, "abcdef", 0x12345678);
+ ASSERT_PP_FORMAT_2 ("abc 12345678", "%.3s %x", "abcdef", 0x12345678);
/* Verify flag 'q'. */
- assert_pp_format ("`foo' 12345678", "%qs %x", "foo", 0x12345678);
- assert_pp_format_colored ("`\33[01m\33[Kfoo\33[m\33[K' 12345678", "%qs %x",
+ ASSERT_PP_FORMAT_2 ("`foo' 12345678", "%qs %x", "foo", 0x12345678);
+ assert_pp_format_colored (SELFTEST_LOCATION,
+ "`\33[01m\33[Kfoo\33[m\33[K' 12345678", "%qs %x",
"foo", 0x12345678);
/* Verify that combinations work, along with unformatted text. */
- assert_pp_format ("the quick brown fox jumps over the lazy dog",
+ assert_pp_format (SELFTEST_LOCATION,
+ "the quick brown fox jumps over the lazy dog",
"the %s %s %s jumps over the %s %s",
"quick", "brown", "fox", "lazy", "dog");
- assert_pp_format ("item 3 of 7", "item %i of %i", 3, 7);
- assert_pp_format ("problem with `bar' at line 10",
+ assert_pp_format (SELFTEST_LOCATION, "item 3 of 7", "item %i of %i", 3, 7);
+ assert_pp_format (SELFTEST_LOCATION, "problem with `bar' at line 10",
"problem with %qs at line %i", "bar", 10);
/* Restore old values of open_quote and close_quote. */