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 test for string literal...



details:   https://anonhg.NetBSD.org/src/rev/6852e3231149
branches:  trunk
changeset: 942810:6852e3231149
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu Aug 20 18:43:19 2020 +0000

description:
make(1): add test for string literals in comparisons

diffstat:

 usr.bin/make/unit-tests/cond-cmp-string.exp |   6 +++-
 usr.bin/make/unit-tests/cond-cmp-string.mk  |  39 ++++++++++++++++++++++++++--
 2 files changed, 40 insertions(+), 5 deletions(-)

diffs (57 lines):

diff -r 5e8c04b478e5 -r 6852e3231149 usr.bin/make/unit-tests/cond-cmp-string.exp
--- a/usr.bin/make/unit-tests/cond-cmp-string.exp       Thu Aug 20 18:05:57 2020 +0000
+++ b/usr.bin/make/unit-tests/cond-cmp-string.exp       Thu Aug 20 18:43:19 2020 +0000
@@ -1,1 +1,5 @@
-exit status 0
+make: "cond-cmp-string.mk" line 18: Malformed conditional (str != str)
+make: "cond-cmp-string.mk" line 37: Malformed conditional ("string" != "str""ing")
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 1
diff -r 5e8c04b478e5 -r 6852e3231149 usr.bin/make/unit-tests/cond-cmp-string.mk
--- a/usr.bin/make/unit-tests/cond-cmp-string.mk        Thu Aug 20 18:05:57 2020 +0000
+++ b/usr.bin/make/unit-tests/cond-cmp-string.mk        Thu Aug 20 18:43:19 2020 +0000
@@ -1,8 +1,39 @@
-# $NetBSD: cond-cmp-string.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: cond-cmp-string.mk,v 1.3 2020/08/20 18:43:19 rillig Exp $
 #
 # Tests for string comparisons in .if conditions.
 
-# TODO: Implementation
+# This is a simple comparison of string literals.
+# Nothing surprising here.
+.if "str" != "str"
+.error
+.endif
+
+# The right-hand side of the comparison may be written without quotes.
+.if "str" != str
+.error
+.endif
+
+# The left-hand side of the comparison must be enclosed in quotes.
+# This one is not enclosed in quotes and thus generates an error message.
+.if str != str
+.error
+.endif
 
-all:
-       @:;
+# The left-hand side of the comparison requires a defined variable.
+# The variable named "" is not defined, but applying the :U modifier to it
+# makes it "kind of defined" (see VAR_KEEP).  Therefore it is ok here.
+.if ${:Ustr} != "str"
+.error
+.endif
+
+# Any character in a string literal may be escaped using a backslash.
+# This means that "\n" does not mean a newline but a simple "n".
+.if "string" != "\s\t\r\i\n\g"
+.error
+.endif
+
+# It is not possible to concatenate two string literals to form a single
+# string.
+.if "string" != "str""ing"
+.error
+.endif



Home | Main Index | Thread Index | Old Index