Skip to content

[lit] Read stdin for a "-" operand in builtin cat - #240060

Open
thejesh23 wants to merge 1 commit into
llvm:mainfrom
thejesh23:lit-cat-stdin-dash
Open

thejesh23 wants to merge 1 commit into
llvm:mainfrom
thejesh23:lit-cat-stdin-dash

Conversation

@thejesh23

Copy link
Copy Markdown

lit's builtin cat now reads stdin for a - operand, as POSIX cat does. This adds a case to the shtest-cat inputs.

Fixes #240058

Assisted-by: Claude Code (claude-opus-5-5). I reviewed the change. I also ran the shtest-cat inputs locally: they fail before the change and pass after it.

POSIX cat reads standard input for a "-" operand, but lit's builtin cat
tried to open a file named "-" and failed, so RUN lines such as
`echo foo | cat - %t` broke under the internal shell.

Assisted-by: Claude Code (claude-opus-5-5)
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown

Hello @thejesh23 👋

Thank you for submitting a Pull Request (PR) to the LLVM Project. Since this is your first PR, here are a few useful links covering our main contribution policies and review practices.

  • All contributions to LLVM must follow our LLVM AI Tool Use Policy. In particular, if you used AI while working on this PR, remember to add a note to the PR description.
  • The LLVM Code-Review Policy and Practices document contains practical information about the PR process, including how patches are reviewed and accepted, and who can review a PR.
  • Our LLVM Developer Policy describes our expectations for code quality, commit summaries and contains notes on our CI system.

Please reply to this message to confirm that you have read these policies, especially the LLVM AI Tool Use Policy, and that any AI tool usage has been noted in the PR description.


Frequently asked questions

How do I add reviewers?

This PR will be automatically labeled, and the relevant teams will be notified. For some parts of the project, reviewers may also be added automatically.

You can also add reviewers manually using the Reviewers section on this page. If you cannot use that section, it is probably because you do not have write permissions for the repository. In that case, you can request a review by tagging reviewers in a comment using @ followed by their GitHub username.

What if there are no comments?

If you have not received any comments on your PR after a week, you can request a review by pinging the PR with a comment such as “Ping”. The common courtesy ping rate is once a week. Please remember that you are asking for volunteer time from other developers.

Are any special GitHub settings required to contribute to LLVM?

We only require contributors to have a public email address associated with their GitHub commits, see this section of LLVM Developer Policy for details.


If you have questions, feel free to leave a comment on this PR, or ask on LLVM Discord or LLVM Discourse.

Thank you,
The LLVM Community

@llvmorg-github-actions

Copy link
Copy Markdown

@llvm/pr-subscribers-testing-tools

Author: Thejesh (thejesh23)

Changes

lit's builtin cat now reads stdin for a - operand, as POSIX cat does. This adds a case to the shtest-cat inputs.

Fixes #240058

Assisted-by: Claude Code (claude-opus-5-5). I reviewed the change. I also ran the shtest-cat inputs locally: they fail before the change and pass after it.


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

2 Files Affected:

  • (modified) llvm/utils/lit/lit/builtin_commands/cat.py (+3-1)
  • (modified) llvm/utils/lit/tests/Inputs/shtest-cat/cat.txt (+12)
diff --git a/llvm/utils/lit/lit/builtin_commands/cat.py b/llvm/utils/lit/lit/builtin_commands/cat.py
index 2882b79f572fd9..bf5430d037e038 100644
--- a/llvm/utils/lit/lit/builtin_commands/cat.py
+++ b/llvm/utils/lit/lit/builtin_commands/cat.py
@@ -71,7 +71,9 @@ def run(argv, stdin, stdout, stderr, cwd):
 
         contents = None
         is_text = False
-        if platform.system() == "OS/390":
+        if filename == "-":
+            contents = stdin.read()
+        elif platform.system() == "OS/390":
             try:
                 with open(path, "r") as fileToCat:
                     contents = fileToCat.read()
diff --git a/llvm/utils/lit/tests/Inputs/shtest-cat/cat.txt b/llvm/utils/lit/tests/Inputs/shtest-cat/cat.txt
index c5b5d247c2f959..0f7a81fe168e89 100644
--- a/llvm/utils/lit/tests/Inputs/shtest-cat/cat.txt
+++ b/llvm/utils/lit/tests/Inputs/shtest-cat/cat.txt
@@ -74,3 +74,15 @@
 ## Test that cat will pipe stdin to stdout if no other files are specified.
 # RUN: echo test | cat | FileCheck --check-prefix=CAT-STDIN %s
 # CAT-STDIN: test
+
+## Test that cat reads stdin in place of a "-" operand.
+# RUN: rm -rf %t
+# RUN: mkdir -p %t
+# RUN: echo "abcdefgh" > %t/temp1.write
+# RUN: echo "mnopqrst" > %t/temp2.write
+# RUN: echo "efghijkl" | cat %t/temp1.write - %t/temp2.write | \
+# RUN:      FileCheck --check-prefix=DASH-CAT-OUTPUT --implicit-check-not={{.}} \
+# RUN:      --match-full-lines --strict-whitespace %s
+#      DASH-CAT-OUTPUT:abcdefgh
+# DASH-CAT-OUTPUT-NEXT:efghijkl
+# DASH-CAT-OUTPUT-NEXT:mnopqrst

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[lit] Builtin cat does not read stdin for a "-" operand

1 participant