Module Name:    src
Committed By:   rillig
Date:           Thu Jan 21 13:32:17 UTC 2021

Modified Files:
        src/usr.bin/make/unit-tests: cond-token-plain.exp cond-token-plain.mk

Log Message:
make(1): add more tests for edge cases in conditionals


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/make/unit-tests/cond-token-plain.exp
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/make/unit-tests/cond-token-plain.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-token-plain.exp
diff -u src/usr.bin/make/unit-tests/cond-token-plain.exp:1.4 src/usr.bin/make/unit-tests/cond-token-plain.exp:1.5
--- src/usr.bin/make/unit-tests/cond-token-plain.exp:1.4	Thu Jan 21 00:38:28 2021
+++ src/usr.bin/make/unit-tests/cond-token-plain.exp	Thu Jan 21 13:32:17 2021
@@ -38,4 +38,15 @@ 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
+CondParser_Eval: "" ==
+make: "cond-token-plain.mk" line 140: warning: Missing right-hand-side of operator
+make: "cond-token-plain.mk" line 140: Malformed conditional ("" ==)
+CondParser_Eval: == ""
+make: "cond-token-plain.mk" line 148: Malformed conditional (== "")
+CondParser_Eval: \\
+make: "cond-token-plain.mk" line 163: The variable '\\' is not defined.
+CondParser_Eval: \\
+make: "cond-token-plain.mk" line 168: Now the variable '\\' is defined.
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 1

Index: src/usr.bin/make/unit-tests/cond-token-plain.mk
diff -u src/usr.bin/make/unit-tests/cond-token-plain.mk:1.7 src/usr.bin/make/unit-tests/cond-token-plain.mk:1.8
--- src/usr.bin/make/unit-tests/cond-token-plain.mk:1.7	Thu Jan 21 00:38:28 2021
+++ src/usr.bin/make/unit-tests/cond-token-plain.mk	Thu Jan 21 13:32:17 2021
@@ -1,4 +1,4 @@
-# $NetBSD: cond-token-plain.mk,v 1.7 2021/01/21 00:38:28 rillig Exp $
+# $NetBSD: cond-token-plain.mk,v 1.8 2021/01/21 13:32:17 rillig Exp $
 #
 # Tests for plain tokens (that is, string literals without quotes)
 # in .if conditions.
@@ -136,6 +136,40 @@ VAR=	defined
 .  error
 .endif
 
+# If the right-hand side is missing, it's a parse error.
+.if "" ==
+.  error
+.else
+.  error
+.endif
+
+# If the left-hand side is missing, it's a parse error as well, but without
+# a specific error message.
+.if == ""
+.  error
+.else
+.  error
+.endif
+
+# The '\\' is not a line continuation.  Neither is it an unquoted string
+# literal.  Instead, it is parsed as a function argument (ParseFuncArg),
+# and in that context, the backslash is just an ordinary character. The
+# function argument thus stays '\\' (2 backslashes).  This string is passed
+# to FuncDefined, and since there is no variable named '\\', the condition
+# evaluates to false.
+.if \\
+.  error
+.else
+.  info The variable '\\' is not defined.
+.endif
+
+${:U\\\\}=	backslash
+.if \\
+.  info Now the variable '\\' is defined.
+.else
+.  error
+.endif
+
 # See cond-token-string.mk for similar tests where the condition is enclosed
 # in "quotes".
 

Reply via email to