Skip to content

Commit 2f84b59

Browse files
committed
[lldb] Also Catch invalid calls to TestPExpectTest's expect()
This is a follow up to D88792 which found an issue in a call to PExpectTest's expect function that allows passing a string to the `substrs` parameter. However this issue was found by just grepping and TestPExpect's expect function is still accepting a single string as a value to `substrs`. This patch adds the same sanity check that D88792 added to the PExpectTest's implementation of `expect` and also adds a small test for it. Reviewed By: kastiglione, JDevlieghere Differential Revision: https://reviews.llvm.org/D89302
1 parent a7bcb3b commit 2f84b59

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

‎lldb/packages/Python/lldbsuite/test/lldbpexpect.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ def launch(self, executable=None, extra_args=None, timeout=30, dimensions=None):
5454
def expect(self, cmd, substrs=None):
5555
self.assertNotIn('\n', cmd)
5656
self.child.sendline(cmd)
57+
# If 'substrs' is a string then this code would just check that every
58+
# character of the string is in the output.
59+
assert not isinstance(substrs, six.string_types), \
60+
"substrs must be a collection of strings"
5761
if substrs is not None:
5862
for s in substrs:
5963
self.child.expect_exact(s)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""
2+
Test the PExpectTest test functions.
3+
"""
4+
5+
6+
import lldb
7+
import lldbsuite.test.lldbutil as lldbutil
8+
from lldbsuite.test.lldbtest import *
9+
from textwrap import dedent
10+
11+
12+
class TestPExpectTestCase(TestBase):
13+
14+
mydir = TestBase.compute_mydir(__file__)
15+
NO_DEBUG_INFO_TESTCASE = True
16+
17+
def assert_expect_fails_with(self, cmd, expect_args, expected_msg):
18+
try:
19+
self.expect(cmd, **expect_args)
20+
except AssertionError as e:
21+
self.assertIn(expected_msg, str(e))
22+
else:
23+
self.fail("expect should have raised AssertionError!")
24+
25+
def test_expect(self):
26+
# Test that passing a string to the 'substrs' argument is rejected.
27+
self.assert_expect_fails_with("settings list prompt",
28+
dict(substrs="some substring"),
29+
"substrs must be a collection of strings")

0 commit comments

Comments
 (0)