Skip to content

Commit e5e05ec

Browse files
committed
[lldb/test] Use @skipIfWindows for PExpectTest
Annotating `PExpectTest` with `@skipIfWindows` instead of marking it as an empty class will make the test runner recognize it as a test class, which should allow me to reland adb5c23. I don't have a windows machine to verify this works, but I did some tests using `@skipIfLinux` and they all worked as expected. In case the `pexpect` import is not at all available on windows, I moved it to within the method where it's used. Reviewed By: labath Differential Revision: https://reviews.llvm.org/D86745
1 parent 73f4317 commit e5e05ec

File tree

1 file changed

+47
-52
lines changed

1 file changed

+47
-52
lines changed

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

Lines changed: 47 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -13,65 +13,60 @@
1313
from . import lldbutil
1414
from lldbsuite.test.decorators import *
1515

16-
if sys.platform.startswith('win32'):
17-
# llvm.org/pr22274: need a pexpect replacement for windows
18-
class PExpectTest(object):
19-
pass
20-
else:
21-
import pexpect
16+
@skipIfRemote
17+
@skipIfWindows # llvm.org/pr22274: need a pexpect replacement for windows
18+
class PExpectTest(TestBase):
2219

23-
@skipIfRemote
24-
class PExpectTest(TestBase):
20+
NO_DEBUG_INFO_TESTCASE = True
21+
PROMPT = "(lldb) "
2522

26-
NO_DEBUG_INFO_TESTCASE = True
27-
PROMPT = "(lldb) "
23+
def expect_prompt(self):
24+
self.child.expect_exact(self.PROMPT)
2825

29-
def expect_prompt(self):
30-
self.child.expect_exact(self.PROMPT)
26+
def launch(self, executable=None, extra_args=None, timeout=30, dimensions=None):
27+
logfile = getattr(sys.stdout, 'buffer',
28+
sys.stdout) if self.TraceOn() else None
3129

32-
def launch(self, executable=None, extra_args=None, timeout=30, dimensions=None):
33-
logfile = getattr(sys.stdout, 'buffer',
34-
sys.stdout) if self.TraceOn() else None
30+
args = ['--no-lldbinit', '--no-use-colors']
31+
for cmd in self.setUpCommands():
32+
args += ['-O', cmd]
33+
if executable is not None:
34+
args += ['--file', executable]
35+
if extra_args is not None:
36+
args.extend(extra_args)
3537

36-
args = ['--no-lldbinit', '--no-use-colors']
37-
for cmd in self.setUpCommands():
38-
args += ['-O', cmd]
39-
if executable is not None:
40-
args += ['--file', executable]
41-
if extra_args is not None:
42-
args.extend(extra_args)
38+
env = dict(os.environ)
39+
env["TERM"]="vt100"
4340

44-
env = dict(os.environ)
45-
env["TERM"]="vt100"
46-
47-
self.child = pexpect.spawn(
48-
lldbtest_config.lldbExec, args=args, logfile=logfile,
49-
timeout=timeout, dimensions=dimensions, env=env)
41+
import pexpect
42+
self.child = pexpect.spawn(
43+
lldbtest_config.lldbExec, args=args, logfile=logfile,
44+
timeout=timeout, dimensions=dimensions, env=env)
45+
self.expect_prompt()
46+
for cmd in self.setUpCommands():
47+
self.child.expect_exact(cmd)
5048
self.expect_prompt()
51-
for cmd in self.setUpCommands():
52-
self.child.expect_exact(cmd)
53-
self.expect_prompt()
54-
if executable is not None:
55-
self.child.expect_exact("target create")
56-
self.child.expect_exact("Current executable set to")
57-
self.expect_prompt()
58-
59-
def expect(self, cmd, substrs=None):
60-
self.assertNotIn('\n', cmd)
61-
self.child.sendline(cmd)
62-
if substrs is not None:
63-
for s in substrs:
64-
self.child.expect_exact(s)
49+
if executable is not None:
50+
self.child.expect_exact("target create")
51+
self.child.expect_exact("Current executable set to")
6552
self.expect_prompt()
6653

67-
def quit(self, gracefully=True):
68-
self.child.sendeof()
69-
self.child.close(force=not gracefully)
70-
self.child = None
54+
def expect(self, cmd, substrs=None):
55+
self.assertNotIn('\n', cmd)
56+
self.child.sendline(cmd)
57+
if substrs is not None:
58+
for s in substrs:
59+
self.child.expect_exact(s)
60+
self.expect_prompt()
61+
62+
def quit(self, gracefully=True):
63+
self.child.sendeof()
64+
self.child.close(force=not gracefully)
65+
self.child = None
7166

72-
def cursor_forward_escape_seq(self, chars_to_move):
73-
"""
74-
Returns the escape sequence to move the cursor forward/right
75-
by a certain amount of characters.
76-
"""
77-
return b"\x1b\[" + str(chars_to_move).encode("utf-8") + b"C"
67+
def cursor_forward_escape_seq(self, chars_to_move):
68+
"""
69+
Returns the escape sequence to move the cursor forward/right
70+
by a certain amount of characters.
71+
"""
72+
return b"\x1b\[" + str(chars_to_move).encode("utf-8") + b"C"

0 commit comments

Comments
 (0)