Home | History | Annotate | Line # | Download | only in unit-tests
varmod-range.mk revision 1.5
      1 # $NetBSD: varmod-range.mk,v 1.5 2020/11/01 13:10:22 rillig Exp $
      2 #
      3 # Tests for the :range variable modifier, which generates sequences
      4 # of integers from the given range.
      5 
      6 # The :range modifier generates a sequence of integers, one number per
      7 # word of the variable expression's value.
      8 .if ${a b c:L:range} != "1 2 3"
      9 .  error
     10 .endif
     11 
     12 # To preserve spaces in a word, they can be enclosed in quotes, just like
     13 # everywhere else.
     14 .if ${:U first "the second word" third 4 :range} != "1 2 3 4"
     15 .  error
     16 .endif
     17 
     18 # The :range modifier takes the number of words from the value of the
     19 # variable expression.  If that expression is undefined, the range is
     20 # undefined as well.  This should not come as a surprise.
     21 .if "${:range}" != ""
     22 .  error
     23 .endif
     24 
     25 # The :range modifier can be given a parameter, which makes the generated
     26 # range independent from the value or the name of the variable expression.
     27 #
     28 # XXX: As of 2020-09-27, the :range=... modifier does not turn the undefined
     29 # expression into a defined one.  This looks like an oversight.
     30 .if "${:range=5}" != ""
     31 .  error
     32 .endif
     33 
     34 # Negative ranges don't make sense.
     35 # As of 2020-11-01, they are accepted though, using up all available memory.
     36 #.if "${:range=-1}"
     37 #.  error
     38 #.else
     39 #.  error
     40 #.endif
     41 
     42 # The :range modifier requires a number as parameter.
     43 # As of 2020-11-01, the parser tries to read the 'x' as a number, fails and
     44 # stops there.  It then tries to parse the next modifier at that point,
     45 # which fails with the message "Unknown modifier".
     46 .if "${:U:range=x}Rest" != "Rest"
     47 .  error
     48 .else
     49 .  error
     50 .endif
     51 
     52 # The upper limit of the range must always be given in decimal.
     53 # This parse error stops at the 'x', trying to parse it as a variable
     54 # modifier.
     55 .if "${:U:range=0x0}Rest" != "Rest"
     56 .  error
     57 .else
     58 .  error
     59 .endif
     60 
     61 # As of 2020-11-01, numeric overflow is not detected.
     62 # Since strtoul returns ULONG_MAX in such a case, it is interpreted as a
     63 # very large number, consuming all available memory.
     64 #.if "${:U:range=18446744073709551619}Rest" != "Rest"
     65 #.  error
     66 #.else
     67 #.  error
     68 #.endif
     69 
     70 # modifier name too short
     71 .if "${a b c:L:rang}Rest" != "Rest"
     72 .  error
     73 .else
     74 .  error
     75 .endif
     76 
     77 # misspelled modifier name
     78 .if "${a b c:L:rango}Rest" != "Rest"
     79 .  error
     80 .else
     81 .  error
     82 .endif
     83 
     84 # modifier name too long
     85 .if "${a b c:L:ranger}Rest" != "Rest"
     86 .  error
     87 .else
     88 .  error
     89 .endif
     90 
     91 all:
     92