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

Jordan Rupprecht via lldb-commits lldb-commits at lists.llvm.org
Tue Nov 19 15:18:07 PST 2019


Author: Jordan Rupprecht
Date: 2019-11-19T15:17:35-08:00
New Revision: 327a18ca0a000e4f99d02d0042ca2106db635a68

URL: https://github.com/llvm/llvm-project/commit/327a18ca0a000e4f99d02d0042ca2106db635a68
DIFF: https://github.com/llvm/llvm-project/commit/327a18ca0a000e4f99d02d0042ca2106db635a68.diff

LOG: [lldb][test] Prevent \n in calls to lldb's expect() test helper.

Summary:
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.

Reviewers: labath

Reviewed By: labath

Subscribers: merge_guards_bot, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D70324

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/lldb/packages/Python/lldbsuite/test/lldbpexpect.py b/lldb/packages/Python/lldbsuite/test/lldbpexpect.py
index 402148a9534f..ef60eadba319 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbpexpect.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbpexpect.py
@@ -50,6 +50,7 @@ def launch(self, executable=None, extra_args=None, timeout=30, dimensions=None):
                 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:

diff  --git a/lldb/packages/Python/lldbsuite/test/terminal/TestEditline.py b/lldb/packages/Python/lldbsuite/test/terminal/TestEditline.py
index 49a46f2de539..df622820028b 100644
--- a/lldb/packages/Python/lldbsuite/test/terminal/TestEditline.py
+++ b/lldb/packages/Python/lldbsuite/test/terminal/TestEditline.py
@@ -24,26 +24,23 @@ def test_left_right_arrow(self):
         "help command" while exercising word-navigation, so type it as below,
         where [] indicates cursor position.
 
-        1. Send "el ommand" -> "el ommand[]"
-        2. Ctrl+left once   -> "el []ommand"
-        3. Send "c"         -> "el c[]ommand"
-        4. Ctrl+left twice  -> "[]el command"
-        5. Send "h"         -> "h[]el command"
-        6. Ctrl+right       -> "hel[] command"
-        7. Send "p"         -> "help command"
+        1. Send "el rint"  -> "el rint[]"
+        2. Ctrl+left once  -> "el []rint"
+        3. Send "p"        -> "el p[]rint"
+        4. Ctrl+left twice -> "[]el print"
+        5. Send "h"        -> "h[]el print"
+        6. Ctrl+right      -> "hel[] print"
+        7. Send "p"        -> "help print"
         """
         self.launch()
 
-        # Run help for 
diff erent 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()


        


More information about the lldb-commits mailing list