[Lldb-commits] [PATCH] D89302: [lldb] Also Catch invalid calls to TestPExpectTest's expect()

Raphael Isemann via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu Nov 5 05:09:11 PST 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rG2f84b59a4cf9: [lldb] Also Catch invalid calls to TestPExpectTest's expect() (authored by teemperor).
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89302/new/

https://reviews.llvm.org/D89302

Files:
  lldb/packages/Python/lldbsuite/test/lldbpexpect.py
  lldb/test/API/test_utils/TestPExpectTest.py


Index: lldb/test/API/test_utils/TestPExpectTest.py
===================================================================
--- /dev/null
+++ lldb/test/API/test_utils/TestPExpectTest.py
@@ -0,0 +1,29 @@
+"""
+Test the PExpectTest test functions.
+"""
+
+
+import lldb
+import lldbsuite.test.lldbutil as lldbutil
+from lldbsuite.test.lldbtest import *
+from textwrap import dedent
+
+
+class TestPExpectTestCase(TestBase):
+
+    mydir = TestBase.compute_mydir(__file__)
+    NO_DEBUG_INFO_TESTCASE = True
+
+    def assert_expect_fails_with(self, cmd, expect_args, expected_msg):
+        try:
+            self.expect(cmd, **expect_args)
+        except AssertionError as e:
+            self.assertIn(expected_msg, str(e))
+        else:
+            self.fail("expect should have raised AssertionError!")
+
+    def test_expect(self):
+        # Test that passing a string to the 'substrs' argument is rejected.
+        self.assert_expect_fails_with("settings list prompt",
+            dict(substrs="some substring"),
+            "substrs must be a collection of strings")
Index: lldb/packages/Python/lldbsuite/test/lldbpexpect.py
===================================================================
--- lldb/packages/Python/lldbsuite/test/lldbpexpect.py
+++ lldb/packages/Python/lldbsuite/test/lldbpexpect.py
@@ -54,6 +54,10 @@
     def expect(self, cmd, substrs=None):
         self.assertNotIn('\n', cmd)
         self.child.sendline(cmd)
+        # If 'substrs' is a string then this code would just check that every
+        # character of the string is in the output.
+        assert not isinstance(substrs, six.string_types), \
+            "substrs must be a collection of strings"
         if substrs is not None:
             for s in substrs:
                 self.child.expect_exact(s)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89302.303089.patch
Type: text/x-patch
Size: 1798 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20201105/c44639fb/attachment.bin>


More information about the lldb-commits mailing list