aboutsummaryrefslogtreecommitdiff
path: root/contrib/bmake/unit-tests/cond-op-or.mk
blob: 165408f3c1301862b70121c9b2c085c07625095d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# $NetBSD: cond-op-or.mk,v 1.11 2023/12/17 09:44:00 rillig Exp $
#
# Tests for the || operator in .if conditions.

.if 0 || 0
.  error
.endif

.if !(1 || 0)
.  error
.endif

.if !(0 || 1)
.  error
.endif

.if !(1 || 1)
.  error
.endif


# The right-hand side is not evaluated since the left-hand side is already
# true.
.if 1 || ${UNDEF}
.endif

# When an outer condition makes the inner '||' condition irrelevant, neither
# of its operands must be evaluated.  This had been wrong in cond.c 1.283 from
# 2021-12-09 and was reverted in cond.c 1.284 an hour later.
.if 0 && (!defined(UNDEF) || ${UNDEF})
.endif

# Test combinations of outer '&&' with inner '||', to ensure that the operands
# of the inner '||' is only evaluated if necessary.
DEF=	defined
.if 0 && (${DEF} || ${UNDEF})
.endif
.if 0 && (!${DEF} || ${UNDEF})
.endif
.if 0 && (${UNDEF} || ${UNDEF})
.endif
.if 0 && (!${UNDEF} || ${UNDEF})
.endif
.if 1 && (${DEF} || ${UNDEF})
.endif
# expect+1: Malformed conditional (1 && (!${DEF} || ${UNDEF}))
.if 1 && (!${DEF} || ${UNDEF})
.endif
# expect+1: Malformed conditional (1 && (${UNDEF} || ${UNDEF}))
.if 1 && (${UNDEF} || ${UNDEF})
.endif
# expect+1: Malformed conditional (1 && (!${UNDEF} || ${UNDEF}))
.if 1 && (!${UNDEF} || ${UNDEF})
.endif


# The || operator may be abbreviated as |.  This is not widely known though
# and is also not documented in the manual page.

.if 0 | 0
.  error
.endif
.if !(1 | 0)
.  error
.endif
.if !(0 | 1)
.  error
.endif
.if !(1 | 1)
.  error
.endif

# There is no operator |||.
# expect+1: Malformed conditional (0 ||| 0)
.if 0 ||| 0
.  error
.endif

# The '||' operator must be preceded by whitespace, otherwise it becomes part
# of the preceding bare word.  The condition is parsed as '"1||" != "" || 0'.
.if 1|| || 0
.else
.  error
.endif