[Lldb-commits] [lldb] b5277b1 - [lldb][test] Print command output when it unexpectedly passes (#224021)

via lldb-commits lldb-commits at lists.llvm.org
Thu Sep 17 04:06:41 PDT 2026


Author: Raphael Isemann
Date: 2026-09-17T12:06:36+01:00
New Revision: b5277b196f75cdb845290667b7f923f01055584d

URL: https://github.com/llvm/llvm-project/commit/b5277b196f75cdb845290667b7f923f01055584d
DIFF: https://github.com/llvm/llvm-project/commit/b5277b196f75cdb845290667b7f923f01055584d.diff

LOG: [lldb][test] Print command output when it unexpectedly passes (#224021)

Some LLDB tests expect commands to fail. However, we do sometimes see
these commands actually pass on the bots and the test output doesn't
really indicate what is going on.

This patch adds the (error) output of commands that we expected to fail
but didn't do the test output. This changes the dreaded `Command 'foo'
is expected to fail!` error to:

```
Command 'foo' is expected to fail!
Output: bar
```

Added: 
    

Modified: 
    lldb/packages/Python/lldbsuite/test/lldbtest.py

Removed: 
    


################################################################################
diff  --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py b/lldb/packages/Python/lldbsuite/test/lldbtest.py
index bec50f806110b..7f5f30472ceba 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -2529,6 +2529,20 @@ def switch_to_thread_with_stop_reason(self, stop_reason):
             if matched:
                 self.runCmd("thread select %s" % matched.group(1))
 
+    def _assert_command_failed(self, command, res):
+        fail_msg = "Command '" + command + "' is expected to fail!"
+        output = res.GetOutput()
+        error = res.GetError()
+        if output:
+            fail_msg += "\nOutput: " + output
+        if error:
+            # If output is very long, add a dividing marker before printing the
+            # error message.
+            if output and len(output.splitlines()) > 10:
+                fail_msg += "\n" + "-" * 80
+            fail_msg += "\nError: " + error
+        self.assertFalse(res.Succeeded(), fail_msg)
+
     def match(
         self, str, patterns, msg=None, trace=False, error=False, matching=True, exe=True
     ):
@@ -2550,9 +2564,7 @@ def match(
 
             # If error is True, the API client expects the command to fail!
             if error:
-                self.assertFalse(
-                    self.res.Succeeded(), "Command '" + str + "' is expected to fail!"
-                )
+                self._assert_command_failed(str, self.res)
         else:
             # No execution required, just compare str against the golden input.
             output = str
@@ -2887,10 +2899,7 @@ def expect(
 
             # If error is True, the API client expects the command to fail!
             if error:
-                self.assertFalse(
-                    self.res.Succeeded(),
-                    "Command '" + string + "' is expected to fail!",
-                )
+                self._assert_command_failed(string, self.res)
         else:
             # No execution required, just compare string against the golden input.
             if isinstance(string, lldb.SBCommandReturnObject):


        


More information about the lldb-commits mailing list