Module Name:    src
Committed By:   rillig
Date:           Mon Dec  2 01:01:08 UTC 2019

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

Log Message:
Add more tests for variable modifiers in make.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/varmod-edge.exp
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/make/unit-tests/varmod-edge.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-edge.exp
diff -u src/usr.bin/make/unit-tests/varmod-edge.exp:1.3 src/usr.bin/make/unit-tests/varmod-edge.exp:1.4
--- src/usr.bin/make/unit-tests/varmod-edge.exp:1.3	Sat Nov 30 03:53:45 2019
+++ src/usr.bin/make/unit-tests/varmod-edge.exp	Mon Dec  2 01:01:08 2019
@@ -1,4 +1,5 @@
 make: Unclosed variable specification (expecting '}') for "" (value "*)") modifier U
+make: Unclosed substitution for INP.eq-esc (= missing)
 ok M-paren
 ok M-mixed
 ok M-unescape
@@ -8,4 +9,9 @@ ok M-pat-err
 ok M-bsbs
 ok M-bs1-par
 ok M-bs2-par
+ok M-128
+ok eq-ext
+ok eq-q
+ok eq-bs
+ok eq-esc
 exit status 0

Index: src/usr.bin/make/unit-tests/varmod-edge.mk
diff -u src/usr.bin/make/unit-tests/varmod-edge.mk:1.5 src/usr.bin/make/unit-tests/varmod-edge.mk:1.6
--- src/usr.bin/make/unit-tests/varmod-edge.mk:1.5	Sun Dec  1 23:53:49 2019
+++ src/usr.bin/make/unit-tests/varmod-edge.mk	Mon Dec  2 01:01:08 2019
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-edge.mk,v 1.5 2019/12/01 23:53:49 rillig Exp $
+# $NetBSD: varmod-edge.mk,v 1.6 2019/12/02 01:01:08 rillig Exp $
 #
 # Tests for edge cases in variable modifiers.
 #
@@ -51,6 +51,7 @@ TESTS+=		M-nest-mix
 INP.M-nest-mix=	(parentheses)
 MOD.M-nest-mix=	${INP.M-nest-mix:M${:U*)}}
 EXP.M-nest-mix=	(parentheses)}
+# make: Unclosed variable specification (expecting '}') for "" (value "*)") modifier U
 
 # In contrast to parentheses and braces, the brackets are not counted
 # when the :M modifier is parsed since Makefile variables only take the
@@ -112,6 +113,44 @@ INP.M-bs2-par=	( (:M (:M} \( \(:M \(:M}
 MOD.M-bs2-par=	${INP.M-bs2-par:M\\(:M*}}}
 EXP.M-bs2-par=	\(:M}}
 
+# Str_Match uses a recursive algorithm for matching the * patterns.
+# Make sure that it survives patterns with 128 asterisks.
+# That should be enough for all practical purposes.
+# To produce a stack overflow, just add more :Qs below.
+TESTS+=		M-128
+INP.M-128=	${:U\\:Q:Q:Q:Q:Q:Q:Q:S,\\,x,g}
+PAT.M-128=	${:U\\:Q:Q:Q:Q:Q:Q:Q:S,\\,*,g}
+MOD.M-128=	${INP.M-128:M${PAT.M-128}}
+EXP.M-128=	${INP.M-128}
+
+# This is the normal SysV substitution. Nothing surprising here.
+TESTS+=		eq-ext
+INP.eq-ext=	file.c file.cc
+MOD.eq-ext=	${INP.eq-ext:%.c=%.o}
+EXP.eq-ext=	file.o file.cc
+
+# The SysV := modifier is greedy and consumes all the modifier text
+# up until the closing brace or parenthesis. The :Q may look like a
+# modifier, but it really isn't, that's why it appears in the output.
+TESTS+=		eq-q
+INP.eq-q=	file.c file.cc
+MOD.eq-q=	${INP.eq-q:%.c=%.o:Q}
+EXP.eq-q=	file.o:Q file.cc
+
+# The = in the := modifier can be escaped.
+TESTS+=		eq-bs
+INP.eq-bs=	file.c file.c=%.o
+MOD.eq-bs=	${INP.eq-bs:%.c\=%.o=.ext}
+EXP.eq-bs=	file.c file.ext
+
+# Having only an escaped = results in a parse error.
+# The call to "pattern.lhs = VarGetPattern" fails.
+TESTS+=		eq-esc
+INP.eq-esc=	file.c file...
+MOD.eq-esc=	${INP.eq-esc:a\=b}
+EXP.eq-esc=	# empty
+# make: Unclosed substitution for INP.eq-esc (= missing)
+
 all:
 .for test in ${TESTS}
 .  if ${MOD.${test}} == ${EXP.${test}}

Reply via email to