Home | History | Annotate | Line # | Download | only in unit-tests
opt-jobs-no-action.mk revision 1.7
      1 # $NetBSD: opt-jobs-no-action.mk,v 1.7 2020/12/09 08:20:56 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 ParseGetLine.
     25 # The '\n' is handled by Str_Words in Job_ParseShell.
     26 # The '$$' is handled by Var_Subst in ParseDependency.
     27 .SHELL: \
     28 	name=sh \
     29 	path=${.SHELL} \
     30 	quiet="\# .echoOff" \
     31 	echo="\# .echoOn" \
     32 	filter="\# .noPrint\n" \
     33 	check="\# .errOnOrEcho\n""echo \"%s\"\n" \
     34 	ignore="\# .errOffOrExecIgnore\n""%s\n" \
     35 	errout="\# .errExit\n""{ %s \n} || exit $$?\n"
     36 
     37 all: explained combined
     38 .ORDER: explained combined
     39 
     40 # Explain the most basic cases in detail.
     41 explained: .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.errOnOrEcho,
     46 	# - then using the template shell.errExit.
     47 	false regular
     48 
     49 	# The following command is silent, it is printed once, using the
     50 	# template shell.errExit.
     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.errOnOrEcho 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 #
     73 SILENT.no=	# none
     74 SILENT.yes=	@
     75 ALWAYS.no=	# none
     76 ALWAYS.yes=	+
     77 IGNERR.no=	echo running
     78 IGNERR.yes=	-echo running; false
     79 #
     80 combined: combined-begin
     81 
     82 combined-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}
     90 combined: .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 
    100 combined: combined-end
    101 combined-end: .PHONY
    102 	@+echo hide-from-output 'end combined'
    103