Home | History | Annotate | Line # | Download | only in unit-tests
cond-cmp-string.mk revision 1.9
      1 # $NetBSD: cond-cmp-string.mk,v 1.9 2020/10/30 14:46:01 rillig Exp $
      2 #
      3 # Tests for string comparisons in .if conditions.
      4 
      5 # This is a simple comparison of string literals.
      6 # Nothing surprising here.
      7 .if "str" != "str"
      8 .  error
      9 .endif
     10 
     11 # The right-hand side of the comparison may be written without quotes.
     12 .if "str" != str
     13 .  error
     14 .endif
     15 
     16 # The left-hand side of the comparison must be enclosed in quotes.
     17 # This one is not enclosed in quotes and thus generates an error message.
     18 .if str != str
     19 .  error
     20 .endif
     21 
     22 # The left-hand side of the comparison requires a defined variable.
     23 # The variable named "" is not defined, but applying the :U modifier to it
     24 # makes it "kind of defined" (see VAR_KEEP).  Therefore it is ok here.
     25 .if ${:Ustr} != "str"
     26 .  error
     27 .endif
     28 
     29 # Any character in a string literal may be escaped using a backslash.
     30 # This means that "\n" does not mean a newline but a simple "n".
     31 .if "string" != "\s\t\r\i\n\g"
     32 .  error
     33 .endif
     34 
     35 # It is not possible to concatenate two string literals to form a single
     36 # string.
     37 .if "string" != "str""ing"
     38 .  error
     39 .endif
     40 
     41 # There is no = operator for strings.
     42 .if !("value" = "value")
     43 .  error
     44 .else
     45 .  error
     46 .endif
     47 
     48 # There is no === operator for strings either.
     49 .if !("value" === "value")
     50 .  error
     51 .else
     52 .  error
     53 .endif
     54 
     55 # A variable expression can be enclosed in double quotes.
     56 .if ${:Uword} != "${:Uword}"
     57 .  error
     58 .endif
     59 
     60 # XXX: As of 2020-10-30, adding literal characters to the string results
     61 # in a parse error.  This is a bug and should have been caught much earlier.
     62 # I wonder since when it exists.
     63 .if ${:Uword} != "${:Uword} "
     64 .  error
     65 .else
     66 .  error
     67 .endif
     68 
     69 # Some other characters work though, and some don't.
     70 # Those that are mentioned in is_separator don't work.
     71 .if ${:Uword0} != "${:Uword}0"
     72 .  error
     73 .endif
     74 .if ${:Uword&} != "${:Uword}&"
     75 .  error
     76 .endif
     77 .if ${:Uword!} != "${:Uword}!"
     78 .  error
     79 .endif
     80 .if ${:Uword<} != "${:Uword}<"
     81 .  error
     82 .endif
     83 
     84 # Adding another variable expression to the string literal works though.
     85 .if ${:Uword} != "${:Uwo}${:Urd}"
     86 .  error
     87 .endif
     88 
     89 # Adding a space at the beginning of the quoted variable expression works
     90 # though.
     91 .if ${:U word } != " ${:Uword} "
     92 .  error
     93 .endif
     94