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 make(1): add more tests for tokens i...
details: https://anonhg.NetBSD.org/src/rev/6ae07051c219
branches: trunk
changeset: 950208:6ae07051c219
user: rillig <rillig%NetBSD.org@localhost>
date: Thu Jan 21 00:38:28 2021 +0000
description:
make(1): add more tests for tokens in conditionals
diffstat:
usr.bin/make/unit-tests/cond-token-plain.exp | 12 ++++++
usr.bin/make/unit-tests/cond-token-plain.mk | 48 ++++++++++++++++++++++++++-
usr.bin/make/unit-tests/cond-token-string.exp | 20 ++++++++--
usr.bin/make/unit-tests/cond-token-string.mk | 47 +++++++++++++++++++++++++-
4 files changed, 119 insertions(+), 8 deletions(-)
diffs (169 lines):
diff -r 934d80c13540 -r 6ae07051c219 usr.bin/make/unit-tests/cond-token-plain.exp
--- a/usr.bin/make/unit-tests/cond-token-plain.exp Wed Jan 20 22:46:33 2021 +0000
+++ b/usr.bin/make/unit-tests/cond-token-plain.exp Thu Jan 21 00:38:28 2021 +0000
@@ -26,4 +26,16 @@
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
diff -r 934d80c13540 -r 6ae07051c219 usr.bin/make/unit-tests/cond-token-plain.mk
--- a/usr.bin/make/unit-tests/cond-token-plain.mk Wed Jan 20 22:46:33 2021 +0000
+++ b/usr.bin/make/unit-tests/cond-token-plain.mk Thu Jan 21 00:38:28 2021 +0000
@@ -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:
@:;
diff -r 934d80c13540 -r 6ae07051c219 usr.bin/make/unit-tests/cond-token-string.exp
--- a/usr.bin/make/unit-tests/cond-token-string.exp Wed Jan 20 22:46:33 2021 +0000
+++ b/usr.bin/make/unit-tests/cond-token-string.exp Thu Jan 21 00:38:28 2021 +0000
@@ -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
diff -r 934d80c13540 -r 6ae07051c219 usr.bin/make/unit-tests/cond-token-string.mk
--- a/usr.bin/make/unit-tests/cond-token-string.mk Wed Jan 20 22:46:33 2021 +0000
+++ b/usr.bin/make/unit-tests/cond-token-string.mk Thu Jan 21 00:38:28 2021 +0000
@@ -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 string literals in .if conditions.
#
-# Tests for quoted and unquoted 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:
@:;
Home |
Main Index |
Thread Index |
Old Index