xref: /freebsd/contrib/bmake/unit-tests/cond-op-parentheses.mk (revision 13ec1e3155c7e9bf037b12af186351b7fa9b9450)
1# $NetBSD: cond-op-parentheses.mk,v 1.5 2022/01/22 21:50:41 rillig Exp $
2#
3# Tests for parentheses in .if conditions, which group expressions to override
4# the precedence of the operators '!', '&&' and '||'.  Parentheses cannot be
5# used to form arithmetic expressions such as '(3+4)' though.
6
7# Contrary to the C family of programming languages, the outermost condition
8# does not have to be enclosed in parentheses.
9.if defined(VAR)
10.  error
11.elif !1
12.  error
13.endif
14
15# Parentheses cannot enclose numbers as there is no need for it.  Make does
16# not implement any arithmetic functions in its condition parser.  If
17# absolutely necessary, use expr(1).
18# expect+1: String comparison operator must be either == or !=
19.if 3 > (2)
20.endif
21# expect+1: Malformed conditional ((3) > 2)
22.if (3) > 2
23.endif
24
25# Test for deeply nested conditions.
26.if	((((((((((((((((((((((((((((((((((((((((((((((((((((((((	\
27	((((((((((((((((((((((((((((((((((((((((((((((((((((((((	\
28	1								\
29	))))))))))))))))))))))))))))))))))))))))))))))))))))))))	\
30	))))))))))))))))))))))))))))))))))))))))))))))))))))))))
31# Parentheses can be nested at least to depth 112.  There is nothing special
32# about this number though, much higher numbers work as well, at least on
33# NetBSD.  The actual limit depends on the allowed call stack depth for C code
34# of the platform.  Anyway, 112 should be enough for all practical purposes.
35.else
36.  error
37.endif
38
39# An unbalanced opening parenthesis is a parse error.
40.if (
41.  error
42.else
43.  error
44.endif
45
46# An unbalanced closing parenthesis is a parse error.
47#
48# Before cond.c 1.237 from 2021-01-19, CondParser_Term returned TOK_RPAREN
49# even though the documentation of that function promised to only ever return
50# TOK_TRUE, TOK_FALSE or TOK_ERROR.  In cond.c 1.241, the return type of that
51# function was changed to a properly restricted enum type, to prevent this bug
52# from occurring again.
53.if )
54.  error
55.else
56.  error
57.endif
58
59all:
60	@:;
61