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

Raphael Isemann via lldb-commits lldb-commits at lists.llvm.org
Wed Sep 16 06:51:08 PDT 2026


https://github.com/Teemperor created https://github.com/llvm/llvm-project/pull/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
```

>From 542ac402786aa101d7e0ef26dc56039cf61493d5 Mon Sep 17 00:00:00 2001
From: Raphael Isemann <rise at apple.com>
Date: Wed, 16 Sep 2026 14:42:27 +0100
Subject: [PATCH] [lldb][test] Print command output when it unexpectedly passes

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
```
---
 lldb/packages/Python/lldbsuite/test/lldbtest.py | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py b/lldb/packages/Python/lldbsuite/test/lldbtest.py
index bec50f806110b..16d224d01fc2b 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -2529,6 +2529,14 @@ 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!"
+        if res.GetOutput():
+            fail_msg += "\nOutput: " + res.GetOutput()
+        if res.GetError():
+            fail_msg += "\nError: " + res.GetError()
+        self.assertFalse(res.Succeeded(), fail_msg)
+
     def match(
         self, str, patterns, msg=None, trace=False, error=False, matching=True, exe=True
     ):
@@ -2550,9 +2558,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 +2893,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