[PATCH] D65739: [API] Have SBCommandReturnObject::GetOutput/Error return "" instead of nullptr

Pavel Labath via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 14 01:13:28 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL368806: [API] Have SBCommandReturnObject::GetOutput/Error return "" instead of nullptr (authored by labath, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65739/new/

https://reviews.llvm.org/D65739

Files:
  lldb/trunk/packages/Python/lldbsuite/test/lldbtest.py
  lldb/trunk/packages/Python/lldbsuite/test/python_api/interpreter/TestCommandInterpreterAPI.py
  lldb/trunk/source/API/SBCommandReturnObject.cpp


Index: lldb/trunk/packages/Python/lldbsuite/test/python_api/interpreter/TestCommandInterpreterAPI.py
===================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/python_api/interpreter/TestCommandInterpreterAPI.py
+++ lldb/trunk/packages/Python/lldbsuite/test/python_api/interpreter/TestCommandInterpreterAPI.py
@@ -12,6 +12,7 @@
 class CommandInterpreterAPICase(TestBase):
 
     mydir = TestBase.compute_mydir(__file__)
+    NO_DEBUG_INFO_TESTCASE = True
 
     def setUp(self):
         # Call super's setUp().
@@ -72,3 +73,19 @@
 
         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(), "")
Index: lldb/trunk/packages/Python/lldbsuite/test/lldbtest.py
===================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lldbtest.py
+++ lldb/trunk/packages/Python/lldbsuite/test/lldbtest.py
@@ -2318,8 +2318,6 @@
             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"
 
Index: lldb/trunk/source/API/SBCommandReturnObject.cpp
===================================================================
--- lldb/trunk/source/API/SBCommandReturnObject.cpp
+++ lldb/trunk/source/API/SBCommandReturnObject.cpp
@@ -72,10 +72,8 @@
   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 @@
   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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65739.215037.patch
Type: text/x-patch
Size: 2949 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190814/e9f83674/attachment.bin>


More information about the llvm-commits mailing list