xref: /freebsd/contrib/bmake/unit-tests/cond-func-defined.mk (revision 7fdf597e96a02165cfe22ff357b857d5fa15ed8a)
1# $NetBSD: cond-func-defined.mk,v 1.12 2024/04/23 22:51:28 rillig Exp $
2#
3# Tests for the defined() function in .if conditions.
4
5DEF=		defined
6${:UA B}=	variable name with spaces
7
8.if !defined(DEF)
9.  error
10.endif
11
12# Horizontal whitespace (space tab) after the opening parenthesis is ignored.
13.if !defined( 	DEF)
14.  error
15.endif
16
17# Horizontal whitespace (space tab) before the closing parenthesis is ignored.
18.if !defined(DEF 	)
19.  error
20.endif
21
22# The argument of a function must not directly contain whitespace.
23# expect+1: Missing closing parenthesis for defined()
24.if !defined(A B)
25.  error
26.endif
27
28# If necessary, the whitespace can be generated by an expression.
29.if !defined(${:UA B})
30.  error
31.endif
32
33# expect+1: Missing closing parenthesis for defined()
34.if defined(DEF
35.  error
36.else
37.  error
38.endif
39
40# Variables from .for loops are not defined.
41# See directive-for.mk for more details.
42.for var in value
43.  if defined(var)
44.    error
45.  else
46# In .for loops, expressions based on the loop variables are substituted at
47# evaluation time.  There is no actual variable involved, even if the code in
48# the makefiles looks like it.
49.  endif
50.endfor
51
52# Neither of the conditions is true.  Before July 2020, the right-hand
53# condition was evaluated even though it was irrelevant.
54.if defined(UNDEF) && ${UNDEF:Mx} != ""
55.  error
56.endif
57
58all: .PHONY
59