Skip to content

Commit fb14374

Browse files
boomanaiden154github-actions[bot]
authored andcommitted
Automerge: [lit] Make builtin cat work with stdin
cat with no files passed to it is supposed to read from STDIN according to POSIX. The builtin cat lacking this behavior led to the clang test in dev-fd-fs.c to fail because it expected this behavior. This is a simple modification and I do not think it is possible to rewrite the test without this easily while preserving the semantics around named pipes. Reviewers: petrhosek, arichardson, ilovepi, cmtice, jh7370 Reviewed By: jh7370, arichardson, ilovepi, cmtice Pull Request: llvm/llvm-project#158447
2 parents 8ce3a27 + 7a3fa06 commit fb14374

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

clang/test/Misc/dev-fd-fs.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Check that we can operate on files from /dev/fd.
22
// REQUIRES: dev-fd-fs
3-
// REQUIRES: shell
43

54
// Check reading from named pipes. We cat the input here instead of redirecting
65
// it to ensure that /dev/fd/0 is a named pipe, not just a redirected file.

llvm/utils/lit/lit/builtin_commands/cat.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ def main(argv):
4949
import os, msvcrt
5050

5151
msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
52+
if len(filenames) == 0:
53+
sys.stdout.write(sys.stdin.read())
54+
sys.exit(0)
5255
for filename in filenames:
5356
try:
5457
contents = None

llvm/utils/lit/tests/Inputs/shtest-cat/cat.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,7 @@
7070
# NP-CAT-OUTPUT-NEXT:M-HM-IM-JM-KM-LM-MM-NM-OM-PM-QM-RM-SM-TM-UM-VM-WM-XM-YM-ZM-[
7171
# NP-CAT-OUTPUT-NEXT:M-\M-]M-^M-_M-`M-aM-bM-cM-dM-eM-fM-gM-hM-iM-jM-kM-lM-mM-nM-o
7272
# NP-CAT-OUTPUT-NEXT:M-pM-qM-rM-sM-tM-uM-vM-wM-xM-yM-zM-{M-|M-}M-~M-^?
73+
74+
## Test that cat will pipe stdin to stdout if no other files are specified.
75+
# RUN: echo test | cat | FileCheck --check-prefix=CAT-STDIN %s
76+
# CAT-STDIN: test

0 commit comments

Comments
 (0)