Home | History | Annotate | Line # | Download | only in unit-tests
varmod-remember.mk revision 1.7
      1 # $NetBSD: varmod-remember.mk,v 1.7 2023/02/09 07:34:15 sjg 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 # this should result in "1=A 2=B 3=C"
      7 ABC= ${A B C:L:_:range:@i@$i=${_:[$i]}@}
      8 
      9 # we compare this with a repeat later
     10 x:= ${ABC}
     11 
     12 .if ${1 2 3:L:_:@var@${_}@} != "1 2 3 1 2 3 1 2 3"
     13 .  error
     14 .endif
     15 
     16 # In the parameterized form, having the variable name on the right side of
     17 # the = assignment operator is confusing.  In almost all other situations
     18 # the variable name is on the left-hand side of the = operator.  Luckily
     19 # this modifier is only rarely needed.
     20 .if ${1 2 3:L:@var@${var:_=SAVED:}@} != "1 2 3"
     21 .  error
     22 .elif ${SAVED} != "3"
     23 .  error
     24 .endif
     25 
     26 # The ':_' modifier takes a variable name as optional argument.  This variable
     27 # name can refer to other variables, though this was rather an implementation
     28 # oversight than an intended feature.  The variable name stops at the first
     29 # '}' or ')' and thus cannot use the usual form ${VARNAME} of long variable
     30 # names.
     31 #
     32 # Because of all these edge-casey conditions, this "feature" has been removed
     33 # in var.c 1.867 from 2021-03-14.
     34 S=	INDIRECT_VARNAME
     35 .if ${value:L:@var@${var:_=$S}@} != "value"
     36 .  error
     37 .elif defined(INDIRECT_VARNAME)
     38 .  error
     39 .endif
     40 
     41 # we *should* get the same result as for $x above
     42 X:= ${ABC}
     43 .if $X != $x
     44 .  error
     45 .endif
     46 
     47 all:
     48