Home | History | Annotate | Line # | Download | only in unit-tests
var-eval-short.mk revision 1.6
      1  1.6  rillig # $NetBSD: var-eval-short.mk,v 1.6 2021/09/06 19:38:30 rillig Exp $
      2  1.1  rillig #
      3  1.1  rillig # Tests for each variable modifier to ensure that they only do the minimum
      4  1.1  rillig # necessary computations.  If the result of the expression is not needed, they
      5  1.1  rillig # should only parse the modifier but not actually evaluate it.
      6  1.1  rillig #
      7  1.1  rillig # See also:
      8  1.1  rillig #	var.c, the comment starting with 'The ApplyModifier functions'
      9  1.1  rillig #	ApplyModifier, for the order of the modifiers
     10  1.1  rillig #	ParseModifierPart, for evaluating nested expressions
     11  1.1  rillig #	cond-short.mk
     12  1.1  rillig 
     13  1.1  rillig FAIL=	${:!echo unexpected 1>&2!}
     14  1.1  rillig 
     15  1.1  rillig # The following tests only ensure that nested expressions are not evaluated.
     16  1.1  rillig # They cannot ensure that any unexpanded text returned from ParseModifierPart
     17  1.1  rillig # is ignored as well.  To do that, it is necessary to step through the code of
     18  1.1  rillig # each modifier.
     19  1.1  rillig 
     20  1.1  rillig .if 0 && ${FAIL}
     21  1.1  rillig .endif
     22  1.1  rillig 
     23  1.1  rillig .if 0 && ${VAR::=${FAIL}}
     24  1.1  rillig .elif defined(VAR)
     25  1.1  rillig .  error
     26  1.1  rillig .endif
     27  1.1  rillig 
     28  1.1  rillig .if 0 && ${${FAIL}:?then:else}
     29  1.1  rillig .endif
     30  1.1  rillig 
     31  1.1  rillig .if 0 && ${1:?${FAIL}:${FAIL}}
     32  1.1  rillig .endif
     33  1.1  rillig 
     34  1.1  rillig .if 0 && ${0:?${FAIL}:${FAIL}}
     35  1.1  rillig .endif
     36  1.1  rillig 
     37  1.5  rillig # Before var.c 1.870 from 2021-03-14, the expression ${FAIL} was evaluated
     38  1.4  rillig # after the loop, when undefining the temporary global loop variable.
     39  1.5  rillig # Since var.c 1.907 from 2021-04-04, a '$' is no longer allowed in the
     40  1.5  rillig # variable name.
     41  1.1  rillig .if 0 && ${:Uword:@${FAIL}@expr@}
     42  1.1  rillig .endif
     43  1.1  rillig 
     44  1.1  rillig .if 0 && ${:Uword:@var@${FAIL}@}
     45  1.1  rillig .endif
     46  1.1  rillig 
     47  1.6  rillig # Before var.c 1.877 from 2021-03-14, the modifier ':[...]' did not expand
     48  1.4  rillig # the nested expression ${FAIL} and then tried to parse the unexpanded text,
     49  1.4  rillig # which failed since '$' is not a valid range character.
     50  1.1  rillig .if 0 && ${:Uword:[${FAIL}]}
     51  1.1  rillig .endif
     52  1.1  rillig 
     53  1.6  rillig # Before var.c 1.867 from 2021-03-14, the modifier ':_' defined the variable
     54  1.4  rillig # even though the whole expression should have only been parsed, not
     55  1.4  rillig # evaluated.
     56  1.1  rillig .if 0 && ${:Uword:_=VAR}
     57  1.1  rillig .elif defined(VAR)
     58  1.1  rillig .  error
     59  1.1  rillig .endif
     60  1.1  rillig 
     61  1.6  rillig # Before var.c 1.856 from 2021-03-14, the modifier ':C' did not expand the
     62  1.4  rillig # nested expression ${FAIL} and then tried to compile the unexpanded text as a
     63  1.4  rillig # regular expression, which failed both because of the '{FAIL}', which is not
     64  1.4  rillig # a valid repetition, and because of the '****', which are repeated
     65  1.4  rillig # repetitions as well.
     66  1.4  rillig # '${FAIL}'
     67  1.1  rillig .if 0 && ${:Uword:C,${FAIL}****,,}
     68  1.1  rillig .endif
     69  1.1  rillig 
     70  1.1  rillig DEFINED=	# defined
     71  1.1  rillig .if 0 && ${DEFINED:D${FAIL}}
     72  1.1  rillig .endif
     73  1.1  rillig 
     74  1.1  rillig .if 0 && ${:Uword:E}
     75  1.1  rillig .endif
     76  1.1  rillig 
     77  1.1  rillig # As of 2021-03-14, the error 'Invalid time value: ${FAIL}}' is ok since
     78  1.1  rillig # ':gmtime' does not expand its argument.
     79  1.1  rillig .if 0 && ${:Uword:gmtime=${FAIL}}
     80  1.1  rillig .endif
     81  1.1  rillig 
     82  1.1  rillig .if 0 && ${:Uword:H}
     83  1.1  rillig .endif
     84  1.1  rillig 
     85  1.1  rillig .if 0 && ${:Uword:hash}
     86  1.1  rillig .endif
     87  1.1  rillig 
     88  1.1  rillig .if 0 && ${value:L}
     89  1.1  rillig .endif
     90  1.1  rillig 
     91  1.1  rillig # As of 2021-03-14, the error 'Invalid time value: ${FAIL}}' is ok since
     92  1.1  rillig # ':localtime' does not expand its argument.
     93  1.1  rillig .if 0 && ${:Uword:localtime=${FAIL}}
     94  1.1  rillig .endif
     95  1.1  rillig 
     96  1.1  rillig .if 0 && ${:Uword:M${FAIL}}
     97  1.1  rillig .endif
     98  1.1  rillig 
     99  1.1  rillig .if 0 && ${:Uword:N${FAIL}}
    100  1.1  rillig .endif
    101  1.1  rillig 
    102  1.1  rillig .if 0 && ${:Uword:O}
    103  1.1  rillig .endif
    104  1.1  rillig 
    105  1.1  rillig .if 0 && ${:Uword:Ox}
    106  1.1  rillig .endif
    107  1.1  rillig 
    108  1.1  rillig .if 0 && ${:Uword:P}
    109  1.1  rillig .endif
    110  1.1  rillig 
    111  1.1  rillig .if 0 && ${:Uword:Q}
    112  1.1  rillig .endif
    113  1.1  rillig 
    114  1.1  rillig .if 0 && ${:Uword:q}
    115  1.1  rillig .endif
    116  1.1  rillig 
    117  1.1  rillig .if 0 && ${:Uword:R}
    118  1.1  rillig .endif
    119  1.1  rillig 
    120  1.1  rillig .if 0 && ${:Uword:range}
    121  1.1  rillig .endif
    122  1.1  rillig 
    123  1.1  rillig .if 0 && ${:Uword:S,${FAIL},${FAIL},}
    124  1.1  rillig .endif
    125  1.1  rillig 
    126  1.1  rillig .if 0 && ${:Uword:sh}
    127  1.1  rillig .endif
    128  1.1  rillig 
    129  1.1  rillig .if 0 && ${:Uword:T}
    130  1.1  rillig .endif
    131  1.1  rillig 
    132  1.1  rillig .if 0 && ${:Uword:ts/}
    133  1.1  rillig .endif
    134  1.1  rillig 
    135  1.1  rillig .if 0 && ${:U${FAIL}}
    136  1.1  rillig .endif
    137  1.1  rillig 
    138  1.1  rillig .if 0 && ${:Uword:u}
    139  1.1  rillig .endif
    140  1.1  rillig 
    141  1.1  rillig .if 0 && ${:Uword:word=replacement}
    142  1.1  rillig .endif
    143  1.1  rillig 
    144  1.3  rillig # Before var.c 1.875 from 2021-03-14, Var_Parse returned "${FAIL}else" for the
    145  1.2  rillig # irrelevant right-hand side of the condition, even though this was not
    146  1.2  rillig # necessary.  Since the return value from Var_Parse is supposed to be ignored
    147  1.2  rillig # anyway, and since it is actually ignored in an overly complicated way,
    148  1.2  rillig # an empty string suffices.
    149  1.2  rillig .MAKEFLAGS: -dcpv
    150  1.2  rillig .if 0 && ${0:?${FAIL}then:${FAIL}else}
    151  1.2  rillig .endif
    152  1.2  rillig 
    153  1.2  rillig # The ':L' is applied before the ':?' modifier, giving the expression a name
    154  1.2  rillig # and a value, just to see whether this value gets passed through or whether
    155  1.2  rillig # the parse-only mode results in an empty string (only visible in the debug
    156  1.3  rillig # log).  As of var.c 1.875 from 2021-03-14, the value of the variable gets
    157  1.3  rillig # through, even though an empty string would suffice.
    158  1.2  rillig DEFINED=	defined
    159  1.2  rillig .if 0 && ${DEFINED:L:?${FAIL}then:${FAIL}else}
    160  1.2  rillig .endif
    161  1.2  rillig .MAKEFLAGS: -d0
    162  1.2  rillig 
    163  1.1  rillig all:
    164