xref: /freebsd/contrib/bmake/unit-tests/cond-func-defined.mk (revision 548bfc56eb0b2cefa0fb8dc2478240bfef610309)
1*548bfc56SSimon J. Gerraty# $NetBSD: cond-func-defined.mk,v 1.12 2024/04/23 22:51:28 rillig Exp $
22c3632d1SSimon J. Gerraty#
32c3632d1SSimon J. Gerraty# Tests for the defined() function in .if conditions.
42c3632d1SSimon J. Gerraty
52c3632d1SSimon J. GerratyDEF=		defined
62c3632d1SSimon J. Gerraty${:UA B}=	variable name with spaces
72c3632d1SSimon J. Gerraty
82c3632d1SSimon J. Gerraty.if !defined(DEF)
92c3632d1SSimon J. Gerraty.  error
102c3632d1SSimon J. Gerraty.endif
112c3632d1SSimon J. Gerraty
12956e45f6SSimon J. Gerraty# Horizontal whitespace (space tab) after the opening parenthesis is ignored.
132c3632d1SSimon J. Gerraty.if !defined( 	DEF)
142c3632d1SSimon J. Gerraty.  error
152c3632d1SSimon J. Gerraty.endif
162c3632d1SSimon J. Gerraty
17956e45f6SSimon J. Gerraty# Horizontal whitespace (space tab) before the closing parenthesis is ignored.
182c3632d1SSimon J. Gerraty.if !defined(DEF 	)
192c3632d1SSimon J. Gerraty.  error
202c3632d1SSimon J. Gerraty.endif
212c3632d1SSimon J. Gerraty
222c3632d1SSimon J. Gerraty# The argument of a function must not directly contain whitespace.
23148ee845SSimon J. Gerraty# expect+1: Missing closing parenthesis for defined()
242c3632d1SSimon J. Gerraty.if !defined(A B)
252c3632d1SSimon J. Gerraty.  error
262c3632d1SSimon J. Gerraty.endif
272c3632d1SSimon J. Gerraty
28d5e0a182SSimon J. Gerraty# If necessary, the whitespace can be generated by an expression.
292c3632d1SSimon J. Gerraty.if !defined(${:UA B})
302c3632d1SSimon J. Gerraty.  error
312c3632d1SSimon J. Gerraty.endif
322c3632d1SSimon J. Gerraty
33148ee845SSimon J. Gerraty# expect+1: Missing closing parenthesis for defined()
34e2eeea75SSimon J. Gerraty.if defined(DEF
35e2eeea75SSimon J. Gerraty.  error
36e2eeea75SSimon J. Gerraty.else
37e2eeea75SSimon J. Gerraty.  error
38e2eeea75SSimon J. Gerraty.endif
39e2eeea75SSimon J. Gerraty
40e2eeea75SSimon J. Gerraty# Variables from .for loops are not defined.
41e2eeea75SSimon J. Gerraty# See directive-for.mk for more details.
42e2eeea75SSimon J. Gerraty.for var in value
43e2eeea75SSimon J. Gerraty.  if defined(var)
44e2eeea75SSimon J. Gerraty.    error
45e2eeea75SSimon J. Gerraty.  else
46*548bfc56SSimon J. Gerraty# In .for loops, expressions based on the loop variables are substituted at
47*548bfc56SSimon J. Gerraty# evaluation time.  There is no actual variable involved, even if the code in
48*548bfc56SSimon J. Gerraty# the makefiles looks like it.
49e2eeea75SSimon J. Gerraty.  endif
50e2eeea75SSimon J. Gerraty.endfor
51e2eeea75SSimon J. Gerraty
52954401e6SSimon J. Gerraty# Neither of the conditions is true.  Before July 2020, the right-hand
53954401e6SSimon J. Gerraty# condition was evaluated even though it was irrelevant.
54954401e6SSimon J. Gerraty.if defined(UNDEF) && ${UNDEF:Mx} != ""
55954401e6SSimon J. Gerraty.  error
56954401e6SSimon J. Gerraty.endif
57954401e6SSimon J. Gerraty
58954401e6SSimon J. Gerratyall: .PHONY
59