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