1# $NetBSD: job-output-null.mk,v 1.3 2021/09/12 10:26:49 rillig Exp $
2#
3# Test how null bytes in the output of a command are handled.  Make processes
4# them using null-terminated strings, which may cut off some of the output.
5#
6# As of 2021-04-15, make handles null bytes from the child process
7# inconsistently.  It's an edge case though since typically the child
8# processes output text.
9
10# Note: The printf commands used in this test must only use a single format
11# string, without parameters.  This is because it is implementation-dependent
12# how many times the command 'printf "fmt%s" "" "" ""' calls write(2).
13#
14#	NetBSD /bin/sh		1 x write("fmtfmtfmt")
15#	Dash			1 x write("fmtfmtfmt")
16#	NetBSD /bin/ksh		3 x write("fmt") (via /bin/printf)
17#	Bash 5			3 x write("fmt")
18#
19# In the latter case the output may arrive in parts, which in this test makes
20# a crucial difference since the outcome of the test depends on whether there
21# is a '\n' in each of the blocks from the output.
22
23.MAKEFLAGS: -j1		# force jobs mode
24
25all: .PHONY
26	# The null byte from the command output is kept as-is.
27	# See CollectOutput, which looks like it intended to replace these
28	# null bytes with simple spaces.
29	@printf '1\0trailing\n'
30
31	# Give the parent process a chance to see the above output, but not
32	# yet the output from the next printf command.
33	@sleep 1
34
35	# All null bytes from the command output are kept as-is.
36	@printf '2a\0trailing\n''2b\0trailing\n''2c\0trailing\n'
37
38	@sleep 1
39
40	# The null bytes are replaced with spaces since they are not followed
41	# by a newline.
42	#
43	# The three null bytes in a row test whether this output is
44	# compressed to a single space like in DebugFailedTarget.  It isn't.
45	@printf '3a\0without\0\0\0newline, 3b\0without\0\0\0newline.'
46