Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/make/unit-tests make: add test for reading from make...
details: https://anonhg.NetBSD.org/src/rev/c689904caa9d
branches: trunk
changeset: 950839:c689904caa9d
user: rillig <rillig%NetBSD.org@localhost>
date: Mon Feb 01 20:31:41 2021 +0000
description:
make: add test for reading from make's stdin
Just out of curiosity whether that really works. It does.
diffstat:
distrib/sets/lists/tests/mi | 4 +-
usr.bin/make/unit-tests/Makefile | 3 +-
usr.bin/make/unit-tests/cmdline-redirect-stdin.exp | 1 +
usr.bin/make/unit-tests/cmdline-redirect-stdin.mk | 34 ++++++++++++++++++++++
4 files changed, 40 insertions(+), 2 deletions(-)
diffs (78 lines):
diff -r a941d50c678f -r c689904caa9d distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi Mon Feb 01 20:01:26 2021 +0000
+++ b/distrib/sets/lists/tests/mi Mon Feb 01 20:31:41 2021 +0000
@@ -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
diff -r a941d50c678f -r c689904caa9d usr.bin/make/unit-tests/Makefile
--- a/usr.bin/make/unit-tests/Makefile Mon Feb 01 20:01:26 2021 +0000
+++ b/usr.bin/make/unit-tests/Makefile Mon Feb 01 20:31:41 2021 +0000
@@ -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-lint
TESTS+= cmd-interrupt
TESTS+= cmdline
+TESTS+= cmdline-redirect-stdin
TESTS+= cmdline-undefined
TESTS+= comment
TESTS+= compat-error
diff -r a941d50c678f -r c689904caa9d usr.bin/make/unit-tests/cmdline-redirect-stdin.exp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/cmdline-redirect-stdin.exp Mon Feb 01 20:31:41 2021 +0000
@@ -0,0 +1,1 @@
+exit status 0
diff -r a941d50c678f -r c689904caa9d usr.bin/make/unit-tests/cmdline-redirect-stdin.mk
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/cmdline-redirect-stdin.mk Mon Feb 01 20:31:41 2021 +0000
@@ -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
Home |
Main Index |
Thread Index |
Old Index