Module Name:    src
Committed By:   rillig
Date:           Mon Feb  1 20:31:41 UTC 2021

Modified Files:
        src/distrib/sets/lists/tests: mi
        src/usr.bin/make/unit-tests: Makefile
Added Files:
        src/usr.bin/make/unit-tests: cmdline-redirect-stdin.exp
            cmdline-redirect-stdin.mk

Log Message:
make: add test for reading from make's stdin

Just out of curiosity whether that really works.  It does.


To generate a diff of this commit:
cvs rdiff -u -r1.1014 -r1.1015 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.264 -r1.265 src/usr.bin/make/unit-tests/Makefile
cvs rdiff -u -r0 -r1.1 src/usr.bin/make/unit-tests/cmdline-redirect-stdin.exp \
    src/usr.bin/make/unit-tests/cmdline-redirect-stdin.mk

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.1014 src/distrib/sets/lists/tests/mi:1.1015
--- src/distrib/sets/lists/tests/mi:1.1014	Sat Jan 30 12:46:38 2021
+++ src/distrib/sets/lists/tests/mi	Mon Feb  1 20:31:41 2021
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1014 2021/01/30 12:46:38 rillig Exp $
+# $NetBSD: mi,v 1.1015 2021/02/01 20:31:41 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -4826,6 +4826,8 @@
 ./usr/tests/usr.bin/make/unit-tests/cmd-errors.mk				tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/cmd-interrupt.exp				tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/cmd-interrupt.mk				tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/cmdline-redirect-stdin.exp			tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/cmdline-redirect-stdin.mk			tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/cmdline-undefined.exp			tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/cmdline-undefined.mk			tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/cmdline.exp					tests-usr.bin-tests	compattestfile,atf

Index: src/usr.bin/make/unit-tests/Makefile
diff -u src/usr.bin/make/unit-tests/Makefile:1.264 src/usr.bin/make/unit-tests/Makefile:1.265
--- src/usr.bin/make/unit-tests/Makefile:1.264	Sat Jan 30 12:46:38 2021
+++ src/usr.bin/make/unit-tests/Makefile	Mon Feb  1 20:31:41 2021
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.264 2021/01/30 12:46:38 rillig Exp $
+# $NetBSD: Makefile,v 1.265 2021/02/01 20:31:41 rillig Exp $
 #
 # Unit tests for make(1)
 #
@@ -46,6 +46,7 @@ TESTS+=		cmd-errors-jobs
 TESTS+=		cmd-errors-lint
 TESTS+=		cmd-interrupt
 TESTS+=		cmdline
+TESTS+=		cmdline-redirect-stdin
 TESTS+=		cmdline-undefined
 TESTS+=		comment
 TESTS+=		compat-error

Added files:

Index: src/usr.bin/make/unit-tests/cmdline-redirect-stdin.exp
diff -u /dev/null src/usr.bin/make/unit-tests/cmdline-redirect-stdin.exp:1.1
--- /dev/null	Mon Feb  1 20:31:41 2021
+++ src/usr.bin/make/unit-tests/cmdline-redirect-stdin.exp	Mon Feb  1 20:31:41 2021
@@ -0,0 +1 @@
+exit status 0
Index: src/usr.bin/make/unit-tests/cmdline-redirect-stdin.mk
diff -u /dev/null src/usr.bin/make/unit-tests/cmdline-redirect-stdin.mk:1.1
--- /dev/null	Mon Feb  1 20:31:41 2021
+++ src/usr.bin/make/unit-tests/cmdline-redirect-stdin.mk	Mon Feb  1 20:31:41 2021
@@ -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

Reply via email to