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