cond-op-and.mk revision 1.9 1 # $NetBSD: cond-op-and.mk,v 1.9 2023/12/17 09:44:00 rillig Exp $
2 #
3 # Tests for the && operator in .if conditions.
4
5 .if 0 && 0
6 . error
7 .endif
8
9 .if 1 && 0
10 . error
11 .endif
12
13 .if 0 && 1
14 . error
15 .endif
16
17 .if !(1 && 1)
18 . error
19 .endif
20
21
22 # The right-hand side is not evaluated since the left-hand side is already
23 # false.
24 .if 0 && ${UNDEF}
25 .endif
26
27 # When an outer condition makes the inner '&&' condition irrelevant, neither
28 # of its operands must be evaluated.
29 #
30 .if 1 || (${UNDEF} && ${UNDEF})
31 .endif
32
33 # Test combinations of outer '||' with inner '&&', to ensure that the operands
34 # of the inner '&&' are only evaluated if necessary.
35 DEF= defined
36 # expect+1: Malformed conditional (0 || (${DEF} && ${UNDEF}))
37 .if 0 || (${DEF} && ${UNDEF})
38 .endif
39 .if 0 || (!${DEF} && ${UNDEF})
40 .endif
41 # expect+1: Malformed conditional (0 || (${UNDEF} && ${UNDEF}))
42 .if 0 || (${UNDEF} && ${UNDEF})
43 .endif
44 # expect+1: Malformed conditional (0 || (!${UNDEF} && ${UNDEF}))
45 .if 0 || (!${UNDEF} && ${UNDEF})
46 .endif
47 .if 1 || (${DEF} && ${UNDEF})
48 .endif
49 .if 1 || (!${DEF} && ${UNDEF})
50 .endif
51 .if 1 || (${UNDEF} && ${UNDEF})
52 .endif
53 .if 1 || (!${UNDEF} && ${UNDEF})
54 .endif
55
56
57 # The && operator may be abbreviated as &. This is not widely known though
58 # and is also not documented in the manual page.
59
60 .if 0 & 0
61 . error
62 .endif
63 .if 1 & 0
64 . error
65 .endif
66 .if 0 & 1
67 . error
68 .endif
69 .if !(1 & 1)
70 . error
71 .endif
72
73 # There is no operator &&&.
74 # expect+1: Malformed conditional (0 &&& 0)
75 .if 0 &&& 0
76 . error
77 .endif
78
79 # The '&&' operator must be preceded by whitespace, otherwise it becomes part
80 # of the preceding bare word. The condition is parsed as '"1&&" != "" && 1'.
81 .if 1&& && 1
82 .else
83 . error
84 .endif
85