From de83a47b934352f0db7b2cec6305e147e083355d Mon Sep 17 00:00:00 2001 From: rillig Date: Wed, 9 Dec 2020 00:43:48 +0000 Subject: [PATCH] make(1): add more tests for combining -j1 and -n --- .../make/unit-tests/opt-jobs-no-action.exp | 60 +++++++++++++++++++ usr.bin/make/unit-tests/opt-jobs-no-action.mk | 40 +++++++++++-- 2 files changed, 94 insertions(+), 6 deletions(-) diff --git a/usr.bin/make/unit-tests/opt-jobs-no-action.exp b/usr.bin/make/unit-tests/opt-jobs-no-action.exp index 3b5d31e9b33c..e3b285b15e60 100644 --- a/usr.bin/make/unit-tests/opt-jobs-no-action.exp +++ b/usr.bin/make/unit-tests/opt-jobs-no-action.exp @@ -12,4 +12,64 @@ echo "false regular" false ignore-errors echo run despite the -n option run despite the -n option +echo + +echo 'begin combined' +begin combined +echo + +echo silent=no always=no ignerr=no +silent=no always=no ignerr=no +# .echoOff +# .errOnOrEcho +echo "true" +# .errExit +{ true +} || exit $? +# .echoOn +echo + +echo silent=no always=no ignerr=yes +silent=no always=no ignerr=yes +false +echo + +echo silent=no always=yes ignerr=no +silent=no always=yes ignerr=no +true +echo + +echo silent=no always=yes ignerr=yes +silent=no always=yes ignerr=yes +false +*** Error code 1 (ignored) +echo + +echo silent=yes always=no ignerr=no +silent=yes always=no ignerr=no +# .errExit +{ true +} || exit $? +# .echoOn +echo + +echo silent=yes always=no ignerr=yes +silent=yes always=no ignerr=yes +false +# .echoOn +echo + +echo silent=yes always=yes ignerr=no +silent=yes always=yes ignerr=no +true +echo + +echo silent=yes always=yes ignerr=yes +silent=yes always=yes ignerr=yes +false +*** Error code 1 (ignored) +echo + +echo 'end combined' +end combined exit status 0 diff --git a/usr.bin/make/unit-tests/opt-jobs-no-action.mk b/usr.bin/make/unit-tests/opt-jobs-no-action.mk index 1d3e2d2325a4..8bd18e96cb8b 100644 --- a/usr.bin/make/unit-tests/opt-jobs-no-action.mk +++ b/usr.bin/make/unit-tests/opt-jobs-no-action.mk @@ -1,4 +1,4 @@ -# $NetBSD: opt-jobs-no-action.mk,v 1.1 2020/12/09 00:25:00 rillig Exp $ +# $NetBSD: opt-jobs-no-action.mk,v 1.2 2020/12/09 00:43:48 rillig Exp $ # # Tests for the combination of the options -j and -n, which prints the # commands instead of actually running them. @@ -6,6 +6,8 @@ # 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 opt-jobs.mk for the corresponding tests without the -n option. .MAKEFLAGS: -j1 -n @@ -28,7 +30,18 @@ ignore="\# .errOffOrExecIgnore\n""%s\n" \ errout="\# .errExit\n""{ %s \n} || exit $$?\n" -all: +SILENT.no= # none +SILENT.yes= @ +ALWAYS.no= # none +ALWAYS.yes= + +IGNERR.no= true +IGNERR.yes= -false + +all: documented combined +.ORDER: documented combined + +# Explain the most basic cases in detail. +documented: .PHONY # The following command is regular, it is printed twice: # - first using the template shell.errOnOrEcho, # - then using the template shell.errExit. @@ -49,7 +62,22 @@ all: # '!silent' in Compat_RunCommand. +echo run despite the -n option - # TODO: test all 8 combinations of '-', '+', '@'. - # TODO: for each of the above test, test '-true' and '-false'. - # The code with its many branches feels like a big mess. - # See opt-jobs.mk for the corresponding tests without the -n option. + @+echo + +# Test all combinations of the 3 RunFlags. +# +# TODO: Closely inspect the output whether it makes sense. +# XXX: The output should not contain the 'echo silent=...' lines. +combined: + @+echo 'begin $@' + @+echo +.for silent in no yes +. for always in no yes +. for ignerr in no yes + @+echo silent=${silent} always=${always} ignerr=${ignerr} + ${SILENT.${silent}}${ALWAYS.${always}}${IGNERR.${ignerr}} + @+echo +. endfor +. endfor +.endfor + @+echo 'end $@'