summaryrefslogtreecommitdiff
path: root/usr.bin/make
diff options
context:
space:
mode:
authorrillig <rillig@NetBSD.org>2021-04-15 19:02:29 +0000
committerrillig <rillig@NetBSD.org>2021-04-15 19:02:29 +0000
commit796d288fc8ad62888d5d8f90ccbcc028fd9fce94 (patch)
tree0ab68842891c309acb0a8388dc1fda07d5d3925e /usr.bin/make
parent0244db378aaf2de3e313e9d982f849bcaff81826 (diff)
tests/make: demonstrate handling of null bytes
Diffstat (limited to 'usr.bin/make')
-rw-r--r--usr.bin/make/unit-tests/Makefile3
-rw-r--r--usr.bin/make/unit-tests/job-output-null.exp4
-rw-r--r--usr.bin/make/unit-tests/job-output-null.mk32
3 files changed, 38 insertions, 1 deletions
diff --git a/usr.bin/make/unit-tests/Makefile b/usr.bin/make/unit-tests/Makefile
index aaf5127b4a5..21991a6531c 100644
--- a/usr.bin/make/unit-tests/Makefile
+++ b/usr.bin/make/unit-tests/Makefile
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.275 2021/04/04 13:20:52 rillig Exp $
+# $NetBSD: Makefile,v 1.276 2021/04/15 19:02:29 rillig Exp $
#
# Unit tests for make(1)
#
@@ -204,6 +204,7 @@ TESTS+= impsrc
TESTS+= include-main
TESTS+= job-flags
TESTS+= job-output-long-lines
+TESTS+= job-output-null
TESTS+= jobs-empty-commands
TESTS+= jobs-error-indirect
TESTS+= jobs-error-nested
diff --git a/usr.bin/make/unit-tests/job-output-null.exp b/usr.bin/make/unit-tests/job-output-null.exp
new file mode 100644
index 00000000000..af9b4e64dba
--- /dev/null
+++ b/usr.bin/make/unit-tests/job-output-null.exp
@@ -0,0 +1,4 @@
+hello
+hello
+hello world without newline, hello world without newline, hello world without newline.
+exit status 0
diff --git a/usr.bin/make/unit-tests/job-output-null.mk b/usr.bin/make/unit-tests/job-output-null.mk
new file mode 100644
index 00000000000..7620bdf6a7b
--- /dev/null
+++ b/usr.bin/make/unit-tests/job-output-null.mk
@@ -0,0 +1,32 @@
+# $NetBSD: job-output-null.mk,v 1.1 2021/04/15 19:02:29 rillig Exp $
+#
+# Test how null bytes in the output of a command are handled. Make processes
+# them using null-terminated strings, which may cut off some of the output.
+#
+# As of 2021-04-15, make handles null bytes from the child process
+# inconsistently. It's an edge case though since typically the child
+# processes output text.
+
+.MAKEFLAGS: -j1 # force jobs mode
+
+all: .PHONY
+ # The null byte from the command output is kept as-is.
+ # See CollectOutput, which looks like it intended to replace these
+ # null bytes with simple spaces.
+ @printf 'hello\0world%s\n' ''
+
+ # Give the parent process a chance to see the above output, but not
+ # yet the output from the next printf command.
+ @sleep 1
+
+ # All null bytes from the command output are kept as-is.
+ @printf 'hello\0world%s\n' '' '' '' '' '' ''
+
+ @sleep 1
+
+ # The null bytes are replaced with spaces since they are not followed
+ # by a newline.
+ #
+ # The three null bytes in a row test whether this output is
+ # compressed to a single space like in DebugFailedTarget. It isn't.
+ @printf 'hello\0world\0without\0\0\0newline%s' ', ' ', ' '.'