1 # $NetBSD: cond-short.mk,v 1.7 2020/07/09 22:34:09 sjg Exp $
3 # Demonstrates that in conditions, the right-hand side of an && or ||
4 # is only evaluated if it can actually influence the result.
6 # Between 2015-10-11 and 2020-06-28, the right-hand side of an && or ||
7 # operator was always evaluated, which was wrong.
12 .if 0 && ${echo "unexpected and" 1>&2 :L:sh}
15 .if 1 && ${echo "expected and" 1>&2 :L:sh}
18 .if 0 && exists(nonexistent${echo "unexpected and exists" 1>&2 :L:sh})
21 .if 1 && exists(nonexistent${echo "expected and exists" 1>&2 :L:sh})
24 .if 0 && empty(${echo "unexpected and empty" 1>&2 :L:sh})
27 .if 1 && empty(${echo "expected and empty" 1>&2 :L:sh})
30 # "VAR U11" is not evaluated; it was evaluated before 2020-07-02.
31 # The whole !empty condition is only parsed and then discarded.
32 VAR= ${VAR${:U11${echo "unexpected VAR U11" 1>&2 :L:sh}}}
33 VAR13= ${VAR${:U12${echo "unexpected VAR13" 1>&2 :L:sh}}}
34 .if 0 && !empty(VAR${:U13${echo "unexpected U13 condition" 1>&2 :L:sh}})
37 VAR= ${VAR${:U21${echo "unexpected VAR U21" 1>&2 :L:sh}}}
38 VAR23= ${VAR${:U22${echo "expected VAR23" 1>&2 :L:sh}}}
39 .if 1 && !empty(VAR${:U23${echo "expected U23 condition" 1>&2 :L:sh}})
41 VAR= # empty again, for the following tests
43 # The :M modifier is only parsed, not evaluated.
44 # Before 2020-07-02, it was wrongly evaluated.
45 .if 0 && !empty(VAR:M${:U${echo "unexpected M pattern" 1>&2 :L:sh}})
48 .if 1 && !empty(VAR:M${:U${echo "expected M pattern" 1>&2 :L:sh}})
51 .if 0 && !empty(VAR:S,from,${:U${echo "unexpected S modifier" 1>&2 :L:sh}},)
54 .if 0 && !empty(VAR:C,from,${:U${echo "unexpected C modifier" 1>&2 :L:sh}},)
57 .if 0 && !empty("" == "" :? ${:U${echo "unexpected ? modifier" 1>&2 :L:sh}} :)
60 .if 0 && !empty(VAR:old=${:U${echo "unexpected = modifier" 1>&2 :L:sh}})
63 .if 0 && !empty(1 2 3:L:@var@${:U${echo "unexpected @ modifier" 1>&2 :L:sh}}@)
66 .if 0 && !empty(:U${:!echo "unexpected exclam modifier" 1>&2 !})
71 .if 1 || ${echo "unexpected or" 1>&2 :L:sh}
74 .if 0 || ${echo "expected or" 1>&2 :L:sh}
77 .if 1 || exists(nonexistent${echo "unexpected or exists" 1>&2 :L:sh})
80 .if 0 || exists(nonexistent${echo "expected or exists" 1>&2 :L:sh})
83 .if 1 || empty(${echo "unexpected or empty" 1>&2 :L:sh})
86 .if 0 || empty(${echo "expected or empty" 1>&2 :L:sh})
89 # Unreachable nested conditions are skipped completely as well.
92 . if ${echo "unexpected nested and" 1>&2 :L:sh}
97 .elif ${echo "unexpected nested or" 1>&2 :L:sh}
100 # make sure these do not cause complaint
107 .if defined(V42) && ${V42} > 0
112 x!= echo 'defined(V42) && ${V42} > 0: $x' >&2; echo
113 # this one throws both String comparison operator and
114 # Malformed conditional with cond.c 1.78
115 # indirect iV2 would expand to "" and treated as 0
116 .if defined(V66) && ( ${iV2} < ${V42} )
121 x!= echo 'defined(V66) && ( "${iV2}" < ${V42} ): $x' >&2; echo
122 # next two thow String comparison operator with cond.c 1.78
123 # indirect iV1 would expand to 42
124 .if 1 || ${iV1} < ${V42}
129 x!= echo '1 || ${iV1} < ${V42}: $x' >&2; echo
130 .if 1 || ${iV2:U2} < ${V42}
135 x!= echo '1 || ${iV2:U2} < ${V42}: $x' >&2; echo
136 # the same expressions are fine when the lhs is expanded
137 # ${iV1} expands to 42
138 .if 0 || ${iV1} <= ${V42}
143 x!= echo '0 || ${iV1} <= ${V42}: $x' >&2; echo
144 # ${iV2:U2} expands to 2
145 .if 0 || ${iV2:U2} < ${V42}
150 x!= echo '0 || ${iV2:U2} < ${V42}: $x' >&2; echo