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