Home | History | Annotate | Line # | Download | only in unit-tests
parse-var.mk revision 1.2
      1 # $NetBSD: parse-var.mk,v 1.2 2022/08/06 21:26:05 rillig Exp $
      2 #
      3 # Tests for parsing variable expressions.
      4 
      5 .MAKEFLAGS: -dL
      6 
      7 # In variable assignments, there may be spaces in the middle of the left-hand
      8 # side of the assignment, but only if they occur inside variable expressions.
      9 # Leading spaces (but not tabs) are possible but unusual.
     10 # Trailing spaces are common in some coding styles, others omit them.
     11 VAR.${:U param }=	value
     12 .if ${VAR.${:U param }} != "value"
     13 .  error
     14 .endif
     15 
     16 
     17 # As of var.c 1.1027 from 2022-08-05, the exact way of parsing an expression
     18 # depends on whether the expression is actually evaluated or merely parsed.
     19 #
     20 # If it is evaluated, nested expressions are parsed correctly, parsing each
     21 # modifier according to its exact definition.  If the expression is merely
     22 # parsed but not evaluated (because its value would not influence the outcome
     23 # of the condition), and the expression contains a modifier, and that modifier
     24 # contains a nested expression, the nested expression is not parsed
     25 # correctly.  Instead, make only counts the opening and closing delimiters,
     26 # which fails for nested modifiers with unbalanced braces.
     27 #
     28 # See ParseModifierPartDollar.
     29 
     30 #.MAKEFLAGS: -dcpv
     31 # Keep these braces outside the conditions below, to keep them simple to
     32 # understand.  If the BRACE_PAIR had been replaced with ':U{}', the '}' would
     33 # have to be escaped, but not the '{'.  This asymmetry would have made the
     34 # example even more complicated to understand.
     35 BRACE_PAIR=	{}
     36 # In this test word, the '{{}' in the middle will be replaced.
     37 BRACE_GROUP=	{{{{}}}}
     38 
     39 # The inner ':S' modifier turns the word '{}' into '{{}'.
     40 # The outer ':S' modifier then replaces '{{}' with '<lbraces>'.
     41 # In the first case, the outer expression is relevant and is parsed correctly.
     42 .if 1 && ${BRACE_GROUP:S,${BRACE_PAIR:S,{,{{,},<lbraces>,}
     43 .endif
     44 # In the second case, the outer expression is irrelevant.  In this case, in
     45 # the parts of the outer ':S' modifier, make only counts the braces, and since
     46 # the inner expression '${:U...}' contains more '{' than '}', parsing fails.
     47 .if 0 && ${BRACE_GROUP:S,${BRACE_PAIR:S,{,{{,},<lbraces>,}
     48 .endif
     49 #.MAKEFLAGS: -d0
     50 
     51 
     52 all: .PHONY
     53