Home | History | Annotate | Line # | Download | only in unit-tests
cond-op-and.mk revision 1.9.2.1
      1  1.9.2.1  perseant # $NetBSD: cond-op-and.mk,v 1.9.2.1 2025/08/02 05:58:31 perseant Exp $
      2      1.1    rillig #
      3      1.2    rillig # Tests for the && operator in .if conditions.
      4      1.1    rillig 
      5      1.3    rillig .if 0 && 0
      6      1.5    rillig .  error
      7      1.3    rillig .endif
      8      1.3    rillig 
      9      1.3    rillig .if 1 && 0
     10      1.5    rillig .  error
     11      1.3    rillig .endif
     12      1.3    rillig 
     13      1.3    rillig .if 0 && 1
     14      1.5    rillig .  error
     15      1.3    rillig .endif
     16      1.3    rillig 
     17      1.3    rillig .if !(1 && 1)
     18      1.5    rillig .  error
     19      1.3    rillig .endif
     20      1.3    rillig 
     21      1.6    rillig 
     22      1.3    rillig # The right-hand side is not evaluated since the left-hand side is already
     23      1.3    rillig # false.
     24      1.3    rillig .if 0 && ${UNDEF}
     25      1.3    rillig .endif
     26      1.1    rillig 
     27      1.6    rillig # When an outer condition makes the inner '&&' condition irrelevant, neither
     28  1.9.2.1  perseant # of its operands is evaluated.
     29      1.6    rillig .if 1 || (${UNDEF} && ${UNDEF})
     30      1.6    rillig .endif
     31      1.6    rillig 
     32      1.6    rillig # Test combinations of outer '||' with inner '&&', to ensure that the operands
     33      1.6    rillig # of the inner '&&' are only evaluated if necessary.
     34      1.6    rillig DEF=	defined
     35  1.9.2.1  perseant # expect+1: Variable "UNDEF" is undefined
     36      1.6    rillig .if 0 || (${DEF} && ${UNDEF})
     37      1.6    rillig .endif
     38      1.6    rillig .if 0 || (!${DEF} && ${UNDEF})
     39      1.6    rillig .endif
     40  1.9.2.1  perseant # expect+1: Variable "UNDEF" is undefined
     41      1.6    rillig .if 0 || (${UNDEF} && ${UNDEF})
     42      1.6    rillig .endif
     43  1.9.2.1  perseant # expect+1: Variable "UNDEF" is undefined
     44      1.6    rillig .if 0 || (!${UNDEF} && ${UNDEF})
     45      1.6    rillig .endif
     46      1.6    rillig .if 1 || (${DEF} && ${UNDEF})
     47      1.6    rillig .endif
     48      1.6    rillig .if 1 || (!${DEF} && ${UNDEF})
     49      1.6    rillig .endif
     50      1.6    rillig .if 1 || (${UNDEF} && ${UNDEF})
     51      1.6    rillig .endif
     52      1.6    rillig .if 1 || (!${UNDEF} && ${UNDEF})
     53      1.6    rillig .endif
     54      1.6    rillig 
     55      1.6    rillig 
     56      1.4    rillig # The && operator may be abbreviated as &.  This is not widely known though
     57      1.4    rillig # and is also not documented in the manual page.
     58      1.4    rillig 
     59  1.9.2.1  perseant # expect+1: Unknown operator "&"
     60      1.4    rillig .if 0 & 0
     61      1.4    rillig .  error
     62  1.9.2.1  perseant .else
     63  1.9.2.1  perseant .  error
     64      1.4    rillig .endif
     65  1.9.2.1  perseant # expect+1: Unknown operator "&"
     66      1.4    rillig .if 1 & 0
     67      1.4    rillig .  error
     68  1.9.2.1  perseant .else
     69  1.9.2.1  perseant .  error
     70      1.4    rillig .endif
     71  1.9.2.1  perseant # expect+1: Unknown operator "&"
     72      1.4    rillig .if 0 & 1
     73      1.4    rillig .  error
     74  1.9.2.1  perseant .else
     75  1.9.2.1  perseant .  error
     76      1.4    rillig .endif
     77  1.9.2.1  perseant # expect+1: Unknown operator "&"
     78      1.4    rillig .if !(1 & 1)
     79      1.4    rillig .  error
     80  1.9.2.1  perseant .else
     81  1.9.2.1  perseant .  error
     82      1.4    rillig .endif
     83      1.4    rillig 
     84  1.9.2.1  perseant # There is no operator '&&&'.  The first two '&&' form an operator, the third
     85  1.9.2.1  perseant # '&' forms the next (incomplete) token.
     86  1.9.2.1  perseant # expect+1: Unknown operator "&"
     87      1.4    rillig .if 0 &&& 0
     88      1.4    rillig .  error
     89  1.9.2.1  perseant .else
     90  1.9.2.1  perseant .  error
     91      1.4    rillig .endif
     92      1.4    rillig 
     93      1.8    rillig # The '&&' operator must be preceded by whitespace, otherwise it becomes part
     94  1.9.2.1  perseant # of the preceding bare word.  The condition starts with a digit and is thus
     95  1.9.2.1  perseant # parsed as '"1&&" != "" && 1'.
     96      1.8    rillig .if 1&& && 1
     97      1.8    rillig .else
     98      1.8    rillig .  error
     99      1.8    rillig .endif
    100