[llvm] [llvm-lit] Process ANSI color codes in test output when formatting (PR #106776)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 30 11:35:33 PDT 2024
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {darker}-->
:warning: Python code formatter, darker found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
darker --check --diff -r 9e1f1cfa59c4513798de5c326d77e1e5912b1634...e8733617420b4d67133cbd23312afa0d5639220e llvm/utils/lit/tests/escape-color.py llvm/utils/lit/lit/TestRunner.py
``````````
</details>
<details>
<summary>
View the diff from darker here.
</summary>
``````````diff
--- lit/TestRunner.py 2024-08-30 18:23:28.000000 +0000
+++ lit/TestRunner.py 2024-08-30 18:35:07.802931 +0000
@@ -1002,40 +1002,46 @@
if cmd.negate:
exitCode = not exitCode
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):
if not f:
return s
return f"\33[0m{s}{f}"
+
color_re = re.compile("\33\\[[^m]*m")
+
+
def formatLines(lines):
curr_color = None
out = ""
for line in lines:
out += escapeColor("# | ", curr_color)
out += line + "\n"
curr_color = findColor(line, curr_color)
if curr_color:
- out += "\33[0m" # prevent unterminated formatting from leaking
+ out += "\33[0m" # prevent unterminated formatting from leaking
return out
def formatOutput(title, data, limit=None):
if not data.strip():
return ""
--- tests/escape-color.py 2024-08-30 18:23:28.000000 +0000
+++ tests/escape-color.py 2024-08-30 18:35:07.851271 +0000
@@ -1,5 +1,4 @@
# cut off the first 9 lines to avoid absolute file paths in the output
# then keep only the next 10 lines to avoid test timing in the output
# RUN: %{lit} %{inputs}/escape-color/color.txt -a | tail -n +10 | head -n 10 > %t
# RUN: diff %{inputs}/escape-color/color-escaped.txt %t
-
``````````
</details>
https://github.com/llvm/llvm-project/pull/106776
More information about the llvm-commits
mailing list