OSDN Git Service

[lldb/Test] Make substrs argument to self.expect ordered.
authorJonas Devlieghere <jonas@devlieghere.com>
Fri, 31 Jan 2020 21:27:15 +0000 (13:27 -0800)
committerJonas Devlieghere <jonas@devlieghere.com>
Fri, 31 Jan 2020 21:35:37 +0000 (13:35 -0800)
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

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

index 602749c..933a99d 100644 (file)
@@ -2341,8 +2341,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 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)