Skip to content

Commit dd2bf73

Browse files
committed
[lldb] Support ordered patterns in lldbtest.expect
Change `lldbtest.expect` to search the given `patterns` in order, if the `ordered` parameter is true. The `ordered` parameter is true by default, so this change also fixes tests by either tweaking the patterns to work in order, or by setting `ordered=False`. I have often wanted to test with `patterns` and also verify the order. This change allows that.
1 parent 0bd8a75 commit dd2bf73

File tree

9 files changed

+20
-16
lines changed

9 files changed

+20
-16
lines changed

lldb/packages/Python/lldbsuite/test/lldbtest.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2460,9 +2460,9 @@ def found_str(matched):
24602460
if substrs and matched == matching:
24612461
start = 0
24622462
for substr in substrs:
2463-
index = output[start:].find(substr)
2464-
start = start + index + len(substr) if ordered and matching else 0
2463+
index = output.find(substr, start)
24652464
matched = index != -1
2465+
start = index + len(substr) if ordered and matched else 0
24662466
log_lines.append(
24672467
'{} sub string: "{}" ({})'.format(
24682468
expecting_str, substr, found_str(matched)
@@ -2473,20 +2473,21 @@ def found_str(matched):
24732473
break
24742474

24752475
if patterns and matched == matching:
2476+
start = 0
24762477
for pattern in patterns:
2477-
matched = re.search(pattern, output)
2478+
pat = re.compile(pattern)
2479+
match = pat.search(output, start)
2480+
matched = bool(match)
2481+
start = match.end() if ordered and matched else 0
24782482

24792483
pattern_line = '{} regex pattern: "{}" ({}'.format(
24802484
expecting_str, pattern, found_str(matched)
24812485
)
2482-
if matched:
2483-
pattern_line += ', matched "{}"'.format(matched.group(0))
2486+
if match:
2487+
pattern_line += ', matched "{}"'.format(match.group(0))
24842488
pattern_line += ")"
24852489
log_lines.append(pattern_line)
24862490

2487-
# Convert to bool because match objects
2488-
# are True-ish but is not True itself
2489-
matched = bool(matched)
24902491
if matched != matching:
24912492
break
24922493

lldb/test/API/functionalities/alias/TestBtAliasRepeat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def test(self):
99
lldbutil.run_to_source_breakpoint(self, "return", lldb.SBFileSpec("main.c"))
1010

1111
# Expect "frame #0" but not "frame #1".
12-
self.expect("bt 1", inHistory=True, patterns=["frame #0", "^(?!.*frame #1)"])
12+
self.expect("bt 1", inHistory=True, patterns=["frame #0", "(?!.*frame #1)"])
1313

1414
# Run an empty command to run the repeat command for `bt`.
1515
# The repeat command for `bt N` lists the subsequent N frames.

lldb/test/API/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjCNSContainer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def nscontainers_data_formatter_commands(self):
5252

5353
self.expect(
5454
"frame variable -d run-target *nscfDictionary",
55+
ordered=False,
5556
patterns=[
5657
r"\(__NSCFDictionary\) \*nscfDictionary =",
5758
'key = 0x.* @"foo"',
@@ -67,6 +68,7 @@ def nscontainers_data_formatter_commands(self):
6768

6869
self.expect(
6970
"frame variable -d run-target *cfDictionaryRef",
71+
ordered=False,
7072
patterns=[
7173
r"\(const __CFDictionary\) \*cfDictionaryRef =",
7274
'key = 0x.* @"foo"',

lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/unordered/TestDataFormatterGenericUnordered.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ def cleanup():
122122
)
123123

124124
def look_for_content_and_continue(self, var_name, patterns):
125-
self.expect(("frame variable %s" % var_name), patterns=patterns)
126-
self.expect(("frame variable %s" % var_name), patterns=patterns)
125+
self.expect(("frame variable %s" % var_name), ordered=False, patterns=patterns)
126+
self.expect(("frame variable %s" % var_name), ordered=False, patterns=patterns)
127127
self.runCmd("continue")
128128

129129
@add_test_categories(["libstdcxx"])

lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/span/TestDataFormatterLibcxxSpan.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,4 @@ def test_ref_and_ptr(self):
172172

173173
# The pointer should just show the right number of elements:
174174

175-
self.expect("frame variable ptr", patterns=["ptr = 0x.*", " size=5"])
175+
self.expect("frame variable ptr", patterns=["ptr = 0x[0-9a-f]+ size=5"])

lldb/test/API/functionalities/data-formatter/root-reference-children/TestRootReferenceChildren.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ def test(self):
2020
"v summary_and_children_ref", substrs=["some summary", "child = 30"]
2121
)
2222
self.expect(
23-
"v summary_only_ref", patterns=["some summary", "(?s)^(?!.*child = )"]
23+
"v summary_only_ref", patterns=["some summary", "(?s)(?!.*child = )"]
2424
)
2525
self.expect(
26-
"v children_only_ref", patterns=["(?s)^(?!.*some summary)", "child = 30"]
26+
"v children_only_ref", patterns=["(?s)(?!.*some summary)", "child = 30"]
2727
)

lldb/test/API/lang/cpp/signed_types/TestSignedTypes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ def test(self):
5757
"frame variable --show-types --no-args",
5858
VARIABLES_DISPLAYED_CORRECTLY,
5959
patterns=[
60-
r"\((short int|short)\) the_signed_short = 99",
6160
r"\((signed char|char)\) the_signed_char = 'c'",
61+
r"\((short int|short)\) the_signed_short = 99",
6262
],
6363
substrs=[
6464
"(int) the_signed_int = 99",

lldb/test/API/lang/objc/foundation/TestObjCMethods.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def test_data_type_and_expr(self):
166166
"frame variable --show-types --scope",
167167
VARIABLES_DISPLAYED_CORRECTLY,
168168
substrs=["ARG: (MyString *) self"],
169-
patterns=[r"ARG: \(.*\) _cmd", "(objc_selector *)|(SEL)"],
169+
patterns=[r"ARG: \(SEL|objc_selector \*\) _cmd"],
170170
)
171171

172172
# rdar://problem/8651752

lldb/test/API/source-manager/TestSourceManager.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ def do_display_source_python_api(
129129
stream.GetData(),
130130
"Source code displayed correctly:\n" + stream.GetData(),
131131
exe=False,
132+
ordered=False,
132133
patterns=["=>", "%d.*Hello world" % self.line, needle_regex],
133134
)
134135

0 commit comments

Comments
 (0)