1 1.2 rillig # $NetBSD: cond-short.mk,v 1.2 2020/06/28 11:06:26 rillig Exp $ 2 1.1 rillig # 3 1.1 rillig # Demonstrates that in conditions, the right-hand side of an && or || 4 1.2 rillig # is only evaluated if it can actually influence the result. 5 1.1 rillig # 6 1.2 rillig # Between 2015-10-11 and 2020-06-28, the right-hand side of an && or || 7 1.2 rillig # operator was always evaluated, which was wrong. 8 1.1 rillig # 9 1.2 rillig 10 1.2 rillig # The && operator. 11 1.1 rillig 12 1.1 rillig .if 0 && ${echo "unexpected and" 1>&2 :L:sh} 13 1.1 rillig .endif 14 1.1 rillig 15 1.1 rillig .if 1 && ${echo "expected and" 1>&2 :L:sh} 16 1.1 rillig .endif 17 1.1 rillig 18 1.2 rillig .if 0 && exists(nonexistent${echo "unexpected and exists" 1>&2 :L:sh}) 19 1.2 rillig .endif 20 1.2 rillig 21 1.2 rillig .if 1 && exists(nonexistent${echo "expected and exists" 1>&2 :L:sh}) 22 1.2 rillig .endif 23 1.2 rillig 24 1.2 rillig .if 0 && empty(${echo "unexpected and empty" 1>&2 :L:sh}) 25 1.2 rillig .endif 26 1.2 rillig 27 1.2 rillig .if 1 && empty(${echo "expected and empty" 1>&2 :L:sh}) 28 1.2 rillig .endif 29 1.2 rillig 30 1.2 rillig # The || operator. 31 1.2 rillig 32 1.1 rillig .if 1 || ${echo "unexpected or" 1>&2 :L:sh} 33 1.1 rillig .endif 34 1.1 rillig 35 1.1 rillig .if 0 || ${echo "expected or" 1>&2 :L:sh} 36 1.1 rillig .endif 37 1.1 rillig 38 1.2 rillig .if 1 || exists(nonexistent${echo "unexpected or exists" 1>&2 :L:sh}) 39 1.2 rillig .endif 40 1.2 rillig 41 1.2 rillig .if 0 || exists(nonexistent${echo "expected or exists" 1>&2 :L:sh}) 42 1.2 rillig .endif 43 1.2 rillig 44 1.2 rillig .if 1 || empty(${echo "unexpected or empty" 1>&2 :L:sh}) 45 1.2 rillig .endif 46 1.2 rillig 47 1.2 rillig .if 0 || empty(${echo "expected or empty" 1>&2 :L:sh}) 48 1.2 rillig .endif 49 1.2 rillig 50 1.2 rillig # Unreachable nested conditions are skipped completely as well. 51 1.1 rillig 52 1.1 rillig .if 0 53 1.1 rillig . if ${echo "unexpected nested and" 1>&2 :L:sh} 54 1.1 rillig . endif 55 1.1 rillig .endif 56 1.1 rillig 57 1.1 rillig .if 1 58 1.1 rillig .elif ${echo "unexpected nested or" 1>&2 :L:sh} 59 1.1 rillig .endif 60 1.1 rillig 61 1.1 rillig all: 62 1.1 rillig @:;: 63