Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make/unit-tests tests/make: extend test for the 'emp...



details:   https://anonhg.NetBSD.org/src/rev/3e11026174ee
branches:  trunk
changeset: 376675:3e11026174ee
user:      rillig <rillig%NetBSD.org@localhost>
date:      Wed Jun 28 06:15:42 2023 +0000

description:
tests/make: extend test for the 'empty' function in conditions

diffstat:

 usr.bin/make/unit-tests/cond-func-empty.exp |   4 +-
 usr.bin/make/unit-tests/cond-func-empty.mk  |  36 ++++++++++++++++++++--------
 2 files changed, 27 insertions(+), 13 deletions(-)

diffs (98 lines):

diff -r 10bcc0b98c36 -r 3e11026174ee usr.bin/make/unit-tests/cond-func-empty.exp
--- a/usr.bin/make/unit-tests/cond-func-empty.exp       Wed Jun 28 06:15:07 2023 +0000
+++ b/usr.bin/make/unit-tests/cond-func-empty.exp       Wed Jun 28 06:15:42 2023 +0000
@@ -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 -r 10bcc0b98c36 -r 3e11026174ee usr.bin/make/unit-tests/cond-func-empty.mk
--- a/usr.bin/make/unit-tests/cond-func-empty.mk        Wed Jun 28 06:15:07 2023 +0000
+++ b/usr.bin/make/unit-tests/cond-func-empty.mk        Wed Jun 28 06:15:42 2023 +0000
@@ -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 @@ WORD=       word
 .  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 @@ WORD=     word
 # 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 @@ WORD=       word
 # 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.



Home | Main Index | Thread Index | Old Index