Module Name:    src
Committed By:   rillig
Date:           Thu Jun  6 20:41:50 UTC 2024

Modified Files:
        src/usr.bin/make/unit-tests: varmod.exp varmod.mk

Log Message:
tests/make: test unescaped '$' at the end of a modifier part

In ParseModifierPart, an unescaped '$' that occurs right before a
delimiter is handled differently from a '$' that occurs in the middle of
the modifier part.

In practice, this edge case is only used by the first part of the
':C,from,to,' modifier.  Using it in most other modifier parts produces
an error message.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/usr.bin/make/unit-tests/varmod.exp
cvs rdiff -u -r1.14 -r1.15 src/usr.bin/make/unit-tests/varmod.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/varmod.exp
diff -u src/usr.bin/make/unit-tests/varmod.exp:1.11 src/usr.bin/make/unit-tests/varmod.exp:1.12
--- src/usr.bin/make/unit-tests/varmod.exp:1.11	Sun Jun  2 11:25:03 2024
+++ src/usr.bin/make/unit-tests/varmod.exp	Thu Jun  6 20:41:50 2024
@@ -11,6 +11,23 @@ make: "varmod.mk" line 135: while evalua
 make: "varmod.mk" line 135: Malformed conditional (${word:L:range=99333000222000111000})
 make: "varmod.mk" line 143: while evaluating "${:${:Ugmtime=\\}}": Invalid time value "\"
 make: "varmod.mk" line 143: Malformed conditional (${:${:Ugmtime=\\}})
+make: "varmod.mk" line 158: while evaluating variable "VAR": Dollar followed by nothing
+make: "varmod.mk" line 164: while evaluating variable "VAR": Dollar followed by nothing
+make: "varmod.mk" line 164: while evaluating variable "VAR": Dollar followed by nothing
+make: "varmod.mk" line 174: while evaluating variable "word": Dollar followed by nothing
+make: Bad modifier ":[$]" for variable "word"
+make: "varmod.mk" line 179: Malformed conditional (${word:[$]})
+make: "varmod.mk" line 196: while evaluating variable "VAR": Dollar followed by nothing
+make: "varmod.mk" line 196: while evaluating variable "VAR": Invalid variable name '}', at "$} != "set""
+make: "varmod.mk" line 200: while evaluating "${:Ufallback$} != "fallback"": Invalid variable name '}', at "$} != "fallback""
+make: "varmod.mk" line 205: while evaluating variable "%y": Invalid time value "1000$"
+make: "varmod.mk" line 205: Malformed conditional (${%y:L:gmtime=1000$})
+make: "varmod.mk" line 212: while evaluating variable "%y": Invalid time value "1000$"
+make: "varmod.mk" line 212: Malformed conditional (${%y:L:localtime=1000$})
+make: "varmod.mk" line 218: while evaluating variable "word": Dollar followed by nothing
+make: "varmod.mk" line 222: while evaluating variable "word": Dollar followed by nothing
+make: "varmod.mk" line 227: while evaluating variable ".": Invalid argument 'fallback$' for modifier ':mtime'
+make: "varmod.mk" line 227: Malformed conditional (${.:L:mtime=fallback$})
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1

Index: src/usr.bin/make/unit-tests/varmod.mk
diff -u src/usr.bin/make/unit-tests/varmod.mk:1.14 src/usr.bin/make/unit-tests/varmod.mk:1.15
--- src/usr.bin/make/unit-tests/varmod.mk:1.14	Wed Jun  5 22:06:53 2024
+++ src/usr.bin/make/unit-tests/varmod.mk	Thu Jun  6 20:41:50 2024
@@ -1,4 +1,4 @@
-# $NetBSD: varmod.mk,v 1.14 2024/06/05 22:06:53 rillig Exp $
+# $NetBSD: varmod.mk,v 1.15 2024/06/06 20:41:50 rillig Exp $
 #
 # Tests for variable modifiers, such as :Q, :S,from,to or :Ufallback.
 #
@@ -143,3 +143,95 @@ VAR=	STOP
 .if ${:${:Ugmtime=\\}}
 .  error
 .endif
+
+# Test a '$' at the end of a modifier part, for all modifiers in the order
+# listed in ApplyModifier.
+#
+# The only modifier parts where an unescaped '$' makes sense at the end are
+# the 'from' parts of the ':S' and ':C' modifiers.  In all other modifier
+# parts, an unescaped '$' is an undocumented and discouraged edge case, as it
+# means the same as an escaped '$'.
+.if ${:U:!printf '%s\n' $!} != "\$"
+.  error
+.endif
+# expect+1: while evaluating variable "VAR": Dollar followed by nothing
+.if ${VAR::=value$} != "" || ${VAR} != "value"
+.  error
+.endif
+${:U }=		<space>
+# expect+2: while evaluating variable "VAR": Dollar followed by nothing
+# expect+1: while evaluating variable "VAR": Dollar followed by nothing
+.if ${VAR::+=appended$} != "" || ${VAR} != "value<space>appended"
+.  error
+.endif
+.if ${1:?then$:else$} != "then\$"
+.  error
+.endif
+.if ${0:?then$:else$} != "else\$"
+.  error
+.endif
+# expect+1: while evaluating variable "word": Dollar followed by nothing
+.if ${word:L:@w@$w$@} != "word"
+.  error
+.endif
+# expect: make: Bad modifier ":[$]" for variable "word"
+# expect+1: Malformed conditional (${word:[$]})
+.if ${word:[$]}
+.  error
+.else
+.  error
+.endif
+VAR_DOLLAR=	VAR$$
+.if ${word:L:_=VAR$} != "word" || ${${VAR_DOLLAR}} != "word"
+.  error
+.endif
+.if ${word:L:C,d$,m,} != "worm"
+.  error
+.endif
+.if ${word:L:C,d,$,} != "wor\$"
+.  error
+.endif
+# expect+2: while evaluating variable "VAR": Invalid variable name '}', at "$} != "set""
+# expect+1: while evaluating variable "VAR": Dollar followed by nothing
+.if ${VAR:Dset$} != "set"
+.  error
+.endif
+# expect+1: while evaluating "${:Ufallback$} != "fallback"": Invalid variable name '}', at "$} != "fallback""
+.if ${:Ufallback$} != "fallback"
+.  error
+.endif
+# expect+2: Malformed conditional (${%y:L:gmtime=1000$})
+# expect+1: while evaluating variable "%y": Invalid time value "1000$"
+.if ${%y:L:gmtime=1000$}
+.  error
+.else
+.  error
+.endif
+# expect+2: Malformed conditional (${%y:L:localtime=1000$})
+# expect+1: while evaluating variable "%y": Invalid time value "1000$"
+.if ${%y:L:localtime=1000$}
+.  error
+.else
+.  error
+.endif
+# expect+1: while evaluating variable "word": Dollar followed by nothing
+.if ${word:L:Mw*$} != "word"
+.  error
+.endif
+# expect+1: while evaluating variable "word": Dollar followed by nothing
+.if ${word:L:NX*$} != "word"
+.  error
+.endif
+# expect+2: while evaluating variable ".": Invalid argument 'fallback$' for modifier ':mtime'
+# expect+1: Malformed conditional (${.:L:mtime=fallback$})
+.if ${.:L:mtime=fallback$}
+.  error
+.else
+.  error
+.endif
+.if ${word:L:S,d$,m,} != "worm"
+.  error
+.endif
+.if ${word:L:S,d,m$,} != "worm\$"
+.  error
+.endif

Reply via email to