xref: /freebsd/contrib/bmake/unit-tests/varmod-shell.mk (revision 226192822cddc30cacecd55bccb48f39c653058c)
1*22619282SSimon J. Gerraty# $NetBSD: varmod-shell.mk,v 1.10 2024/07/05 19:47:22 rillig Exp $
22c3632d1SSimon J. Gerraty#
3b0c40a00SSimon J. Gerraty# Tests for the ':!cmd!' variable modifier, which runs the shell command
4b0c40a00SSimon J. Gerraty# given by the variable modifier and returns its output.
5e2eeea75SSimon J. Gerraty#
6e2eeea75SSimon J. Gerraty# This modifier has been added on 2000-04-29.
7e2eeea75SSimon J. Gerraty#
8e2eeea75SSimon J. Gerraty# See also:
9e2eeea75SSimon J. Gerraty#	ApplyModifier_ShellCommand
102c3632d1SSimon J. Gerraty
11e2eeea75SSimon J. Gerraty# The command to be run is enclosed between exclamation marks.
12e2eeea75SSimon J. Gerraty# The previous value of the expression is irrelevant for this modifier.
13e2eeea75SSimon J. Gerraty# The :!cmd! modifier turns an undefined expression into a defined one.
14e2eeea75SSimon J. Gerraty.if ${:!echo word!} != "word"
15e2eeea75SSimon J. Gerraty.  error
16e2eeea75SSimon J. Gerraty.endif
17e2eeea75SSimon J. Gerraty
18e2eeea75SSimon J. Gerraty# If the command exits with non-zero, an error message is printed.
19e2eeea75SSimon J. Gerraty# XXX: Processing continues as usual though.
20e2eeea75SSimon J. Gerraty#
21e2eeea75SSimon J. Gerraty# Between 2000-04-29 and 2020-11-17, the error message mentioned the previous
22e2eeea75SSimon J. Gerraty# value of the expression (which is usually an empty string) instead of the
239f45a3c8SSimon J. Gerraty# command that was executed.
24*22619282SSimon J. Gerraty# expect+1: warning: while evaluating "${:!echo word; (exit 13)!} != "word"" with value "word": Command "echo word; (exit 13)" exited with status 13
25*22619282SSimon J. Gerraty.if ${:!echo word; (exit 13)!} != "word"
26e2eeea75SSimon J. Gerraty.  error
27e2eeea75SSimon J. Gerraty.endif
28*22619282SSimon J. Gerraty# expect+1: warning: while evaluating "${:Uprevious value:!echo word; (exit 13)!} != "word"" with value "word": Command "echo word; (exit 13)" exited with status 13
29*22619282SSimon J. Gerraty.if ${:Uprevious value:!echo word; (exit 13)!} != "word"
30e2eeea75SSimon J. Gerraty.  error
31e2eeea75SSimon J. Gerraty.endif
32e2eeea75SSimon J. Gerraty
339f45a3c8SSimon J. Gerraty
34*22619282SSimon J. Gerraty.MAKEFLAGS: -dv			# to see the "Capturing" debug output
35*22619282SSimon J. Gerraty# expect+1: warning: while evaluating "${:!echo word; ${:U(exit 13)}!}" with value "word": Command "echo word; (exit 13)" exited with status 13
36*22619282SSimon J. Gerraty_:=	${:!echo word; ${:U(exit 13)}!}
379f45a3c8SSimon J. Gerraty.MAKEFLAGS: -d0
389f45a3c8SSimon J. Gerraty
39*22619282SSimon J. Gerraty
402c3632d1SSimon J. Gerratyall:
41