xref: /freebsd/contrib/bmake/unit-tests/varmod-remember.mk (revision 5def4c47d4bd90b209b9b4a4ba9faec15846d8fd)
1# $NetBSD: varmod-remember.mk,v 1.6 2021/03/14 17:27:27 rillig Exp $
2#
3# Tests for the :_ modifier, which saves the current variable value
4# in the _ variable or another, to be used later again.
5
6.if ${1 2 3:L:_:@var@${_}@} != "1 2 3 1 2 3 1 2 3"
7.  error
8.endif
9
10# In the parameterized form, having the variable name on the right side of
11# the = assignment operator is confusing.  In almost all other situations
12# the variable name is on the left-hand side of the = operator.  Luckily
13# this modifier is only rarely needed.
14.if ${1 2 3:L:@var@${var:_=SAVED:}@} != "1 2 3"
15.  error
16.elif ${SAVED} != "3"
17.  error
18.endif
19
20# The ':_' modifier takes a variable name as optional argument.  This variable
21# name can refer to other variables, though this was rather an implementation
22# oversight than an intended feature.  The variable name stops at the first
23# '}' or ')' and thus cannot use the usual form ${VARNAME} of long variable
24# names.
25#
26# Because of all these edge-casey conditions, this "feature" has been removed
27# in var.c 1.867 from 2021-03-14.
28S=	INDIRECT_VARNAME
29.if ${value:L:@var@${var:_=$S}@} != "value"
30.  error
31.elif defined(INDIRECT_VARNAME)
32.  error
33.endif
34
35all:
36