diff options
Diffstat (limited to 'unit-tests/cmdline-redirect-stdin.mk')
-rw-r--r-- | unit-tests/cmdline-redirect-stdin.mk | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/unit-tests/cmdline-redirect-stdin.mk b/unit-tests/cmdline-redirect-stdin.mk new file mode 100644 index 000000000000..994016b5ec87 --- /dev/null +++ b/unit-tests/cmdline-redirect-stdin.mk @@ -0,0 +1,34 @@ +# $NetBSD: cmdline-redirect-stdin.mk,v 1.1 2021/02/01 20:31:41 rillig Exp $ +# +# Demonstrate that the '!=' assignment operator can read individual lines +# from make's stdin. +# +# This edge case is an implementation detail that has no practical +# application. + +all: .PHONY + @printf '%s\n' "first line" "second line" \ + | ${MAKE} -f ${MAKEFILE} read-lines + +.if make(read-lines) +line1!= read line; echo "$$line" +line2!= read line; echo "$$line" + +.if ${line1} != "first line" +. error line1="${line1}" + +.elif ${line2} == "" +# If this branch is ever reached, the shell from the assignment to line1 +# probably buffers its input. Most shells use unbuffered stdin, and this +# is actually specified by POSIX, which says that "The read utility shall +# read a single line from standard input". This is the reason why the shell +# reads its input byte by byte, which makes it terribly slow for practical +# applications. +. error The shell's read command does not read a single line. + +.elif ${line2} != "second line" +. error line2="${line2}" +.endif + +read-lines: .PHONY +.endif |