From e211a7d2aafeeb9536f3aa9492601099655b833c Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Fri, 31 Jan 2020 14:13:20 -0800 Subject: [PATCH] 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 --- .../test/commands/target/basic/TestTargetCommand.py | 1 + .../lang/c/global_variables/TestGlobalVariables.py | 1 + lldb/packages/Python/lldbsuite/test/lldbtest.py | 10 +++++++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lldb/packages/Python/lldbsuite/test/commands/target/basic/TestTargetCommand.py b/lldb/packages/Python/lldbsuite/test/commands/target/basic/TestTargetCommand.py index 81d7804b85f2..95df78eef12a 100644 --- a/lldb/packages/Python/lldbsuite/test/commands/target/basic/TestTargetCommand.py +++ b/lldb/packages/Python/lldbsuite/test/commands/target/basic/TestTargetCommand.py @@ -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', diff --git a/lldb/packages/Python/lldbsuite/test/lang/c/global_variables/TestGlobalVariables.py b/lldb/packages/Python/lldbsuite/test/lang/c/global_variables/TestGlobalVariables.py index a471058b3b45..04b874942acb 100644 --- a/lldb/packages/Python/lldbsuite/test/lang/c/global_variables/TestGlobalVariables.py +++ b/lldb/packages/Python/lldbsuite/test/lang/c/global_variables/TestGlobalVariables.py @@ -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"', diff --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py b/lldb/packages/Python/lldbsuite/test/lldbtest.py index 602749c80fa8..fe4b198e93ce 100644 --- a/lldb/packages/Python/lldbsuite/test/lldbtest.py +++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py @@ -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)