forked from Imagelibrary/binutils-gdb
[gdb/cli] Add gnu-source-highlight selftest
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 ... Tested on x86_64-linux.
This commit is contained in:
@@ -22,7 +22,6 @@
|
|||||||
#include "source.h"
|
#include "source.h"
|
||||||
#include "cli/cli-style.h"
|
#include "cli/cli-style.h"
|
||||||
#include "symtab.h"
|
#include "symtab.h"
|
||||||
#include "gdbsupport/selftest.h"
|
|
||||||
#include "objfiles.h"
|
#include "objfiles.h"
|
||||||
#include "exec.h"
|
#include "exec.h"
|
||||||
#include "cli/cli-cmds.h"
|
#include "cli/cli-cmds.h"
|
||||||
@@ -40,6 +39,10 @@
|
|||||||
#include <srchilite/settings.h>
|
#include <srchilite/settings.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if GDB_SELF_TEST
|
||||||
|
#include "gdbsupport/selftest.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
/* The number of source files we'll cache. */
|
/* The number of source files we'll cache. */
|
||||||
|
|
||||||
#define MAX_ENTRIES 5
|
#define MAX_ENTRIES 5
|
||||||
@@ -258,6 +261,43 @@ try_source_highlight (std::string &contents ATTRIBUTE_UNUSED,
|
|||||||
#endif /* HAVE_SOURCE_HIGHLIGHT */
|
#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. */
|
/* See source-cache.h. */
|
||||||
|
|
||||||
bool
|
bool
|
||||||
@@ -489,5 +529,9 @@ styling to source code lines that are shown."),
|
|||||||
|
|
||||||
#if GDB_SELF_TEST
|
#if GDB_SELF_TEST
|
||||||
selftests::register_test ("source-cache", selftests::extract_lines_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
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user