]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/bmake/unit-tests/cond-op.mk
Update to bmake-20200902
[FreeBSD/FreeBSD.git] / contrib / bmake / unit-tests / cond-op.mk
1 # $NetBSD: cond-op.mk,v 1.4 2020/08/28 14:07:51 rillig Exp $
2 #
3 # Tests for operators like &&, ||, ! in .if conditions.
4 #
5 # See also:
6 #       cond-op-and.mk
7 #       cond-op-not.mk
8 #       cond-op-or.mk
9 #       cond-op-parentheses.mk
10
11 # In make, && binds more tightly than ||, like in C.
12 # If make had the same precedence for both && and ||, the result would be
13 # different.
14 # If || were to bind more tightly than &&, the result would be different
15 # as well.
16 .if !(1 || 1 && 0)
17 .error
18 .endif
19
20 # If make were to interpret the && and || operators like the shell, the
21 # implicit binding would be this:
22 .if (1 || 1) && 0
23 .error
24 .endif
25
26 # The precedence of the ! operator is different from C though. It has a
27 # lower precedence than the comparison operators.
28 .if !"word" == "word"
29 .error
30 .endif
31
32 # This is how the above condition is actually interpreted.
33 .if !("word" == "word")
34 .error
35 .endif
36
37 # TODO: Demonstrate that the precedence of the ! and == operators actually
38 # makes a difference.  There is a simple example for sure, I just cannot
39 # wrap my head around it.
40
41 # This condition is malformed because the '!' on the right-hand side must not
42 # appear unquoted.  If any, it must be enclosed in quotes.
43 # In any case, it is not interpreted as a negation of an unquoted string.
44 # See CondGetString.
45 .if "!word" == !word
46 .error
47 .endif
48
49 # Surprisingly, the ampersand and pipe are allowed in bare strings.
50 # That's another opportunity for writing confusing code.
51 # See CondGetString, which only has '!' in the list of stop characters.
52 .if "a&&b||c" != a&&b||c
53 .error
54 .endif
55
56 # Just in case that parsing should ever stop on the first error.
57 .info Parsing continues until here.
58
59 all:
60         @:;