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 tests/make: demonstrate handling of ...



details:   https://anonhg.NetBSD.org/src/rev/71b46a3fd344
branches:  trunk
changeset: 961696:71b46a3fd344
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu Apr 15 19:02:29 2021 +0000

description:
tests/make: demonstrate handling of null bytes

diffstat:

 distrib/sets/lists/tests/mi                 |   4 ++-
 usr.bin/make/unit-tests/Makefile            |   3 +-
 usr.bin/make/unit-tests/job-output-null.exp |   4 +++
 usr.bin/make/unit-tests/job-output-null.mk  |  32 +++++++++++++++++++++++++++++
 4 files changed, 41 insertions(+), 2 deletions(-)

diffs (79 lines):

diff -r 165a6f4f2bcc -r 71b46a3fd344 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Thu Apr 15 18:36:17 2021 +0000
+++ b/distrib/sets/lists/tests/mi       Thu Apr 15 19:02:29 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1040 2021/04/14 18:27:11 rillig Exp $
+# $NetBSD: mi,v 1.1041 2021/04/15 19:02:29 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -5487,6 +5487,8 @@
 ./usr/tests/usr.bin/make/unit-tests/job-flags.mk                               tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/job-output-long-lines.exp                  tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/job-output-long-lines.mk                   tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/job-output-null.exp                                tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/job-output-null.mk                         tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/jobs-empty-commands.exp                    tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/jobs-empty-commands.mk                     tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/jobs-error-indirect.exp                    tests-usr.bin-tests     compattestfile,atf
diff -r 165a6f4f2bcc -r 71b46a3fd344 usr.bin/make/unit-tests/Makefile
--- a/usr.bin/make/unit-tests/Makefile  Thu Apr 15 18:36:17 2021 +0000
+++ b/usr.bin/make/unit-tests/Makefile  Thu Apr 15 19:02:29 2021 +0000
@@ -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+=                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 -r 165a6f4f2bcc -r 71b46a3fd344 usr.bin/make/unit-tests/job-output-null.exp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/job-output-null.exp       Thu Apr 15 19:02:29 2021 +0000
@@ -0,0 +1,4 @@
+hello
+hello
+hello world without   newline, hello world without   newline, hello world without   newline.
+exit status 0
diff -r 165a6f4f2bcc -r 71b46a3fd344 usr.bin/make/unit-tests/job-output-null.mk
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/job-output-null.mk        Thu Apr 15 19:02:29 2021 +0000
@@ -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' ', ' ', ' '.'



Home | Main Index | Thread Index | Old Index