aboutsummaryrefslogtreecommitdiff
path: root/contrib/bmake/unit-tests/opt-jobs-no-action.mk
blob: 19d82c5bf4b80e9c0ec36808cdd9fd46ade3cafa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# $NetBSD: opt-jobs-no-action.mk,v 1.9 2021/04/04 09:58:51 rillig Exp $
#
# Tests for the combination of the options -j and -n, which prints the
# commands instead of actually running them.
#
# The format of the output differs from the output of only the -n option,
# without the -j.  This is because all this code is implemented twice, once
# in compat.c and once in job.c.
#
# See also:
#	opt-jobs.mk
#		The corresponding tests without the -n option
#	opt-no-action-combined.mk
#		The corresponding tests without the -j option

.MAKEFLAGS: -j1 -n

# Change the templates for running the commands in jobs mode, to make it
# easier to see what actually happens.
#
# The shell attributes are handled by Job_ParseShell.
# The shell attributes 'quiet' and 'echo' don't need a trailing newline,
# this is handled by the [0] != '\0' checks in Job_ParseShell.
# The '\#' is handled by ParseGetLine.
# The '\n' is handled by Str_Words in Job_ParseShell.
# The '$$' is handled by Var_Subst in ParseDependencyLine.
.SHELL: \
	name=sh \
	path=${.SHELL} \
	quiet="\# .echoOff" \
	echo="\# .echoOn" \
	filter="\# .noPrint\n" \
	check="\# .echoTmpl\n""echo \"%s\"\n" \
	ignore="\# .runIgnTmpl\n""%s\n" \
	errout="\# .runChkTmpl\n""{ %s \n} || exit $$?\n"

all: explained combined
.ORDER: explained combined

# Explain the most basic cases in detail.
explained: .PHONY
	@+echo hide-from-output 'begin explain'

	# The following command is regular, it is printed twice:
	# - first using the template shell.echoTmpl,
	# - then using the template shell.runChkTmpl.
	false regular

	# The following command is silent, it is printed once, using the
	# template shell.runChkTmpl.
	@: silent

	# The following command ignores errors, it is printed once, using
	# the default template for cmdTemplate, which is "%s\n".
	# XXX: Why is it not printed using shell.echoTmpl as well?
	# XXX: The '-' should not influence the echoing of the command.
	-false ignore-errors

	# The following command ignores the -n command line option, it is
	# not handled by the Job module but by the Compat module, see the
	# '!silent' in Compat_RunCommand.
	+echo run despite the -n option

	@+echo hide-from-output 'end explain'
	@+echo hide-from-output


# Test all combinations of the 3 RunFlags.
#
# TODO: Closely inspect the output whether it makes sense.
# XXX: silent=no always=no ignerr={no,yes} should be almost the same.
#
SILENT.no=	# none
SILENT.yes=	@
ALWAYS.no=	# none
ALWAYS.yes=	+
IGNERR.no=	echo running
IGNERR.yes=	-echo running; false
#
combined: combined-begin

combined-begin: .PHONY
	@+echo hide-from-output 'begin combined'
	@+echo hide-from-output

.for silent in no yes
.  for always in no yes
.    for ignerr in no yes
.      for target in combined-silent-${silent}-always-${always}-ignerr-${ignerr}
combined: .WAIT ${target} .WAIT
${target}: .PHONY
	@+echo hide-from-output silent=${silent} always=${always} ignerr=${ignerr}
	${SILENT.${silent}}${ALWAYS.${always}}${IGNERR.${ignerr}}
	@+echo hide-from-output
.      endfor
.    endfor
.  endfor
.endfor

combined: combined-end
combined-end: .PHONY
	@+echo hide-from-output 'end combined'