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)
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)
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits