public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: Re: [PATCH v5 3/6] [gdb/cli] Add gnu-source-highlight selftest
Date: Tue, 24 Oct 2023 14:33:57 +0200	[thread overview]
Message-ID: <7d7720ee-f221-4981-8428-a11d5d84fb53@suse.de> (raw)
In-Reply-To: <20231024094933.12009-4-tdevries@suse.de>

On 10/24/23 11:49, Tom de Vries wrote:
> Add a selftest gnu-source-highlight:
> ...
> $ gdb -q -batch -ex "maint selftest gnu-source-highlight"
> Running selftest gnu-source-highlight.
> Ran 1 unit tests, 0 failed
> ...
> 

I realized that this simplified version doesn't really depend on 
anything from the series, so ... pushed.

Thanks,
- Tom

> Tested on x86_64-linux.
> ---
>   gdb/source-cache.c | 46 +++++++++++++++++++++++++++++++++++++++++++++-
>   1 file changed, 45 insertions(+), 1 deletion(-)
> 
> diff --git a/gdb/source-cache.c b/gdb/source-cache.c
> index 92acb100901..c955929b543 100644
> --- a/gdb/source-cache.c
> +++ b/gdb/source-cache.c
> @@ -22,7 +22,6 @@
>   #include "source.h"
>   #include "cli/cli-style.h"
>   #include "symtab.h"
> -#include "gdbsupport/selftest.h"
>   #include "objfiles.h"
>   #include "exec.h"
>   #include "cli/cli-cmds.h"
> @@ -40,6 +39,10 @@
>   #include <srchilite/settings.h>
>   #endif
>   
> +#if GDB_SELF_TEST
> +#include "gdbsupport/selftest.h"
> +#endif
> +
>   /* The number of source files we'll cache.  */
>   
>   #define MAX_ENTRIES 5
> @@ -258,6 +261,43 @@ try_source_highlight (std::string &contents ATTRIBUTE_UNUSED,
>   #endif /* HAVE_SOURCE_HIGHLIGHT */
>   }
>   
> +#ifdef HAVE_SOURCE_HIGHLIGHT
> +#if GDB_SELF_TEST
> +namespace selftests
> +{
> +static void gnu_source_highlight_test ()
> +{
> +  const std::string prog
> +    = ("int\n"
> +       "foo (void)\n"
> +       "{\n"
> +       "  return 0;\n"
> +       "}\n");
> +  const std::string fullname = "test.c";
> +  std::string styled_prog;
> +
> +  bool res = false;
> +  bool saw_exception = false;
> +  styled_prog = prog;
> +  try
> +    {
> +      res = try_source_highlight (styled_prog, language_c, fullname);
> +    }
> +  catch (...)
> +    {
> +      saw_exception = true;
> +    }
> +
> +  SELF_CHECK (!saw_exception);
> +  if (res)
> +    SELF_CHECK (prog.size () < styled_prog.size ());
> +  else
> +    SELF_CHECK (prog == styled_prog);
> +}
> +}
> +#endif /* GDB_SELF_TEST */
> +#endif /* HAVE_SOURCE_HIGHLIGHT */
> +
>   /* See source-cache.h.  */
>   
>   bool
> @@ -489,5 +529,9 @@ styling to source code lines that are shown."),
>   
>   #if GDB_SELF_TEST
>     selftests::register_test ("source-cache", selftests::extract_lines_test);
> +#ifdef HAVE_SOURCE_HIGHLIGHT
> +  selftests::register_test ("gnu-source-highlight",
> +			    selftests::gnu_source_highlight_test);
> +#endif
>   #endif
>   }


  reply	other threads:[~2023-10-24 12:33 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-24  9:49 [PATCH v5 0/6] [gdb/cli] Allow source highlighting to be interrupted Tom de Vries
2023-10-24  9:49 ` [PATCH v5 1/6] [gdb/cli] Add signal_handler_selftest Tom de Vries
2023-11-22 16:26   ` Tom de Vries
2023-10-24  9:49 ` [PATCH v5 2/6] [gdb/python] Make python selftest more robust Tom de Vries
2023-10-24  9:49 ` [PATCH v5 3/6] [gdb/cli] Add gnu-source-highlight selftest Tom de Vries
2023-10-24 12:33   ` Tom de Vries [this message]
2023-10-24  9:49 ` [PATCH v5 4/6] [gdb/cli] Allow source highlighting to be interrupted Tom de Vries
2023-10-24  9:49 ` [PATCH v5 5/6] [gdb/cli] Ask if source highlighting should " Tom de Vries
2023-10-24  9:49 ` [PATCH v5 6/6] [gdb/cli] Simplify gdb_highlight_event_listener::notify Tom de Vries

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7d7720ee-f221-4981-8428-a11d5d84fb53@suse.de \
    --to=tdevries@suse.de \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).