xref: /freebsd/contrib/bmake/unit-tests/opt-jobs-no-action.mk (revision 4d846d260e2b9a3d4d0a701462568268cbfe7a5b)
1# $NetBSD: opt-jobs-no-action.mk,v 1.10 2022/05/08 06:51:27 rillig Exp $
2#
3# Tests for the combination of the options -j and -n, which prints the
4# commands instead of actually running them.
5#
6# The format of the output differs from the output of only the -n option,
7# without the -j.  This is because all this code is implemented twice, once
8# in compat.c and once in job.c.
9#
10# See also:
11#	opt-jobs.mk
12#		The corresponding tests without the -n option
13#	opt-no-action-combined.mk
14#		The corresponding tests without the -j option
15
16.MAKEFLAGS: -j1 -n
17
18# Change the templates for running the commands in jobs mode, to make it
19# easier to see what actually happens.
20#
21# The shell attributes are handled by Job_ParseShell.
22# The shell attributes 'quiet' and 'echo' don't need a trailing newline,
23# this is handled by the [0] != '\0' checks in Job_ParseShell.
24# The '\#' is handled by ParseRawLine.
25# The '\n' is handled by Str_Words in Job_ParseShell.
26# The '$$' is handled by Var_Subst in ParseDependencyLine.
27.SHELL: \
28	name=sh \
29	path=${.SHELL} \
30	quiet="\# .echoOff" \
31	echo="\# .echoOn" \
32	filter="\# .noPrint\n" \
33	check="\# .echoTmpl\n""echo \"%s\"\n" \
34	ignore="\# .runIgnTmpl\n""%s\n" \
35	errout="\# .runChkTmpl\n""{ %s \n} || exit $$?\n"
36
37all: explained combined
38.ORDER: explained combined
39
40# Explain the most basic cases in detail.
41explained: .PHONY
42	@+echo hide-from-output 'begin explain'
43
44	# The following command is regular, it is printed twice:
45	# - first using the template shell.echoTmpl,
46	# - then using the template shell.runChkTmpl.
47	false regular
48
49	# The following command is silent, it is printed once, using the
50	# template shell.runChkTmpl.
51	@: silent
52
53	# The following command ignores errors, it is printed once, using
54	# the default template for cmdTemplate, which is "%s\n".
55	# XXX: Why is it not printed using shell.echoTmpl as well?
56	# XXX: The '-' should not influence the echoing of the command.
57	-false ignore-errors
58
59	# The following command ignores the -n command line option, it is
60	# not handled by the Job module but by the Compat module, see the
61	# '!silent' in Compat_RunCommand.
62	+echo run despite the -n option
63
64	@+echo hide-from-output 'end explain'
65	@+echo hide-from-output
66
67
68# Test all combinations of the 3 RunFlags.
69#
70# TODO: Closely inspect the output whether it makes sense.
71# XXX: silent=no always=no ignerr={no,yes} should be almost the same.
72#
73SILENT.no=	# none
74SILENT.yes=	@
75ALWAYS.no=	# none
76ALWAYS.yes=	+
77IGNERR.no=	echo running
78IGNERR.yes=	-echo running; false
79#
80combined: combined-begin
81
82combined-begin: .PHONY
83	@+echo hide-from-output 'begin combined'
84	@+echo hide-from-output
85
86.for silent in no yes
87.  for always in no yes
88.    for ignerr in no yes
89.      for target in combined-silent-${silent}-always-${always}-ignerr-${ignerr}
90combined: .WAIT ${target} .WAIT
91${target}: .PHONY
92	@+echo hide-from-output silent=${silent} always=${always} ignerr=${ignerr}
93	${SILENT.${silent}}${ALWAYS.${always}}${IGNERR.${ignerr}}
94	@+echo hide-from-output
95.      endfor
96.    endfor
97.  endfor
98.endfor
99
100combined: combined-end
101combined-end: .PHONY
102	@+echo hide-from-output 'end combined'
103