xref: /freebsd/contrib/bmake/unit-tests/var-recursive.mk (revision 6a7405f5a6b639682cacf01e35d561411ff556aa)
1# $NetBSD: var-recursive.mk,v 1.10 2024/08/29 20:20:36 rillig Exp $
2#
3# Tests for expressions that refer to themselves and thus cannot be
4# evaluated, as that would lead to an endless loop.
5
6.if make(loadtime)
7
8DIRECT=	${DIRECT}	# Defining a recursive variable is not an error.
9# expect+2: Variable DIRECT is recursive.
10# expect+1: <>
11.  info <${DIRECT}>	# But expanding such a variable is an error.
12
13
14# The chain of variables that refer to each other may be long.
15INDIRECT1=	${INDIRECT2}
16INDIRECT2=	${INDIRECT1}
17# expect+2: Variable INDIRECT1 is recursive.
18# expect+1: <>
19.  info <${INDIRECT1}>
20
21
22# The variable refers to itself, but only in the branch of a condition that
23# is not satisfied and is thus not evaluated.
24CONDITIONAL=	${1:?ok:${CONDITIONAL}}
25# expect+1: <ok>
26.  info <${CONDITIONAL}>
27
28
29# An expression with modifiers is skipped halfway.  This can lead to wrong
30# follow-up error messages, but recursive variables occur seldom.
31MODIFIERS=	${MODIFIERS:Mpattern}
32# expect+2: Variable MODIFIERS is recursive.
33# expect+1: <Mpattern}>
34.  info <${MODIFIERS}>
35
36
37# Short variable names can be expanded using the short-hand $V notation,
38# which takes a different code path in Var_Parse for parsing the variable
39# name.  Ensure that these are checked as well.
40V=	$V
41# expect+2: Variable V is recursive.
42# expect+1: <>
43.  info <$V>
44
45.elif make(runtime)
46
47VAR=	${VAR}
48runtime:
49# expect: : before-recursive
50	: before-recursive
51# expect: make: Variable VAR is recursive.
52# expect-not: recursive-line-before
53# expect-not: recursive-line-after
54	: recursive-line-before <${VAR}> recursive-line-after
55# expect-not: after-recursive
56	: after-recursive
57
58.else
59
60all:
61	@${MAKE} -f ${MAKEFILE} loadtime || echo "sub-exit status $$?"
62	@${MAKE} -f ${MAKEFILE} runtime || echo "sub-exit status $$?"
63
64.endif
65