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