[Lldb-commits] [PATCH] D70324: [lldb][test] Prevent \n in calls to lldb's expect() test helper.

Jordan Rupprecht via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Fri Nov 15 10:41:26 PST 2019


rupprecht created this revision.
rupprecht added a reviewer: labath.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

expect() forwards its command to sendline(). This can be problematic if the command already contains a newline: sendline() unconditionally adds a newline to the command, which causes the command to run twice (hitting enter in lldb runs the previous command). The expect() helper looks for the prompt and finds the first one, but because the command has run a second time, the buffer will contain the contents of the second time the command ran, causing potential erroneous matching.

Simplify the editline test, which was using different commands to workaround this misunderstanding.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70324

Files:
  lldb/packages/Python/lldbsuite/test/lldbpexpect.py
  lldb/packages/Python/lldbsuite/test/terminal/TestEditline.py


Index: lldb/packages/Python/lldbsuite/test/terminal/TestEditline.py
===================================================================
--- lldb/packages/Python/lldbsuite/test/terminal/TestEditline.py
+++ lldb/packages/Python/lldbsuite/test/terminal/TestEditline.py
@@ -34,16 +34,13 @@
         """
         self.launch()
 
-        # Run help for different commands for escape variants to make sure each
-        # one matches uniquely (the buffer isn't cleared in between matches).
-        cases = [
-            ("print", "\x1b[1;5D", "\x1b[1;5C"),
-            ("step", "\x1b[5D", "\x1b[5C"),
-            ("exit", "\x1b\x1b[D", "\x1b\x1b[C"),
+        escape_pairs = [
+            ("\x1b[1;5D", "\x1b[1;5C"),
+            ("\x1b[5D", "\x1b[5C"),
+            ("\x1b\x1b[D", "\x1b\x1b[C"),
         ]
-        for (cmd, l_escape, r_escape) in cases:
-            self.expect("el {cmd_tail}{L}{cmd_head}{L}{L}h{R}p".format(
-                cmd_head=cmd[0], cmd_tail=cmd[1:], L=l_escape, R=r_escape),
-                substrs=["Syntax: %s" % cmd])
+        for (l_escape, r_escape) in escape_pairs:
+            self.expect("el rint{L}p{L}{L}h{R}p".format(
+                L=l_escape, R=r_escape), substrs=["Syntax: print"])
 
         self.quit()
Index: lldb/packages/Python/lldbsuite/test/lldbpexpect.py
===================================================================
--- lldb/packages/Python/lldbsuite/test/lldbpexpect.py
+++ lldb/packages/Python/lldbsuite/test/lldbpexpect.py
@@ -50,6 +50,7 @@
                 self.expect_prompt()
 
         def expect(self, cmd, substrs=None):
+            self.assertNotIn('\n', cmd)
             self.child.sendline(cmd)
             if substrs is not None:
                 for s in substrs:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70324.229593.patch
Type: text/x-patch
Size: 1745 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20191115/db0ea36b/attachment-0001.bin>


More information about the lldb-commits mailing list