diff --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py b/lldb/packages/Python/lldbsuite/test/lldbtest.py index adbd0ec369b7..dd4651c9eff7 100644 --- a/lldb/packages/Python/lldbsuite/test/lldbtest.py +++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py @@ -2318,8 +2318,6 @@ FileCheck output: with recording(self, trace) as sbuf: print("looking at:", output, file=sbuf) - if output is None: - output = "" # The heading says either "Expecting" or "Not expecting". heading = "Expecting" if matching else "Not expecting" diff --git a/lldb/packages/Python/lldbsuite/test/python_api/interpreter/TestCommandInterpreterAPI.py b/lldb/packages/Python/lldbsuite/test/python_api/interpreter/TestCommandInterpreterAPI.py index 7703d20ed416..a920ce845b82 100644 --- a/lldb/packages/Python/lldbsuite/test/python_api/interpreter/TestCommandInterpreterAPI.py +++ b/lldb/packages/Python/lldbsuite/test/python_api/interpreter/TestCommandInterpreterAPI.py @@ -12,6 +12,7 @@ from lldbsuite.test import lldbutil class CommandInterpreterAPICase(TestBase): mydir = TestBase.compute_mydir(__file__) + NO_DEBUG_INFO_TESTCASE = True def setUp(self): # Call super's setUp(). @@ -72,3 +73,19 @@ class CommandInterpreterAPICase(TestBase): if self.TraceOn(): lldbutil.print_stacktraces(process) + + @add_test_categories(['pyapi']) + def test_command_output(self): + """Test command output handling.""" + ci = self.dbg.GetCommandInterpreter() + self.assertTrue(ci, VALID_COMMAND_INTERPRETER) + + # Test that a command which produces no output returns "" instead of + # None. + res = lldb.SBCommandReturnObject() + ci.HandleCommand("settings set use-color false", res) + self.assertTrue(res.Succeeded()) + self.assertIsNotNone(res.GetOutput()) + self.assertEquals(res.GetOutput(), "") + self.assertIsNotNone(res.GetError()) + self.assertEquals(res.GetError(), "") diff --git a/lldb/source/API/SBCommandReturnObject.cpp b/lldb/source/API/SBCommandReturnObject.cpp index 94e89916f7f6..58740eeaade5 100644 --- a/lldb/source/API/SBCommandReturnObject.cpp +++ b/lldb/source/API/SBCommandReturnObject.cpp @@ -72,10 +72,8 @@ const char *SBCommandReturnObject::GetOutput() { LLDB_RECORD_METHOD_NO_ARGS(const char *, SBCommandReturnObject, GetOutput); if (m_opaque_up) { - llvm::StringRef output = m_opaque_up->GetOutputData(); - ConstString result(output.empty() ? llvm::StringRef("") : output); - - return result.AsCString(); + ConstString output(m_opaque_up->GetOutputData()); + return output.AsCString(/*value_if_empty*/ ""); } return nullptr; @@ -85,9 +83,8 @@ const char *SBCommandReturnObject::GetError() { LLDB_RECORD_METHOD_NO_ARGS(const char *, SBCommandReturnObject, GetError); if (m_opaque_up) { - llvm::StringRef output = m_opaque_up->GetErrorData(); - ConstString result(output.empty() ? llvm::StringRef("") : output); - return result.AsCString(); + ConstString output(m_opaque_up->GetErrorData()); + return output.AsCString(/*value_if_empty*/ ""); } return nullptr;