Home | History | Annotate | Line # | Download | only in unit-tests
varmod-sysv.mk revision 1.4
      1  1.4  rillig # $NetBSD: varmod-sysv.mk,v 1.4 2020/10/06 21:05:21 rillig Exp $
      2  1.1  rillig #
      3  1.2  rillig # Tests for the ${VAR:from=to} variable modifier, which replaces the suffix
      4  1.2  rillig # "from" with "to".  It can also use '%' as a wildcard.
      5  1.2  rillig #
      6  1.2  rillig # This modifier is applied when the other modifiers don't match exactly.
      7  1.1  rillig 
      8  1.4  rillig all:
      9  1.1  rillig 
     10  1.3  rillig # The :Q looks like a modifier but isn't.
     11  1.3  rillig # It is part of the replacement string.
     12  1.4  rillig .if ${a b c d e:L:%a=x:Q} != "x:Q b c d e"
     13  1.4  rillig .  error
     14  1.4  rillig .endif
     15  1.3  rillig 
     16  1.3  rillig # Before 2020-07-19, an ampersand could be used in the replacement part
     17  1.4  rillig # of a SysV substitution modifier, and it was replaced with the whole match,
     18  1.4  rillig # just like in the :S modifier.
     19  1.4  rillig #
     20  1.4  rillig # This was probably a copy-and-paste mistake since the code for the SysV
     21  1.4  rillig # modifier looked a lot like the code for the :S and :C modifiers.
     22  1.4  rillig # The ampersand is not mentioned in the manual page.
     23  1.4  rillig .if ${a.bcd.e:L:a.%=%} != "bcd.e"
     24  1.4  rillig .  error
     25  1.4  rillig .endif
     26  1.4  rillig # Before 2020-07-19, the result of the expression was "a.bcd.e".
     27  1.4  rillig .if ${a.bcd.e:L:a.%=&} != "&"
     28  1.4  rillig .  error
     29  1.4  rillig .endif
     30  1.3  rillig 
     31  1.3  rillig # Before 2020-07-20, when a SysV modifier was parsed, a single dollar
     32  1.4  rillig # before the '=' was parsed (but not interpreted) as an anchor.
     33  1.4  rillig # Parsing something without then evaluating it accordingly doesn't make
     34  1.4  rillig # sense.
     35  1.4  rillig .if ${value:L:e$=x} != "value"
     36  1.4  rillig .  error
     37  1.4  rillig .endif
     38  1.4  rillig # Before 2020-07-20, the modifier ":e$=x" was parsed as having a left-hand
     39  1.4  rillig # side "e" and a right-hand side "x".  The dollar was parsed (but not
     40  1.4  rillig # interpreted) as 'anchor at the end'.  Therefore the modifier was equivalent
     41  1.4  rillig # to ":e=x", which doesn't match the string "value$".  Therefore the whole
     42  1.4  rillig # expression evaluated to "value$".
     43  1.4  rillig .if ${${:Uvalue\$}:L:e$=x} != "valux"
     44  1.4  rillig .  error
     45  1.4  rillig .endif
     46  1.4  rillig .if ${value:L:e=x} != "valux"
     47  1.4  rillig .  error
     48  1.4  rillig .endif
     49  1.3  rillig 
     50  1.3  rillig # Words that don't match are copied unmodified.
     51  1.4  rillig .if ${:Ufile.c file.h:%.c=%.cpp} != "file.cpp file.h"
     52  1.4  rillig .  error
     53  1.4  rillig .endif
     54  1.4  rillig 
     55  1.4  rillig # The % placeholder can be anywhere in the string, it doesn't have to be at
     56  1.4  rillig # the beginning of the pattern.
     57  1.4  rillig .if ${:Ufile.c other.c:file.%=renamed.%} != "renamed.c other.c"
     58  1.4  rillig .  error
     59  1.4  rillig .endif
     60  1.3  rillig 
     61  1.3  rillig # Trying to cover all possible variants of the SysV modifier.
     62  1.3  rillig LIST=	one two
     63  1.4  rillig 
     64  1.4  rillig .if ${LIST:o=X} != "one twX"
     65  1.4  rillig .  error
     66  1.4  rillig .endif
     67  1.4  rillig .if ${LIST:o=} != "one tw"
     68  1.4  rillig .  error
     69  1.4  rillig .endif
     70  1.4  rillig .if ${LIST:o=%} != "one tw%"
     71  1.4  rillig .  error
     72  1.4  rillig .endif
     73  1.4  rillig .if ${LIST:%o=X} != "one X"
     74  1.4  rillig .  error
     75  1.4  rillig .endif
     76  1.4  rillig .if ${LIST:o%=X} != "X two"
     77  1.4  rillig .  error
     78  1.4  rillig .endif
     79  1.4  rillig .if ${LIST:o%e=X} != "X two"
     80  1.4  rillig .  error
     81  1.4  rillig .endif
     82  1.4  rillig .if ${LIST:o%%e=X} != "one two"	# Only the first '%' is the wildcard.
     83  1.4  rillig .  error
     84  1.4  rillig .endif
     85  1.4  rillig .if ${LIST:%=%%} != "one% two%"	# None of the words contains a literal '%'.
     86  1.4  rillig .  error
     87  1.4  rillig .endif
     88  1.4  rillig .if ${LIST:%nes=%xxx} != "one two" # lhs is longer than the word "one"
     89  1.4  rillig .  error
     90  1.3  rillig .endif
     91