xref: /freebsd/contrib/bmake/unit-tests/cond-func-defined.mk (revision 6a7405f5a6b639682cacf01e35d561411ff556aa)
1# $NetBSD: cond-func-defined.mk,v 1.14 2025/01/10 23:00:38 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 ')' after argument 'A' 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 ')' after argument 'DEF' 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# Expressions in the argument of a function call don't have to be defined.
53.if defined(${UNDEF})
54.  error
55.endif
56
57# Neither of the conditions is true.  Before July 2020, the right-hand
58# condition was evaluated even though it was irrelevant.
59.if defined(UNDEF) && ${UNDEF:Mx} != ""
60.  error
61.endif
62
63all: .PHONY
64