7 from .lldbtest
import *
9 from lldbsuite
.test
.decorators
import *
13 @add_test_categories(["pexpect"])
14 class PExpectTest(TestBase
):
15 NO_DEBUG_INFO_TESTCASE
= True
18 def expect_prompt(self
):
19 self
.child
.expect_exact(self
.PROMPT
)
32 # Using a log file is incompatible with using utf-8 as the encoding.
34 getattr(sys
.stdout
, "buffer", sys
.stdout
)
35 if (self
.TraceOn() and not encoding
)
40 if run_under
is not None:
42 args
+= [lldbtest_config
.lldbExec
, "--no-lldbinit"]
44 args
.append("--no-use-colors")
45 for cmd
in self
.setUpCommands():
46 if "use-color false" in cmd
and use_colors
:
49 if executable
is not None:
50 args
+= ["--file", executable
]
51 if extra_args
is not None:
52 args
.extend(extra_args
)
54 env
= dict(os
.environ
)
56 env
["HOME"] = self
.getBuildDir()
60 self
.child
= pexpect
.spawn(
65 dimensions
=dimensions
,
69 self
.child
.ptyproc
.delayafterclose
= timeout
/ 10
70 self
.child
.ptyproc
.delayafterterminate
= timeout
/ 10
72 if post_spawn
is not None:
75 for cmd
in self
.setUpCommands():
76 if "use-color false" in cmd
and use_colors
:
78 self
.child
.expect_exact(cmd
)
80 if executable
is not None:
81 self
.child
.expect_exact("target create")
82 self
.child
.expect_exact("Current executable set to")
85 def expect(self
, cmd
, substrs
=None):
86 self
.assertNotIn("\n", cmd
)
87 # If 'substrs' is a string then this code would just check that every
88 # character of the string is in the output.
89 assert not isinstance(substrs
, str), "substrs must be a collection of strings"
91 self
.child
.sendline(cmd
)
92 if substrs
is not None:
94 self
.child
.expect_exact(s
)
97 def quit(self
, gracefully
=True):
99 self
.child
.close(force
=not gracefully
)
102 def cursor_forward_escape_seq(self
, chars_to_move
):
104 Returns the escape sequence to move the cursor forward/right
105 by a certain amount of characters.
107 return b
"\x1b\[" + str(chars_to_move
).encode("utf-8") + b
"C"