Skip to content

Commit 349295f

Browse files
committedOct 28, 2021
[lldb/test] Allow indentation in inline tests
This makes it possible to use for loops (and other language constructs) in inline tests. Differential Revision: https://reviews.llvm.org/D112706
1 parent e8535fa commit 349295f

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed
 

‎lldb/packages/Python/lldbsuite/test/lldbinline.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
# System modules
55
import os
6+
import textwrap
67

78
# Third-party modules
89
import io
@@ -38,7 +39,7 @@ def parse_one_command(self, line):
3839
new_breakpoint = True
3940

4041
if len(parts) == 2:
41-
command = parts[1].strip() # take off whitespace
42+
command = parts[1].rstrip()
4243
new_breakpoint = parts[0].strip() != ""
4344

4445
return (command, new_breakpoint)
@@ -68,6 +69,8 @@ def parse_source_files(self, source_files):
6869
else:
6970
current_breakpoint['command'] = current_breakpoint[
7071
'command'] + "\n" + command
72+
for bkpt in self.breakpoints:
73+
bkpt['command'] = textwrap.dedent(bkpt['command'])
7174

7275
def set_breakpoints(self, target):
7376
for breakpoint in self.breakpoints:
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from lldbsuite.test.lldbinline import CommandParser
2+
from lldbsuite.test.lldbtest import Base
3+
import textwrap
4+
5+
6+
class TestCommandParser(Base):
7+
8+
mydir = Base.compute_mydir(__file__)
9+
10+
def test_indentation(self):
11+
"""Test indentation handling"""
12+
filename = self.getBuildArtifact("test_file.cpp")
13+
with open(filename, "w") as f:
14+
f.write(textwrap.dedent("""\
15+
int q;
16+
int w; //% first break
17+
int e;
18+
int r; //% second break
19+
//% continue second
20+
//% continuing indented
21+
//% not indented
22+
int t; //% third break
23+
"""))
24+
p = CommandParser()
25+
p.parse_source_files([filename])
26+
27+
def bkpt(line, cmd):
28+
return {'file_name': filename, 'line_number': line, 'command': cmd}
29+
self.assertEqual(
30+
p.breakpoints, [
31+
bkpt(2, 'first break'),
32+
bkpt(4, 'second break\ncontinue second\n continuing indented\nnot indented'),
33+
bkpt(8, "third break")])

0 commit comments

Comments
 (0)
Please sign in to comment.