diff options
| author | Jonas Devlieghere <jonas@devlieghere.com> | 2025-11-14 14:43:01 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-11-14 22:43:01 +0000 |
| commit | 6dad2c2cfb9255bb8b4fec3565f99ffda32dfb1a (patch) | |
| tree | b099ac769a4d65a74a4aeca9af333f2ae5ccd086 /lldb/test/API/python_api | |
| parent | 825ebef51ad83492698cd8ac59c12375fc25636b (diff) | |
| download | llvm-6dad2c2cfb9255bb8b4fec3565f99ffda32dfb1a.zip llvm-6dad2c2cfb9255bb8b4fec3565f99ffda32dfb1a.tar.gz llvm-6dad2c2cfb9255bb8b4fec3565f99ffda32dfb1a.tar.bz2 | |
[lldb] Add a test for capturing stdout/stderr from Python commands (#168138)
Diffstat (limited to 'lldb/test/API/python_api')
| -rw-r--r-- | lldb/test/API/python_api/command_script_output/TestCommandScriptOutput.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/lldb/test/API/python_api/command_script_output/TestCommandScriptOutput.py b/lldb/test/API/python_api/command_script_output/TestCommandScriptOutput.py new file mode 100644 index 0000000..abe0eec --- /dev/null +++ b/lldb/test/API/python_api/command_script_output/TestCommandScriptOutput.py @@ -0,0 +1,47 @@ +""" +Test that HandleCommand captures stdout and stderr from script commands. +""" + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * + + +class CommandScriptOutputTestCase(TestBase): + NO_DEBUG_INFO_TESTCASE = True + + def test_script_command_stdout_stderr(self): + """Test that HandleCommand captures stdout and stderr from script commands.""" + ci = self.dbg.GetCommandInterpreter() + self.assertTrue(ci, VALID_COMMAND_INTERPRETER) + + res = lldb.SBCommandReturnObject() + + # Execute a script command that writes to stdout. + ci.HandleCommand("script print('Hello stdout')", res) + self.assertTrue(res.Succeeded()) + self.assertIn("Hello stdout", res.GetOutput()) + + # Execute a script command that writes to stderr. + ci.HandleCommand("script import sys; sys.stderr.write('Hello stderr\\n')", res) + self.assertTrue(res.Succeeded()) + self.assertIn("Hello stderr", res.GetOutput()) + + # Execute a script command that writes to both stdout and stderr. + ci.HandleCommand( + "script import sys; print('Output line'); sys.stderr.write('Error line\\n')", + res, + ) + self.assertTrue(res.Succeeded()) + self.assertIn("Output line", res.GetOutput()) + self.assertIn("Error line", res.GetOutput()) + + # Test that multiple print statements are captured. + ci.HandleCommand( + "script print('Line 1'); print('Line 2'); print('Line 3')", res + ) + self.assertTrue(res.Succeeded()) + output = res.GetOutput() + self.assertIn("Line 1", output) + self.assertIn("Line 2", output) + self.assertIn("Line 3", output) |
