xref: /freebsd/contrib/bmake/unit-tests/var-recursive.mk (revision cfd6422a5217410fbd66f7a7a8a64d9d85e61229)
1# $NetBSD: var-recursive.mk,v 1.2 2020/10/31 13:45:00 rillig Exp $
2#
3# Tests for variable expressions that refer to themselves and thus
4# cannot be evaluated.
5
6TESTS=	direct indirect conditional short
7
8# Since make exits immediately when it detects a recursive expression,
9# the actual tests are run in sub-makes.
10TEST?=	# none
11.if ${TEST} == ""
12all:
13.for test in ${TESTS}
14	@${.MAKE} -f ${MAKEFILE} TEST=${test} || :
15.endfor
16
17.elif ${TEST} == direct
18
19DIRECT=	${DIRECT}	# Defining a recursive variable is not yet an error.
20.  info still there	# Therefore this line is printed.
21.  info ${DIRECT}	# But expanding the variable is an error.
22
23.elif ${TEST} == indirect
24
25# The chain of variables that refer to each other may be long.
26INDIRECT1=	${INDIRECT2}
27INDIRECT2=	${INDIRECT1}
28.  info ${INDIRECT1}
29
30.elif ${TEST} == conditional
31
32# The variable refers to itself, but only in the branch of a condition that
33# is never satisfied and is thus not evaluated.
34CONDITIONAL=	${1:?ok:${CONDITIONAL}}
35.  info ${CONDITIONAL}
36
37.elif ${TEST} == short
38
39# Short variable names can be expanded using the short-hand $V notation,
40# which takes a different code path in Var_Parse for parsing the variable
41# name.  Ensure that these are checked as well.
42V=	$V
43.  info $V
44
45.else
46.  error Unknown test "${TEST}"
47.endif
48
49all:
50