-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Revert "[llvm-lit] Process ANSI color codes in test output when formatting" #108104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…tting (#…" This reverts commit 0f56ba1.
@llvm/pr-subscribers-testing-tools Author: Henrik G. Olsson (hnrklssn) ChangesReverts llvm/llvm-project#106776 because of a test failure on Windows. Full diff: https://github.com/llvm/llvm-project/pull/108104.diff 5 Files Affected:
diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py
index a2c76d41a43e07..19f35fc7e212f3 100644
--- a/llvm/utils/lit/lit/TestRunner.py
+++ b/llvm/utils/lit/lit/TestRunner.py
@@ -1017,20 +1017,6 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
return exitCode
-def findColor(line, curr_color):
- start = line.rfind("\33[")
- if start == -1:
- return curr_color
- end = line.find("m", start+2)
- if end == -1:
- return curr_color
- match = line[start:end+1]
- # "\33[0m" means "reset all formatting". Sometimes the 0 is skipped.
- if match == "\33[m" or match == "\33[0m":
- return None
- return match
-
-
def formatOutput(title, data, limit=None):
if not data.strip():
return ""
@@ -1041,18 +1027,8 @@ def formatOutput(title, data, limit=None):
msg = ""
ndashes = 30
# fmt: off
- out = f"# .---{title}{'-' * (ndashes - 4 - len(title))}\n"
- curr_color = None
- for line in data.splitlines():
- if curr_color:
- out += "\33[0m"
- out += "# | "
- if curr_color:
- out += curr_color
- out += line + "\n"
- curr_color = findColor(line, curr_color)
- if curr_color:
- out += "\33[0m" # prevent unterminated formatting from leaking
+ out = f"# .---{title}{'-' * (ndashes - 4 - len(title))}\n"
+ out += f"# | " + "\n# | ".join(data.splitlines()) + "\n"
out += f"# `---{msg}{'-' * (ndashes - 4 - len(msg))}\n"
# fmt: on
return out
diff --git a/llvm/utils/lit/tests/Inputs/escape-color/color-escaped.txt b/llvm/utils/lit/tests/Inputs/escape-color/color-escaped.txt
deleted file mode 100644
index e7a33e380b351c..00000000000000
--- a/llvm/utils/lit/tests/Inputs/escape-color/color-escaped.txt
+++ /dev/null
@@ -1,10 +0,0 @@
-# .---command stdout------------
-# | # RUN: cat %s
-# | �[31mred
-�[0m# | �[31mstill red�(B�[m
-# | plain
-# | �[32mgreen
-�[0m# | �[32mstill green (never terminated)
-�[0m# `-----------------------------
-
---
diff --git a/llvm/utils/lit/tests/Inputs/escape-color/color.txt b/llvm/utils/lit/tests/Inputs/escape-color/color.txt
deleted file mode 100644
index 15ffc22d134f0f..00000000000000
--- a/llvm/utils/lit/tests/Inputs/escape-color/color.txt
+++ /dev/null
@@ -1,6 +0,0 @@
-# RUN: cat %s
-�[31mred
-still red�(B�[m
-plain
-�[32mgreen
-still green (never terminated)
diff --git a/llvm/utils/lit/tests/Inputs/escape-color/lit.cfg b/llvm/utils/lit/tests/Inputs/escape-color/lit.cfg
deleted file mode 100644
index 36f4eb69d4858e..00000000000000
--- a/llvm/utils/lit/tests/Inputs/escape-color/lit.cfg
+++ /dev/null
@@ -1,8 +0,0 @@
-import lit.formats
-
-config.name = "escape-color"
-config.suffixes = [".txt"]
-config.test_format = lit.formats.ShTest()
-config.test_source_root = None
-config.test_exec_root = None
-
diff --git a/llvm/utils/lit/tests/escape-color.py b/llvm/utils/lit/tests/escape-color.py
deleted file mode 100644
index 1d0b93b004e9da..00000000000000
--- a/llvm/utils/lit/tests/escape-color.py
+++ /dev/null
@@ -1,4 +0,0 @@
-# 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
|
hnrklssn
added a commit
to hnrklssn/llvm-project
that referenced
this pull request
Sep 10, 2024
…tting" (llvm#108104)" This recommits 0f56ba1 (reverted by 6007ad7). In the original patch llvm/utils/lit/tests/escape-color.py failed on Windows because it diffed llvm-lit output with a file containing '\n' newlines rather than '\r\n'. This issue is avoided by calling 'diff --strip-trailing-cr'. Original description below: Test output that carried color across newlines previously resulted in the formatting around the output also being colored. Detect the current ANSI color and reset it when printing formatting, and then reapply it. As an added bonus an unterminated color code is also detected, preventing it from leaking out into the rest of the terminal. Fixes llvm#106633
hnrklssn
added a commit
that referenced
this pull request
Sep 11, 2024
#108107) …tting" (#108104)" This recommits 0f56ba1 (reverted by 6007ad7). In the original patch llvm/utils/lit/tests/escape-color.py failed on Windows because it diffed llvm-lit output with a file containing '\n' newlines rather than '\r\n'. This issue is avoided by calling 'diff --strip-trailing-cr'. Original description below: Test output that carried color across newlines previously resulted in the formatting around the output also being colored. Detect the current ANSI color and reset it when printing formatting, and then reapply it. As an added bonus an unterminated color code is also detected, preventing it from leaking out into the rest of the terminal. Fixes #106633
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Reverts #106776 because of a test failure on Windows.