[llvm] [llvm-lit] Fix `TypeError` string argument expected in lit's internal shell (PR #105925)

via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 23 22:46:58 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-testing-tools

Author: None (Harini0924)

<details>
<summary>Changes</summary>

This patch addresses an issue encountered when running the BOLT test suite with the lit internal shell using the command: 
```
LIT_USE_INTERNAL_SHELL=1 ninja check-bolt
```
During execution, the following error was observed:
```
File "/usr/local/google/home/harinidonthula/llvm-project/llvm/utils/lit/lit/TestRunner.py", line 416, in executeBuiltinEcho
    stdout.write(encode(maybeUnescape(args[-1])))
TypeError: string argument expected, got 'GlobItem'
```
This error occurs because the `executeBuiltinEcho` function in the lit testing framework expects a string to be passed to `stdout.write`, but it received a `GlobItem` object instead. The `GlobItem` represents an unexpanded glob pattern that needs to be converted to a string before being processed.

This patch adds `str()` to the arguments passed to `stdout.write` in the `executeBuiltinEcho` function. By converting the arguments to strings, including any `GlobItem` objects, we ensure compatibility and prevent the `TypeError` during test execution.

This change is relevant for [[RFC] Enabling the Lit Internal Shell by Default](https://discourse.llvm.org/t/rfc-enabling-the-lit-internal-shell-by-default/80179/3)  
fixes: #<!-- -->102693

---
Full diff: https://github.com/llvm/llvm-project/pull/105925.diff


1 Files Affected:

- (modified) llvm/utils/lit/lit/TestRunner.py (+1-1) 


``````````diff
diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py
index 2d9af9fbbb3634..625ce009515d5f 100644
--- a/llvm/utils/lit/lit/TestRunner.py
+++ b/llvm/utils/lit/lit/TestRunner.py
@@ -413,7 +413,7 @@ def maybeUnescape(arg):
         for arg in args[:-1]:
             stdout.write(encode(maybeUnescape(arg)))
             stdout.write(encode(" "))
-        stdout.write(encode(maybeUnescape(args[-1])))
+        stdout.write(encode(maybeUnescape(str(args[-1]))))
     if write_newline:
         stdout.write(encode("\n"))
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/105925


More information about the llvm-commits mailing list