Home | History | Annotate | Line # | Download | only in unit-tests
cond-token-plain.mk revision 1.4
      1 # $NetBSD: cond-token-plain.mk,v 1.4 2020/09/12 17:47:24 rillig Exp $
      2 #
      3 # Tests for plain tokens (that is, string literals without quotes)
      4 # in .if conditions.
      5 
      6 .MAKEFLAGS: -dc
      7 
      8 .if ${:Uvalue} != value
      9 .  error
     10 .endif
     11 
     12 # Malformed condition since comment parsing is done in an early phase
     13 # and removes the '#' and everything behind it long before the condition
     14 # parser gets to see it.
     15 #
     16 # XXX: The error message is missing for this malformed condition.
     17 # The right-hand side of the comparison is just a '"'.
     18 .if ${:U} != "#hash"
     19 .  error
     20 .endif
     21 
     22 # To get a '#' into a condition, it has to be escaped using a backslash.
     23 # This prevents the comment parser from removing it, and in turn, it becomes
     24 # visible to CondParser_String.
     25 .if ${:U\#hash} != "\#hash"
     26 .  error
     27 .endif
     28 
     29 # Since 2002-12-30, and still as of 2020-09-11, CondParser_Token handles
     30 # the '#' specially, even though at this point, there should be no need for
     31 # comment handling anymore.  The comments are supposed to be stripped off
     32 # in a very early parsing phase.
     33 #
     34 # XXX: Missing error message for the malformed condition. The right-hand
     35 # side is double-quotes, backslash, backslash.
     36 # XXX: It is unexpected that the right-hand side evaluates to a single
     37 # backslash.
     38 .if ${:U\\} != "\\#hash"
     39 .  error
     40 .endif
     41 
     42 # The right-hand side of a comparison is not parsed as a token, therefore
     43 # the code from CondParser_Token does not apply to it.
     44 .if ${:U\#hash} != \#hash
     45 .  error
     46 .endif
     47 
     48 # XXX: What is the purpose of treating an escaped '#' in the following
     49 # condition as a comment?  And why only at the beginning of a token,
     50 # just as in the shell?
     51 .if 0 \# This is treated as a comment, but why?
     52 .  error
     53 .endif
     54 
     55 # Ah, ok, this can be used to add an end-of-condition comment.  But does
     56 # anybody really use this?  This is neither documented nor obvious since
     57 # the '#' is escaped.  It's much clearer to write a comment in the line
     58 # above the condition.
     59 .if ${0 \# comment :?yes:no} != no
     60 .  error
     61 .endif
     62 .if ${1 \# comment :?yes:no} != yes
     63 .  error
     64 .endif
     65 
     66 # Usually there is whitespace around the comparison operator, but this is
     67 # not required.
     68 .if ${UNDEF:Uundefined}!=undefined
     69 .  error
     70 .endif
     71 .if ${UNDEF:U12345}>12345
     72 .  error
     73 .endif
     74 .if ${UNDEF:U12345}<12345
     75 .  error
     76 .endif
     77 .if (${UNDEF:U0})||0
     78 .  error
     79 .endif
     80 
     81 # Only the comparison operator terminates the comparison operand, and it's
     82 # a coincidence that the '!' is both used in the '!=' comparison operator
     83 # as well as for negating a comparison result.
     84 #
     85 # The boolean operators '&' and '|' don't terminate a comparison operand.
     86 .if ${:Uvar}&&name != "var&&name"
     87 .  error
     88 .endif
     89 .if ${:Uvar}||name != "var||name"
     90 .  error
     91 .endif
     92 
     93 all:
     94 	@:;
     95