diff options
Diffstat (limited to 'contrib/bmake/unit-tests/var-op-shell.mk')
-rw-r--r-- | contrib/bmake/unit-tests/var-op-shell.mk | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/contrib/bmake/unit-tests/var-op-shell.mk b/contrib/bmake/unit-tests/var-op-shell.mk index 0fdc54fc6041..4441efaf4a90 100644 --- a/contrib/bmake/unit-tests/var-op-shell.mk +++ b/contrib/bmake/unit-tests/var-op-shell.mk @@ -1,4 +1,4 @@ -# $NetBSD: var-op-shell.mk,v 1.4 2021/02/06 04:55:08 sjg Exp $ +# $NetBSD: var-op-shell.mk,v 1.8 2024/01/05 23:36:45 rillig Exp $ # # Tests for the != variable assignment operator, which runs its right-hand # side through the shell. @@ -15,7 +15,7 @@ OUTPUT!= echo "success"'ful' # an empty output produced the error message "Couldn't read shell's output # for \"%s\"". # -# The error message is still there but reserved for technical errors. +# The error message is still in Cmd_Exec but reserved for technical errors. # It may be possible to trigger the error message by killing the shell after # reading part of its output. OUTPUT!= true @@ -24,13 +24,18 @@ OUTPUT!= true .endif # The output of a shell command that failed is processed nevertheless. -# TODO: Make this an error in lint mode. +# Unlike the other places that run external commands (expression modifier +# '::!=', expression modifier ':!...!'), a failed command generates only a +# warning, not an "error". These "errors" are ignored in default mode, for +# compatibility, but not in lint mode (-dL). +# expect+1: warning: "echo "failed"; false" returned non-zero status OUTPUT!= echo "failed"; false .if ${OUTPUT} != "failed" . error .endif # A command with empty output may fail as well. +# expect+1: warning: "false" returned non-zero status OUTPUT!= false .if ${OUTPUT} != "" . error @@ -53,12 +58,14 @@ OUTPUT!= echo "before"; false; echo "after" # This should result in a warning about "exited on a signal". # This used to be kill -14 (SIGALRM), but that stopped working on # Darwin18 after recent update. +# expect+1: warning: "kill $$" exited on a signal OUTPUT!= kill $$$$ .if ${OUTPUT} != "" . error .endif # A nonexistent command produces a non-zero exit status. +# expect+1: warning: "/bin/no/such/command" returned non-zero status OUTPUT!= /bin/no/such/command .if ${OUTPUT} != "" . error @@ -78,4 +85,28 @@ OUTPUT!= echo '$$$$$$$$' . error .endif + +# As a debugging aid, log the exact command that is run via the shell. +.MAKEFLAGS: -dv +OUTPUT!= echo '$$$$$$$$' +.MAKEFLAGS: -d0 + + +# Since main.c 1.607 from 2024-01-05, long shell commands are not run directly +# via '$shell -c $command', they are first written to a temporary file that is +# then fed to the shell via '$shell $tmpfile'. +OUTPUT_SHORT!= echo "$$0" +OUTPUT_LONG!= echo "$$0" || : ${:U:range=1000} +# When running '$shell -c $command', '$0' in the shell evaluates to the name +# of the shell. +.if ${OUTPUT_SHORT} != ${.SHELL:T} +. error +.endif +# When running '$shell $tmpfile', '$0' in the shell evaluates to the name of +# the temporary file. +.if !${OUTPUT_LONG:M*/make*} +. error +.endif + + all: |