summaryrefslogtreecommitdiffstats
path: root/lldb/packages/Python/lldbsuite/test/python_api/file_handle
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test/python_api/file_handle')
-rw-r--r--lldb/packages/Python/lldbsuite/test/python_api/file_handle/TestFileHandle.py35
1 files changed, 34 insertions, 1 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/python_api/file_handle/TestFileHandle.py b/lldb/packages/Python/lldbsuite/test/python_api/file_handle/TestFileHandle.py
index 577c6b3e88f..1bd002e6bb7 100644
--- a/lldb/packages/Python/lldbsuite/test/python_api/file_handle/TestFileHandle.py
+++ b/lldb/packages/Python/lldbsuite/test/python_api/file_handle/TestFileHandle.py
@@ -772,7 +772,21 @@ class FileHandleTestCase(lldbtest.TestBase):
@add_test_categories(['pyapi'])
- @expectedFailureAll() # FIXME implement SBFile::GetFile
+ def test_stdout_file(self):
+ with open(self.out_filename, 'w') as f:
+ status = self.debugger.SetOutputFile(f)
+ self.assertTrue(status.Success())
+ self.handleCmd(r"script sys.stdout.write('foobar\n')")
+ with open(self.out_filename, 'r') as f:
+ # In python2 sys.stdout.write() returns None, which
+ # the REPL will ignore, but in python3 it will
+ # return the number of bytes written, which the REPL
+ # will print out.
+ lines = [x for x in f.read().strip().split() if x != "7"]
+ self.assertEqual(lines, ["foobar"])
+
+
+ @add_test_categories(['pyapi'])
@skipIf(py_version=['<', (3,)])
def test_identity(self):
@@ -826,3 +840,22 @@ class FileHandleTestCase(lldbtest.TestBase):
with open(self.out_filename, 'r') as f:
self.assertEqual("foobar", f.read().strip())
+
+
+ @add_test_categories(['pyapi'])
+ def test_back_and_forth(self):
+ with open(self.out_filename, 'w') as f:
+ # at each step here we're borrowing the file, so we have to keep
+ # them all alive until the end.
+ sbf = lldb.SBFile.Create(f, borrow=True)
+ def i(sbf):
+ for i in range(10):
+ f = sbf.GetFile()
+ yield f
+ sbf = lldb.SBFile.Create(f, borrow=True)
+ yield sbf
+ sbf.Write(str(i).encode('ascii') + b"\n")
+ files = list(i(sbf))
+ with open(self.out_filename, 'r') as f:
+ self.assertEqual(list(range(10)), list(map(int, f.read().strip().split())))
+
OpenPOWER on IntegriCloud