summaryrefslogtreecommitdiffstats
path: root/lldb/packages/Python/lldbsuite/test/source-manager/TestSourceManager.py
diff options
context:
space:
mode:
authorRaphael Isemann <teemperor@gmail.com>2018-08-02 00:30:15 +0000
committerRaphael Isemann <teemperor@gmail.com>2018-08-02 00:30:15 +0000
commit566afa0ab2ce3fc753ce7490f7c1394c3f4699c0 (patch)
tree4295653b2b9482af2a8f0cbcd7cc90ad7fd54147 /lldb/packages/Python/lldbsuite/test/source-manager/TestSourceManager.py
parentcedebd594083a54cfb0a0b766fd000b6f11216fa (diff)
downloadbcm5719-llvm-566afa0ab2ce3fc753ce7490f7c1394c3f4699c0.tar.gz
bcm5719-llvm-566afa0ab2ce3fc753ce7490f7c1394c3f4699c0.zip
[LLDB] Added syntax highlighting support
Summary: This patch adds syntax highlighting support to LLDB. When enabled (and lldb is allowed to use colors), printed source code is annotated with the ANSI color escape sequences. So far we have only one highlighter which is based on Clang and is responsible for all languages that are supported by Clang. It essentially just runs the raw lexer over the input and then surrounds the specific tokens with the configured escape sequences. Reviewers: zturner, davide Reviewed By: davide Subscribers: labath, teemperor, llvm-commits, mgorny, lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D49334 llvm-svn: 338662
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test/source-manager/TestSourceManager.py')
-rw-r--r--lldb/packages/Python/lldbsuite/test/source-manager/TestSourceManager.py29
1 files changed, 26 insertions, 3 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/source-manager/TestSourceManager.py b/lldb/packages/Python/lldbsuite/test/source-manager/TestSourceManager.py
index 0df4f8b2d2a..dc43cd0815a 100644
--- a/lldb/packages/Python/lldbsuite/test/source-manager/TestSourceManager.py
+++ b/lldb/packages/Python/lldbsuite/test/source-manager/TestSourceManager.py
@@ -22,6 +22,8 @@ def ansi_underline_surround_regex(inner_regex_text):
# return re.compile(r"\[4m%s\[0m" % inner_regex_text)
return "4.+\033\\[4m%s\033\\[0m" % inner_regex_text
+def ansi_color_surround_regex(inner_regex_text):
+ return "\033\\[3[0-7]m%s\033\\[0m" % inner_regex_text
class SourceManagerTestCase(TestBase):
@@ -47,7 +49,7 @@ class SourceManagerTestCase(TestBase):
# the character column after the initial whitespace.
return len(stop_line) - len(stop_line.lstrip()) + 1
- def do_display_source_python_api(self, use_color, column_marker_regex):
+ def do_display_source_python_api(self, use_color, needle_regex, highlight_source=False):
self.build()
exe = self.getBuildArtifact("a.out")
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
@@ -69,6 +71,9 @@ class SourceManagerTestCase(TestBase):
# Setup whether we should use ansi escape sequences, including color
# and styles such as underline.
self.dbg.SetUseColor(use_color)
+ # Disable syntax highlighting if needed.
+
+ self.runCmd("settings set highlight-source " + str(highlight_source).lower())
filespec = lldb.SBFileSpec(self.file, False)
source_mgr = self.dbg.GetSourceManager()
@@ -87,10 +92,10 @@ class SourceManagerTestCase(TestBase):
# => 4 printf("Hello world.\n"); // Set break point at this line.
# 5 return 0;
# 6 }
- self.expect(stream.GetData(), "Source code displayed correctly",
+ self.expect(stream.GetData(), "Source code displayed correctly:\n" + stream.GetData(),
exe=False,
patterns=['=> %d.*Hello world' % self.line,
- column_marker_regex])
+ needle_regex])
# Boundary condition testings for SBStream(). LLDB should not crash!
stream.Print(None)
@@ -111,6 +116,24 @@ class SourceManagerTestCase(TestBase):
underline_regex = ansi_underline_surround_regex(r".")
self.do_display_source_python_api(use_color, underline_regex)
+ @add_test_categories(['pyapi'])
+ def test_display_source_python_ansi_terminal_syntax_highlighting(self):
+ """Test display of source using the SBSourceManager API and check for
+ the syntax highlighted output"""
+ use_color = True
+ syntax_highlighting = True;
+
+ # Just pick 'int' as something that should be colored.
+ color_regex = ansi_color_surround_regex("int")
+ self.do_display_source_python_api(use_color, color_regex, syntax_highlighting)
+
+ # Same for 'char'.
+ color_regex = ansi_color_surround_regex("char")
+ self.do_display_source_python_api(use_color, color_regex, syntax_highlighting)
+
+ # Test that we didn't color unrelated identifiers.
+ self.do_display_source_python_api(use_color, r" printf\(", syntax_highlighting)
+
def test_move_and_then_display_source(self):
"""Test that target.source-map settings work by moving main.c to hidden/main.c."""
self.build()
OpenPOWER on IntegriCloud