xref: /freebsd/contrib/bmake/unit-tests/cond-op-or.mk (revision a8c56be47166295d37600ff81fc1857db87b3a9b)
1*a8c56be4SSimon J. Gerraty# $NetBSD: cond-op-or.mk,v 1.15 2025/06/28 22:39:28 rillig Exp $
22c3632d1SSimon J. Gerraty#
32c3632d1SSimon J. Gerraty# Tests for the || operator in .if conditions.
42c3632d1SSimon J. Gerraty
52c3632d1SSimon J. Gerraty.if 0 || 0
62c3632d1SSimon J. Gerraty.  error
72c3632d1SSimon J. Gerraty.endif
82c3632d1SSimon J. Gerraty
92c3632d1SSimon J. Gerraty.if !(1 || 0)
102c3632d1SSimon J. Gerraty.  error
112c3632d1SSimon J. Gerraty.endif
122c3632d1SSimon J. Gerraty
132c3632d1SSimon J. Gerraty.if !(0 || 1)
142c3632d1SSimon J. Gerraty.  error
152c3632d1SSimon J. Gerraty.endif
162c3632d1SSimon J. Gerraty
172c3632d1SSimon J. Gerraty.if !(1 || 1)
182c3632d1SSimon J. Gerraty.  error
192c3632d1SSimon J. Gerraty.endif
202c3632d1SSimon J. Gerraty
2112904384SSimon J. Gerraty
222c3632d1SSimon J. Gerraty# The right-hand side is not evaluated since the left-hand side is already
232c3632d1SSimon J. Gerraty# true.
242c3632d1SSimon J. Gerraty.if 1 || ${UNDEF}
252c3632d1SSimon J. Gerraty.endif
262c3632d1SSimon J. Gerraty
2712904384SSimon J. Gerraty# When an outer condition makes the inner '||' condition irrelevant, neither
2822619282SSimon J. Gerraty# of its operands is evaluated.
2912904384SSimon J. Gerraty.if 0 && (!defined(UNDEF) || ${UNDEF})
3012904384SSimon J. Gerraty.endif
3112904384SSimon J. Gerraty
3212904384SSimon J. Gerraty# Test combinations of outer '&&' with inner '||', to ensure that the operands
3322619282SSimon J. Gerraty# of the inner '||' are only evaluated if necessary.
3412904384SSimon J. GerratyDEF=	defined
356a7405f5SSimon J. Gerraty# expect+1: Variable "UNDEF" is undefined
3622619282SSimon J. Gerraty.if 1 && (!${DEF} || ${UNDEF})
3712904384SSimon J. Gerraty.endif
3812904384SSimon J. Gerraty.if 1 && (${DEF} || ${UNDEF})
3912904384SSimon J. Gerraty.endif
406a7405f5SSimon J. Gerraty# expect+1: Variable "UNDEF" is undefined
4122619282SSimon J. Gerraty.if 1 && (!${UNDEF} || ${UNDEF})
4212904384SSimon J. Gerraty.endif
436a7405f5SSimon J. Gerraty# expect+1: Variable "UNDEF" is undefined
4412904384SSimon J. Gerraty.if 1 && (${UNDEF} || ${UNDEF})
4512904384SSimon J. Gerraty.endif
4622619282SSimon J. Gerraty.if 0 && (!${DEF} || ${UNDEF})
4722619282SSimon J. Gerraty.endif
4822619282SSimon J. Gerraty.if 0 && (${DEF} || ${UNDEF})
4922619282SSimon J. Gerraty.endif
5022619282SSimon J. Gerraty.if 0 && (!${UNDEF} || ${UNDEF})
5122619282SSimon J. Gerraty.endif
5222619282SSimon J. Gerraty.if 0 && (${UNDEF} || ${UNDEF})
5312904384SSimon J. Gerraty.endif
5412904384SSimon J. Gerraty
5512904384SSimon J. Gerraty
56956e45f6SSimon J. Gerraty# The || operator may be abbreviated as |.  This is not widely known though
57956e45f6SSimon J. Gerraty# and is also not documented in the manual page.
58956e45f6SSimon J. Gerraty
59*a8c56be4SSimon J. Gerraty# expect+1: Unknown operator "|"
60956e45f6SSimon J. Gerraty.if 0 | 0
61956e45f6SSimon J. Gerraty.  error
6222619282SSimon J. Gerraty.else
6322619282SSimon J. Gerraty.  error
64956e45f6SSimon J. Gerraty.endif
65*a8c56be4SSimon J. Gerraty# expect+1: Unknown operator "|"
66956e45f6SSimon J. Gerraty.if !(1 | 0)
67956e45f6SSimon J. Gerraty.  error
6822619282SSimon J. Gerraty.else
69956e45f6SSimon J. Gerraty.  error
70956e45f6SSimon J. Gerraty.endif
71*a8c56be4SSimon J. Gerraty# expect+1: Unknown operator "|"
7222619282SSimon J. Gerraty.if !(0 | 1)
7322619282SSimon J. Gerraty.  error
7422619282SSimon J. Gerraty.else
7522619282SSimon J. Gerraty.  error
7622619282SSimon J. Gerraty.endif
77*a8c56be4SSimon J. Gerraty# expect+1: Unknown operator "|"
78956e45f6SSimon J. Gerraty.if !(1 | 1)
79956e45f6SSimon J. Gerraty.  error
8022619282SSimon J. Gerraty.else
8122619282SSimon J. Gerraty.  error
82956e45f6SSimon J. Gerraty.endif
83956e45f6SSimon J. Gerraty
8422619282SSimon J. Gerraty# There is no operator '|||'.  The first two '||' form an operator, the third
8522619282SSimon J. Gerraty# '|' forms the next (incomplete) token.
86*a8c56be4SSimon J. Gerraty# expect+1: Unknown operator "|"
87956e45f6SSimon J. Gerraty.if 0 ||| 0
88956e45f6SSimon J. Gerraty.  error
8922619282SSimon J. Gerraty.else
9022619282SSimon J. Gerraty.  error
91956e45f6SSimon J. Gerraty.endif
92956e45f6SSimon J. Gerraty
9398875883SSimon J. Gerraty# The '||' operator must be preceded by whitespace, otherwise it becomes part
9422619282SSimon J. Gerraty# of the preceding bare word.  The condition starts with a digit and is thus
9522619282SSimon J. Gerraty# parsed as '"0||" != "" || 0'.
9622619282SSimon J. Gerraty.if 0|| || 0
9798875883SSimon J. Gerraty.else
9898875883SSimon J. Gerraty.  error
9998875883SSimon J. Gerraty.endif
100