Re-land "[lldb/Test] Make substrs argument to self.expect ordered."

Re-landing this now that (hopefully) all the failures this caused on the
bots have been addressed.

This patch changes the behavior of the substrs argument to self.expect.
Currently, the elements of substrs are unordered and as long as the
string appears in the output, the assertion passes.

We can be more precise by requiring that the substrings be ordered in
the way they appear. My hope is that this will make it harder to
accidentally pass a check because a string appears out of order.

Differential revision: https://reviews.llvm.org/D73766
This commit is contained in:
Jonas Devlieghere 2020-01-31 14:13:20 -08:00
parent c3a47221e0
commit e211a7d2aa
3 changed files with 11 additions and 1 deletions

View File

@ -245,6 +245,7 @@ class targetCommandTestCase(TestBase):
# It will find all the global and static variables in the current
# compile unit.
self.expect("target variable",
ordered=False,
substrs=['my_global_char',
'my_static_int',
'my_global_str',

View File

@ -79,6 +79,7 @@ class GlobalVariablesTestCase(TestBase):
self.expect(
"frame variable --show-types --scope --show-globals --no-args",
VARIABLES_DISPLAYED_CORRECTLY,
ordered=False,
substrs=[
'STATIC: (const char *) g_func_static_cstr',
'"g_func_static_cstr"',

View File

@ -2261,6 +2261,7 @@ FileCheck output:
substrs=None,
trace=False,
error=False,
ordered=True,
matching=True,
exe=True,
inHistory=False):
@ -2273,6 +2274,10 @@ FileCheck output:
'startstr', matches the substrings contained in 'substrs', and regexp
matches the patterns contained in 'patterns'.
When matching is true and ordered is true, which are both the default,
the strings in the substrs array have to appear in the command output
in the order in which they appear in the array.
If the keyword argument error is set to True, it signifies that the API
client is expecting the command to fail. In this case, the error stream
from running the command is retrieved and compared against the golden
@ -2341,8 +2346,11 @@ FileCheck output:
# Look for sub strings, if specified.
keepgoing = matched if matching else not matched
if substrs and keepgoing:
start = 0
for substr in substrs:
matched = output.find(substr) != -1
index = output[start:].find(substr)
start = start + index if ordered and matching else 0
matched = index != -1
with recording(self, trace) as sbuf:
print("%s sub string: %s" % (heading, substr), file=sbuf)
print("Matched" if matched else "Not matched", file=sbuf)