Home | History | Annotate | Line # | Download | only in unit-tests
cond-short.mk revision 1.1
      1  1.1  rillig # $NetBSD: cond-short.mk,v 1.1 2020/06/28 09:42:40 rillig Exp $
      2  1.1  rillig #
      3  1.1  rillig # Demonstrates that in conditions, the right-hand side of an && or ||
      4  1.1  rillig # is evaluated even though it cannot influence the result.
      5  1.1  rillig #
      6  1.1  rillig # This is unexpected for several reasons:
      7  1.1  rillig #
      8  1.1  rillig # 1.  The manual page says: "bmake will only evaluate a conditional as
      9  1.1  rillig #     far as is necessary to determine its value."
     10  1.1  rillig #
     11  1.1  rillig # 2.  It differs from the way that these operators are evaluated in
     12  1.1  rillig #     almost all other programming languages.
     13  1.1  rillig #
     14  1.1  rillig # 3.  In cond.c there are lots of doEval variables.
     15  1.1  rillig #
     16  1.1  rillig 
     17  1.1  rillig .if 0 && ${echo "unexpected and" 1>&2 :L:sh}
     18  1.1  rillig .endif
     19  1.1  rillig 
     20  1.1  rillig .if 1 && ${echo "expected and" 1>&2 :L:sh}
     21  1.1  rillig .endif
     22  1.1  rillig 
     23  1.1  rillig .if 1 || ${echo "unexpected or" 1>&2 :L:sh}
     24  1.1  rillig .endif
     25  1.1  rillig 
     26  1.1  rillig .if 0 || ${echo "expected or" 1>&2 :L:sh}
     27  1.1  rillig .endif
     28  1.1  rillig 
     29  1.1  rillig # The following paragraphs demonstrate the workaround.
     30  1.1  rillig 
     31  1.1  rillig .if 0
     32  1.1  rillig .  if ${echo "unexpected nested and" 1>&2 :L:sh}
     33  1.1  rillig .  endif
     34  1.1  rillig .endif
     35  1.1  rillig 
     36  1.1  rillig .if 1
     37  1.1  rillig .elif ${echo "unexpected nested or" 1>&2 :L:sh}
     38  1.1  rillig .endif
     39  1.1  rillig 
     40  1.1  rillig all:
     41  1.1  rillig 	@:;:
     42