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