diff options
| author | rillig <rillig@NetBSD.org> | 2023-06-28 06:15:42 +0000 |
|---|---|---|
| committer | rillig <rillig@NetBSD.org> | 2023-06-28 06:15:42 +0000 |
| commit | 096a7424c6d17d158d45cb9541e1d619d5536030 (patch) | |
| tree | 147a3ff76553047ece34eaa72528896601f932f2 /usr.bin/make | |
| parent | d4250aca4dc916ccf09e0d7a5654d08e41dbf911 (diff) | |
tests/make: extend test for the 'empty' function in conditions
Diffstat (limited to 'usr.bin/make')
| -rw-r--r-- | usr.bin/make/unit-tests/cond-func-empty.exp | 4 | ||||
| -rw-r--r-- | usr.bin/make/unit-tests/cond-func-empty.mk | 36 |
2 files changed, 27 insertions, 13 deletions
diff --git a/usr.bin/make/unit-tests/cond-func-empty.exp b/usr.bin/make/unit-tests/cond-func-empty.exp index 5584b406282..1d955124d1c 100644 --- a/usr.bin/make/unit-tests/cond-func-empty.exp +++ b/usr.bin/make/unit-tests/cond-func-empty.exp @@ -1,5 +1,5 @@ -make: "cond-func-empty.mk" line 154: Unclosed variable "WORD" -make: "cond-func-empty.mk" line 154: Malformed conditional (empty(WORD) +make: "cond-func-empty.mk" line 168: Unclosed variable "WORD" +make: "cond-func-empty.mk" line 168: Malformed conditional (empty(WORD) make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 diff --git a/usr.bin/make/unit-tests/cond-func-empty.mk b/usr.bin/make/unit-tests/cond-func-empty.mk index 69f489efae0..75a00dd2bd9 100644 --- a/usr.bin/make/unit-tests/cond-func-empty.mk +++ b/usr.bin/make/unit-tests/cond-func-empty.mk @@ -1,18 +1,19 @@ -# $NetBSD: cond-func-empty.mk,v 1.20 2023/06/01 20:56:35 rillig Exp $ +# $NetBSD: cond-func-empty.mk,v 1.21 2023/06/28 06:15:42 rillig Exp $ # # Tests for the empty() function in .if conditions, which tests a variable # expression for emptiness. # # Note that the argument in the parentheses is a variable name, not a variable -# expression, optionally followed by variable modifiers. +# expression. That name may be followed by ':...' modifiers. # .undef UNDEF EMPTY= # empty SPACE= ${:U } +ZERO= 0 WORD= word -# An undefined variable is empty. +# An undefined variable counts as empty. .if !empty(UNDEF) . error .endif @@ -78,6 +79,17 @@ WORD= word . error .endif +# The variable ZERO has the numeric value 0, but is not empty. This is a +# subtle difference between using either 'empty(ZERO)' or the expression +# '${ZERO}' in a condition. +.if empty(ZERO) +. error +.elif ${ZERO} +. error +.elif ${ZERO} == "" +. error +.endif + # The following example constructs an expression with the variable name "" # and the value " ". This expression counts as empty since the value contains # only whitespace. @@ -101,7 +113,9 @@ ${:U }= space . error .endif -# The value of the following expression is " word", which is not empty. +# The value of the following expression is " word", which is not empty. To be +# empty, _all_ characters in the expression value have to be whitespace, not +# only the first. .if empty(:U word) . error .endif @@ -128,15 +142,15 @@ ${:U }= space # argument are properly parsed. Typical use cases for this are .for loops, # which are expanded to exactly these ${:U} expressions. # -# If everything goes well, the argument expands to "WORD", and that variable -# is defined at the beginning of this file. The surrounding 'W' and 'D' -# ensure that CondParser_FuncCallEmpty keeps track of the parsing position, -# both before and after the call to Var_Parse. +# The argument expands to "WORD", and that variable is defined at the +# beginning of this file. The surrounding 'W' and 'D' ensure that +# CondParser_FuncCallEmpty keeps track of the parsing position, both before +# and after the call to Var_Parse. .if empty(W${:UOR}D) . error .endif -# There may be spaces at the outside of the parentheses. +# There may be spaces at the outside the parentheses. # Spaces inside the parentheses are interpreted as part of the variable name. .if ! empty ( WORD ) . error @@ -181,8 +195,8 @@ ${:U WORD }= variable name with spaces # prevent it from doing any harm. # # The variable expression was expanded though, and this was wrong. The -# expansion was done without VARE_WANTRES (called VARF_WANTRES back -# then) though. This had the effect that the ${:U1} from the value of VARNAME +# expansion was done without VARE_WANTRES (called VARF_WANTRES back then) +# though. This had the effect that the ${:U1} from the value of VARNAME # expanded to an empty string. This in turn created the seemingly recursive # definition VARNAME=${VARNAME}, and that definition was never meant to be # expanded. |
