diff options
author | David Malcolm <dmalcolm@redhat.com> | 2018-11-30 22:46:45 +0000 |
---|---|---|
committer | David Malcolm <dmalcolm@gcc.gnu.org> | 2018-11-30 22:46:45 +0000 |
commit | 553a316b99c4af9d59e9594204298633b12f6618 (patch) | |
tree | 168260d113bc624bec27096eac34175661bea86c /gcc | |
parent | ed1b53a0abc298f13a89e2bb69cbedfb5c4dd6f9 (diff) | |
download | gcc-553a316b99c4af9d59e9594204298633b12f6618.zip gcc-553a316b99c4af9d59e9594204298633b12f6618.tar.gz gcc-553a316b99c4af9d59e9594204298633b12f6618.tar.bz2 |
pretty-print.c: add selftest::test_prefixes_and_wrapping
gcc/ChangeLog:
* pretty-print.c (class selftest::test_pretty_printer): New
subclass of pretty_printer.
(selftest::test_prefixes_and_wrapping): New test.
(selftest::pretty_print_c_tests): Call it.
From-SVN: r266695
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/pretty-print.c | 96 |
2 files changed, 103 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 873d1c8..58b5886 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2018-11-30 David Malcolm <dmalcolm@redhat.com> + + * pretty-print.c (class selftest::test_pretty_printer): New + subclass of pretty_printer. + (selftest::test_prefixes_and_wrapping): New test. + (selftest::pretty_print_c_tests): Call it. + 2018-11-30 Michael Ploujnikov <michael.ploujnikov@oracle.com> Minimize clone counter memory usage in create_virtual_clone. diff --git a/gcc/pretty-print.c b/gcc/pretty-print.c index 19ef75b..691dbb6 100644 --- a/gcc/pretty-print.c +++ b/gcc/pretty-print.c @@ -2217,6 +2217,101 @@ test_pp_format () "problem with %qs at line %i", "bar", 10); } +/* A subclass of pretty_printer for use by test_prefixes_and_wrapping. */ + +class test_pretty_printer : public pretty_printer +{ + public: + test_pretty_printer (enum diagnostic_prefixing_rule_t rule, + int max_line_length) + { + pp_set_prefix (this, xstrdup ("PREFIX: ")); + wrapping.rule = rule; + pp_set_line_maximum_length (this, max_line_length); + } +}; + +/* Verify that the various values of enum diagnostic_prefixing_rule_t work + as expected, with and without line wrapping. */ + +static void +test_prefixes_and_wrapping () +{ + /* Tests of the various prefixing rules, without wrapping. + Newlines embedded in pp_string don't affect it; we have to + explicitly call pp_newline. */ + { + test_pretty_printer pp (DIAGNOSTICS_SHOW_PREFIX_ONCE, 0); + pp_string (&pp, "the quick brown fox"); + pp_newline (&pp); + pp_string (&pp, "jumps over the lazy dog"); + pp_newline (&pp); + ASSERT_STREQ (pp_formatted_text (&pp), + "PREFIX: the quick brown fox\n" + " jumps over the lazy dog\n"); + } + { + test_pretty_printer pp (DIAGNOSTICS_SHOW_PREFIX_NEVER, 0); + pp_string (&pp, "the quick brown fox"); + pp_newline (&pp); + pp_string (&pp, "jumps over the lazy dog"); + pp_newline (&pp); + ASSERT_STREQ (pp_formatted_text (&pp), + "the quick brown fox\n" + "jumps over the lazy dog\n"); + } + { + test_pretty_printer pp (DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE, 0); + pp_string (&pp, "the quick brown fox"); + pp_newline (&pp); + pp_string (&pp, "jumps over the lazy dog"); + pp_newline (&pp); + ASSERT_STREQ (pp_formatted_text (&pp), + "PREFIX: the quick brown fox\n" + "PREFIX: jumps over the lazy dog\n"); + } + + /* Tests of the various prefixing rules, with wrapping. */ + { + test_pretty_printer pp (DIAGNOSTICS_SHOW_PREFIX_ONCE, 20); + pp_string (&pp, "the quick brown fox jumps over the lazy dog"); + pp_newline (&pp); + pp_string (&pp, "able was I ere I saw elba"); + pp_newline (&pp); + ASSERT_STREQ (pp_formatted_text (&pp), + "PREFIX: the quick \n" + " brown fox jumps \n" + " over the lazy \n" + " dog\n" + " able was I ere I \n" + " saw elba\n"); + } + { + test_pretty_printer pp (DIAGNOSTICS_SHOW_PREFIX_NEVER, 20); + pp_string (&pp, "the quick brown fox jumps over the lazy dog"); + pp_newline (&pp); + pp_string (&pp, "able was I ere I saw elba"); + pp_newline (&pp); + ASSERT_STREQ (pp_formatted_text (&pp), + "the quick brown fox \n" + "jumps over the lazy \n" + "dog\n" + "able was I ere I \n" + "saw elba\n"); + } + { + test_pretty_printer pp (DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE, 20); + pp_string (&pp, "the quick brown fox jumps over the lazy dog"); + pp_newline (&pp); + pp_string (&pp, "able was I ere I saw elba"); + pp_newline (&pp); + ASSERT_STREQ (pp_formatted_text (&pp), + "PREFIX: the quick brown fox jumps over the lazy dog\n" + "PREFIX: able was I ere I saw elba\n"); + } + +} + /* Run all of the selftests within this file. */ void @@ -2224,6 +2319,7 @@ pretty_print_c_tests () { test_basic_printing (); test_pp_format (); + test_prefixes_and_wrapping (); } } // namespace selftest |