xref: /freebsd/contrib/bmake/unit-tests/job-output.mk (revision 0b46a53a2f50b5ab0f4598104119a049b9c42cc9)
1# $NetBSD: job-output.mk,v 1.2 2025/06/13 06:13:20 rillig Exp $
2#
3# Tests for handling the output in parallel mode.
4
5all: .PHONY
6	@${MAKE} -f ${MAKEFILE} -j1 empty-lines
7	@${MAKE} -f ${MAKEFILE} -j1 stdout-and-stderr
8	@${MAKE} -f ${MAKEFILE} -j1 echo-on-stdout-and-stderr
9
10# By sleeping for a second, the output of the child process is written byte
11# by byte, to be consumed in small pieces by make.  No matter what the chunk
12# size is, the empty lines must not be discarded.
13empty-lines: .PHONY
14	@echo begin $@
15	@sleep 1
16	@echo
17	@sleep 1
18	@echo
19	@sleep 1
20	@echo end $@
21
22# In parallel mode, both stdout and stderr from the child process are
23# collected in a local buffer and then written to make's stdout.
24#
25# expect: begin stdout-and-stderr
26# expect: only stdout:
27# expect: This is stdout.
28# expect: This is stderr.
29# expect: only stderr:
30# expect: end stdout-and-stderr
31stdout-and-stderr:
32	@echo begin $@
33	@echo only stdout:
34	@${MAKE} -f ${MAKEFILE} echo-on-stdout-and-stderr 2>/dev/null
35	@echo only stderr:
36	@${MAKE} -f ${MAKEFILE} echo-on-stdout-and-stderr 1>/dev/null
37	@echo end $@
38
39echo-on-stdout-and-stderr: .PHONY
40	@echo This is stdout.
41	@echo This is stderr. 1>&2
42