Home | History | Annotate | Line # | Download | only in unit-tests
sh-flags.mk revision 1.3
      1 # $NetBSD: sh-flags.mk,v 1.3 2020/12/12 12:13:12 rillig Exp $
      2 #
      3 # Tests for the effective RunFlags of a shell command (run/skip, echo/silent,
      4 # error check, trace), which are controlled by 12 different switches.  These
      5 # switches interact in various non-obvious ways.  To analyze the interactions,
      6 # this test runs each possible combination of these switches, for now.
      7 #
      8 # As soon as an interaction of switches is identified as obvious and expected,
      9 # this particular interaction may be removed from the test, to focus on the
     10 # remaining ones.
     11 #
     12 # See also:
     13 #	Compat_RunCommand
     14 #	JobPrintSpecials
     15 
     16 all: .PHONY
     17 
     18 opt-ignerr.yes=		-i
     19 opt-jobs.yes=		-j1
     20 opt-loud.no=		-d0	# side effect: make stdout unbuffered
     21 opt-loud.yes=		-dl	# side effect: make stdout unbuffered
     22 opt-no-action.yes=	-n
     23 opt-silent.yes=		-s
     24 opt-xtrace.yes=		-dx
     25 tgt-always.yes=		.MAKE
     26 tgt-ignerr.yes=		.IGNORE
     27 tgt-silent.yes=		.SILENT
     28 cmd-always.yes=		+
     29 cmd-ignerr.yes=		-
     30 cmd-silent.yes=		@
     31 
     32 letter.always.yes=	a
     33 letter.ignerr.yes=	i
     34 letter.jobs.yes=	j
     35 letter.loud.yes=	l
     36 letter.no-action.yes=	n
     37 letter.silent.yes=	s
     38 letter.xtrace.yes=	x
     39 
     40 .if !defined(OPT_TARGET)
     41 .for opt-ignerr in no yes
     42 .for opt-jobs in no yes
     43 .for opt-loud in no yes
     44 .for opt-no-action in no yes
     45 .for opt-silent in no yes
     46 # Only 'no', not 'yes', since that would add uncontrollable output from
     47 # reading /etc/profile or similar files.
     48 .for opt-xtrace in no
     49 
     50 target=		opt-
     51 target+=	${letter.ignerr.${opt-ignerr}:U_}
     52 target+=	${letter.jobs.${opt-jobs}:U_}
     53 target+=	${letter.loud.${opt-loud}:U_}
     54 target+=	${letter.no-action.${opt-no-action}:U_}
     55 target+=	${letter.silent.${opt-silent}:U_}
     56 target+=	${letter.xtrace.${opt-xtrace}:U_}
     57 
     58 .for target in ${target:ts}
     59 
     60 MAKE_CMD.${target}=	${MAKE}
     61 MAKE_CMD.${target}+=	${opt-ignerr.${opt-ignerr}}
     62 MAKE_CMD.${target}+=	${opt-jobs.${opt-jobs}}
     63 MAKE_CMD.${target}+=	${opt-loud.${opt-loud}}
     64 MAKE_CMD.${target}+=	${opt-no-action.${opt-no-action}}
     65 MAKE_CMD.${target}+=	${opt-silent.${opt-silent}}
     66 MAKE_CMD.${target}+=	${opt-xtrace.${opt-xtrace}}
     67 MAKE_CMD.${target}+=	-f ${MAKEFILE}
     68 MAKE_CMD.${target}+=	OPT_TARGET=${target}
     69 MAKE_CMD.${target}+=	${target}
     70 
     71 all: ${target}
     72 ${target}: .PHONY
     73 	@${MAKE_CMD.${target}:M*}
     74 
     75 .endfor
     76 .endfor
     77 .endfor
     78 .endfor
     79 .endfor
     80 .endfor
     81 .endfor
     82 .endif
     83 
     84 SILENT.yes=	@
     85 ALWAYS.yes=	+
     86 IGNERR.yes=	-
     87 
     88 .if defined(OPT_TARGET)
     89 .for tgt-always in no yes
     90 .for tgt-ignerr in no yes
     91 .for tgt-silent in no yes
     92 .for cmd-always in no yes
     93 .for cmd-ignerr in no yes
     94 .for cmd-silent in no yes
     95 
     96 target=		${OPT_TARGET}-tgt-
     97 target+=	${letter.always.${tgt-always}:U_}
     98 target+=	${letter.ignerr.${tgt-ignerr}:U_}
     99 target+=	${letter.silent.${tgt-silent}:U_}
    100 target+=	-cmd-
    101 target+=	${letter.always.${cmd-always}:U_}
    102 target+=	${letter.ignerr.${cmd-ignerr}:U_}
    103 target+=	${letter.silent.${cmd-silent}:U_}
    104 
    105 .for target in ${target:ts}
    106 
    107 ${OPT_TARGET}: .WAIT ${target} .WAIT
    108 .if ${tgt-always} == yes
    109 ${target}: .MAKE
    110 .endif
    111 .if ${tgt-ignerr} == yes
    112 ${target}: .IGNORE
    113 .endif
    114 .if ${tgt-silent} == yes || ${OPT_TARGET:M*s*}
    115 ${target}: .SILENT
    116 .endif
    117 
    118 RUNFLAGS.${target}=	${SILENT.${cmd-silent}}${ALWAYS.${cmd-always}}${IGNERR.${cmd-ignerr}}
    119 .if ${OPT_TARGET:M*i*} || ${tgt-ignerr} == yes || ${cmd-ignerr} == yes
    120 CMD.${target}=		echo running; false
    121 .else
    122 CMD.${target}=		echo running
    123 .endif
    124 
    125 ${target}: .PHONY
    126 	@+echo hide-from-output
    127 	@+echo hide-from-output ${target}
    128 	${RUNFLAGS.${target}} ${CMD.${target}}
    129 .endfor
    130 
    131 .endfor
    132 .endfor
    133 .endfor
    134 .endfor
    135 .endfor
    136 .endfor
    137 .endif
    138