Home | History | Annotate | Line # | Download | only in unit-tests
cond-token-var.mk revision 1.6
      1  1.6  rillig # $NetBSD: cond-token-var.mk,v 1.6 2021/04/25 21:05:38 rillig Exp $
      2  1.1  rillig #
      3  1.5  rillig # Tests for variable expressions in .if conditions.
      4  1.5  rillig #
      5  1.5  rillig # Note the fine distinction between a variable and a variable expression.
      6  1.5  rillig # A variable has a name and a value.  To access the value, one writes a
      7  1.5  rillig # variable expression of the form ${VAR}.  This is a simple variable
      8  1.5  rillig # expression.  Variable expressions can get more complicated by adding
      9  1.5  rillig # variable modifiers such as in ${VAR:Mpattern}.
     10  1.5  rillig #
     11  1.5  rillig # XXX: Strictly speaking, variable modifiers should be called expression
     12  1.5  rillig # modifiers instead since they only modify the expression, not the variable.
     13  1.5  rillig # Well, except for the assignment modifiers, these do indeed change the value
     14  1.5  rillig # of the variable.
     15  1.1  rillig 
     16  1.3  rillig DEF=	defined
     17  1.1  rillig 
     18  1.3  rillig # A defined variable may appear on either side of the comparison.
     19  1.3  rillig .if ${DEF} == ${DEF}
     20  1.4  rillig .  info ok
     21  1.3  rillig .else
     22  1.4  rillig .  error
     23  1.3  rillig .endif
     24  1.3  rillig 
     25  1.3  rillig # A variable that appears on the left-hand side must be defined.
     26  1.5  rillig # The following line thus generates a parse error.
     27  1.3  rillig .if ${UNDEF} == ${DEF}
     28  1.4  rillig .  error
     29  1.3  rillig .endif
     30  1.3  rillig 
     31  1.3  rillig # A variable that appears on the right-hand side must be defined.
     32  1.5  rillig # The following line thus generates a parse error.
     33  1.3  rillig .if ${DEF} == ${UNDEF}
     34  1.4  rillig .  error
     35  1.3  rillig .endif
     36  1.3  rillig 
     37  1.3  rillig # A defined variable may appear as an expression of its own.
     38  1.3  rillig .if ${DEF}
     39  1.3  rillig .endif
     40  1.3  rillig 
     41  1.5  rillig # An undefined variable on its own generates a parse error.
     42  1.3  rillig .if ${UNDEF}
     43  1.3  rillig .endif
     44  1.3  rillig 
     45  1.5  rillig # The :U modifier turns an undefined expression into a defined expression.
     46  1.5  rillig # Since the expression is defined now, it doesn't generate any parse error.
     47  1.3  rillig .if ${UNDEF:U}
     48  1.3  rillig .endif
     49  1.6  rillig 
     50  1.6  rillig # If the value of the variable expression is a number, it is compared against
     51  1.6  rillig # zero.
     52  1.6  rillig .if ${:U0}
     53  1.6  rillig .  error
     54  1.6  rillig .endif
     55  1.6  rillig .if !${:U1}
     56  1.6  rillig .  error
     57  1.6  rillig .endif
     58  1.6  rillig 
     59  1.6  rillig # If the value of the variable expression is not a number, any non-empty
     60  1.6  rillig # value evaluates to true, even if there is only whitespace.
     61  1.6  rillig .if ${:U}
     62  1.6  rillig .  error
     63  1.6  rillig .endif
     64  1.6  rillig .if !${:U }
     65  1.6  rillig .  error
     66  1.6  rillig .endif
     67  1.6  rillig .if !${:Uanything}
     68  1.6  rillig .  error
     69  1.6  rillig .endif
     70