Module Name: src
Committed By: rillig
Date: Thu Aug 20 18:43:19 UTC 2020
Modified Files:
src/usr.bin/make/unit-tests: cond-cmp-string.exp cond-cmp-string.mk
Log Message:
make(1): add test for string literals in comparisons
To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/cond-cmp-string.exp
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/cond-cmp-string.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-cmp-string.exp
diff -u src/usr.bin/make/unit-tests/cond-cmp-string.exp:1.1 src/usr.bin/make/unit-tests/cond-cmp-string.exp:1.2
--- src/usr.bin/make/unit-tests/cond-cmp-string.exp:1.1 Sun Aug 16 12:07:51 2020
+++ src/usr.bin/make/unit-tests/cond-cmp-string.exp Thu Aug 20 18:43:19 2020
@@ -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
Index: src/usr.bin/make/unit-tests/cond-cmp-string.mk
diff -u src/usr.bin/make/unit-tests/cond-cmp-string.mk:1.2 src/usr.bin/make/unit-tests/cond-cmp-string.mk:1.3
--- src/usr.bin/make/unit-tests/cond-cmp-string.mk:1.2 Sun Aug 16 14:25:16 2020
+++ src/usr.bin/make/unit-tests/cond-cmp-string.mk Thu Aug 20 18:43:19 2020
@@ -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
-all:
- @:;
+# 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
+
+# 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