brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.7 KiB · abe0eec Raw
48 lines · python
1"""2Test that HandleCommand captures stdout and stderr from script commands.3"""4 5import lldb6from lldbsuite.test.decorators import *7from lldbsuite.test.lldbtest import *8 9 10class CommandScriptOutputTestCase(TestBase):11    NO_DEBUG_INFO_TESTCASE = True12 13    def test_script_command_stdout_stderr(self):14        """Test that HandleCommand captures stdout and stderr from script commands."""15        ci = self.dbg.GetCommandInterpreter()16        self.assertTrue(ci, VALID_COMMAND_INTERPRETER)17 18        res = lldb.SBCommandReturnObject()19 20        # Execute a script command that writes to stdout.21        ci.HandleCommand("script print('Hello stdout')", res)22        self.assertTrue(res.Succeeded())23        self.assertIn("Hello stdout", res.GetOutput())24 25        # Execute a script command that writes to stderr.26        ci.HandleCommand("script import sys; sys.stderr.write('Hello stderr\\n')", res)27        self.assertTrue(res.Succeeded())28        self.assertIn("Hello stderr", res.GetOutput())29 30        # Execute a script command that writes to both stdout and stderr.31        ci.HandleCommand(32            "script import sys; print('Output line'); sys.stderr.write('Error line\\n')",33            res,34        )35        self.assertTrue(res.Succeeded())36        self.assertIn("Output line", res.GetOutput())37        self.assertIn("Error line", res.GetOutput())38 39        # Test that multiple print statements are captured.40        ci.HandleCommand(41            "script print('Line 1'); print('Line 2'); print('Line 3')", res42        )43        self.assertTrue(res.Succeeded())44        output = res.GetOutput()45        self.assertIn("Line 1", output)46        self.assertIn("Line 2", output)47        self.assertIn("Line 3", output)48