Module Name: src Committed By: rillig Date: Wed Jun 28 06:15:42 UTC 2023
Modified Files: src/usr.bin/make/unit-tests: cond-func-empty.exp cond-func-empty.mk Log Message: tests/make: extend test for the 'empty' function in conditions To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/usr.bin/make/unit-tests/cond-func-empty.exp cvs rdiff -u -r1.20 -r1.21 src/usr.bin/make/unit-tests/cond-func-empty.mk Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/make/unit-tests/cond-func-empty.exp diff -u src/usr.bin/make/unit-tests/cond-func-empty.exp:1.6 src/usr.bin/make/unit-tests/cond-func-empty.exp:1.7 --- src/usr.bin/make/unit-tests/cond-func-empty.exp:1.6 Thu Jun 1 20:56:35 2023 +++ src/usr.bin/make/unit-tests/cond-func-empty.exp Wed Jun 28 06:15:42 2023 @@ -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 Index: src/usr.bin/make/unit-tests/cond-func-empty.mk diff -u src/usr.bin/make/unit-tests/cond-func-empty.mk:1.20 src/usr.bin/make/unit-tests/cond-func-empty.mk:1.21 --- src/usr.bin/make/unit-tests/cond-func-empty.mk:1.20 Thu Jun 1 20:56:35 2023 +++ src/usr.bin/make/unit-tests/cond-func-empty.mk Wed Jun 28 06:15:42 2023 @@ -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.