Module Name: src
Committed By: rillig
Date: Thu Jan 21 00:38:28 UTC 2021
Modified Files:
src/usr.bin/make/unit-tests: cond-token-plain.exp cond-token-plain.mk
cond-token-string.exp cond-token-string.mk
Log Message:
make(1): add more tests for tokens in conditionals
To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/cond-token-plain.exp \
src/usr.bin/make/unit-tests/cond-token-string.mk
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/make/unit-tests/cond-token-plain.mk
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/make/unit-tests/cond-token-string.exp
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-token-plain.exp
diff -u src/usr.bin/make/unit-tests/cond-token-plain.exp:1.3 src/usr.bin/make/unit-tests/cond-token-plain.exp:1.4
--- src/usr.bin/make/unit-tests/cond-token-plain.exp:1.3 Sat Sep 12 17:47:24 2020
+++ src/usr.bin/make/unit-tests/cond-token-plain.exp Thu Jan 21 00:38:28 2021
@@ -26,4 +26,16 @@ CondParser_Eval: ${:Uvar}&&name != "var&
lhs = "var&&name", rhs = "var&&name", op = !=
CondParser_Eval: ${:Uvar}||name != "var||name"
lhs = "var||name", rhs = "var||name", op = !=
+CondParser_Eval: bare
+make: "cond-token-plain.mk" line 102: A bare word is treated like defined(...), and the variable 'bare' is not defined.
+CondParser_Eval: VAR
+make: "cond-token-plain.mk" line 107: A bare word is treated like defined(...).
+CondParser_Eval: V${:UA}R
+make: "cond-token-plain.mk" line 114: ok
+CondParser_Eval: V${UNDEF}AR
+make: "cond-token-plain.mk" line 122: Undefined variables in bare words expand to an empty string.
+CondParser_Eval: 0${:Ux00}
+make: "cond-token-plain.mk" line 130: Numbers can be composed from literals and variable expressions.
+CondParser_Eval: 0${:Ux01}
+make: "cond-token-plain.mk" line 134: Numbers can be composed from literals and variable expressions.
exit status 0
Index: src/usr.bin/make/unit-tests/cond-token-string.mk
diff -u src/usr.bin/make/unit-tests/cond-token-string.mk:1.3 src/usr.bin/make/unit-tests/cond-token-string.mk:1.4
--- src/usr.bin/make/unit-tests/cond-token-string.mk:1.3 Tue Nov 10 22:23:37 2020
+++ src/usr.bin/make/unit-tests/cond-token-string.mk Thu Jan 21 00:38:28 2021
@@ -1,6 +1,10 @@
-# $NetBSD: cond-token-string.mk,v 1.3 2020/11/10 22:23:37 rillig Exp $
+# $NetBSD: cond-token-string.mk,v 1.4 2021/01/21 00:38:28 rillig Exp $
#
-# Tests for quoted and unquoted string literals in .if conditions.
+# Tests for quoted string literals in .if conditions.
+#
+# See also:
+# cond-token-plain.mk
+# Covers string literals without quotes (called "bare words").
# TODO: Implementation
@@ -35,5 +39,44 @@
. error
.endif
+.MAKEFLAGS: -dc
+
+# A string in quotes is checked whether it is not empty.
+.if "UNDEF"
+. info The string literal "UNDEF" is not empty.
+.else
+. error
+.endif
+
+# A space is not empty as well.
+# This differs from many other places where whitespace is trimmed.
+.if " "
+. info The string literal " " is not empty, even though it consists of $\
+ whitespace only.
+.else
+. error
+.endif
+
+.if "${UNDEF}"
+. error
+.else
+. info An undefined variable in quotes expands to an empty string, which $\
+ then evaluates to false.
+.endif
+
+.if "${:Uvalue}"
+. info A nonempty variable expression evaluates to true.
+.else
+. error
+.endif
+
+.if "${:U}"
+. error
+.else
+. info An empty variable evaluates to false.
+.endif
+
+.MAKEFLAGS: -d0
+
all:
@:;
Index: src/usr.bin/make/unit-tests/cond-token-plain.mk
diff -u src/usr.bin/make/unit-tests/cond-token-plain.mk:1.6 src/usr.bin/make/unit-tests/cond-token-plain.mk:1.7
--- src/usr.bin/make/unit-tests/cond-token-plain.mk:1.6 Sun Nov 15 14:58:14 2020
+++ src/usr.bin/make/unit-tests/cond-token-plain.mk Thu Jan 21 00:38:28 2021
@@ -1,4 +1,4 @@
-# $NetBSD: cond-token-plain.mk,v 1.6 2020/11/15 14:58:14 rillig Exp $
+# $NetBSD: cond-token-plain.mk,v 1.7 2021/01/21 00:38:28 rillig Exp $
#
# Tests for plain tokens (that is, string literals without quotes)
# in .if conditions.
@@ -93,5 +93,51 @@
. error
.endif
+# A bare word may appear alone in a condition, without any comparison
+# operator. It is implicitly converted into defined(bare).
+.if bare
+. error
+.else
+. info A bare word is treated like defined(...), and the variable $\
+ 'bare' is not defined.
+.endif
+
+VAR= defined
+.if VAR
+. info A bare word is treated like defined(...).
+.else
+. error
+.endif
+
+# Bare words may be intermixed with variable expressions.
+.if V${:UA}R
+. info ok
+.else
+. error
+.endif
+
+# In bare words, even undefined variables are allowed. Without the bare
+# words, undefined variables are not allowed. That feels inconsistent.
+.if V${UNDEF}AR
+. info Undefined variables in bare words expand to an empty string.
+.else
+. error
+.endif
+
+.if 0${:Ux00}
+. error
+.else
+. info Numbers can be composed from literals and variable expressions.
+.endif
+
+.if 0${:Ux01}
+. info Numbers can be composed from literals and variable expressions.
+.else
+. error
+.endif
+
+# See cond-token-string.mk for similar tests where the condition is enclosed
+# in "quotes".
+
all:
@:;
Index: src/usr.bin/make/unit-tests/cond-token-string.exp
diff -u src/usr.bin/make/unit-tests/cond-token-string.exp:1.4 src/usr.bin/make/unit-tests/cond-token-string.exp:1.5
--- src/usr.bin/make/unit-tests/cond-token-string.exp:1.4 Sun Dec 20 19:47:34 2020
+++ src/usr.bin/make/unit-tests/cond-token-string.exp Thu Jan 21 00:38:28 2021
@@ -1,8 +1,18 @@
-make: "cond-token-string.mk" line 9: Unknown modifier 'Z'
-make: "cond-token-string.mk" line 9: Malformed conditional ("" != "${:Uvalue:Z}")
-make: "cond-token-string.mk" line 18: xvalue is not defined.
-make: "cond-token-string.mk" line 24: Malformed conditional (x${:Uvalue} == "")
-make: "cond-token-string.mk" line 33: Expected.
+make: "cond-token-string.mk" line 13: Unknown modifier 'Z'
+make: "cond-token-string.mk" line 13: Malformed conditional ("" != "${:Uvalue:Z}")
+make: "cond-token-string.mk" line 22: xvalue is not defined.
+make: "cond-token-string.mk" line 28: Malformed conditional (x${:Uvalue} == "")
+make: "cond-token-string.mk" line 37: Expected.
+CondParser_Eval: "UNDEF"
+make: "cond-token-string.mk" line 46: The string literal "UNDEF" is not empty.
+CondParser_Eval: " "
+make: "cond-token-string.mk" line 55: The string literal " " is not empty, even though it consists of whitespace only.
+CondParser_Eval: "${UNDEF}"
+make: "cond-token-string.mk" line 64: An undefined variable in quotes expands to an empty string, which then evaluates to false.
+CondParser_Eval: "${:Uvalue}"
+make: "cond-token-string.mk" line 68: A nonempty variable expression evaluates to true.
+CondParser_Eval: "${:U}"
+make: "cond-token-string.mk" line 76: An empty variable evaluates to false.
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1