[llvm] [llvm-lit] Process ANSI color codes in test output when formatting (PR #106776)

Alexander Richardson via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 6 15:14:19 PDT 2024


================
@@ -1005,6 +1005,44 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
     return exitCode
 
 
+def reFindLast(r, s):
+    matches = r.findall(s)
+    if not matches:
+        return None
+    return matches[-1]
+
+
+def findColor(s, curr_color):
+    m = reFindLast(color_re, s)
+    if not m:
+        return curr_color
+    # "\33[0m" means "reset all formatting". Sometimes the 0 is skipped.
+    if m == "\33[m" or m == "\33[0m":
+        return None
+    return m
+
+
+def escapeColor(s, f):
----------------
arichardson wrote:

These short variable names make it hard to figure out what the function really does without parsing it. I'd suggest using more descriptive names and possibly also type hints now that we no longer support old python versions.

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


More information about the llvm-commits mailing list