Module Name: src
Committed By: rillig
Date: Sun Aug 9 15:03:25 UTC 2020
Modified Files:
src/usr.bin/make/unit-tests: moderrs.exp moderrs.mk
Log Message:
make(1): add test for undefined subexpression in the :C modifier
To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/usr.bin/make/unit-tests/moderrs.exp
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/make/unit-tests/moderrs.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/moderrs.exp
diff -u src/usr.bin/make/unit-tests/moderrs.exp:1.13 src/usr.bin/make/unit-tests/moderrs.exp:1.14
--- src/usr.bin/make/unit-tests/moderrs.exp:1.13 Sat Aug 8 13:27:42 2020
+++ src/usr.bin/make/unit-tests/moderrs.exp Sun Aug 9 15:03:25 2020
@@ -89,6 +89,14 @@ make: Unfinished modifier for VAR (',' m
make: Unclosed variable specification (expecting '}') for "VAR" (value "TheVariable") modifier C
TheVariable
TheVariable
+mod-regex-undefined-subexpression:
+one one 2 3 5 8 one3 2one 34
+make: No match for subexpression \2
+make: No match for subexpression \2
+make: No match for subexpression \1
+make: No match for subexpression \2
+make: No match for subexpression \1
++ + + 3 5 8 3+ +1 34
mod-ts-parse:
112358132134
15152535558513521534
Index: src/usr.bin/make/unit-tests/moderrs.mk
diff -u src/usr.bin/make/unit-tests/moderrs.mk:1.12 src/usr.bin/make/unit-tests/moderrs.mk:1.13
--- src/usr.bin/make/unit-tests/moderrs.mk:1.12 Sat Aug 8 13:27:42 2020
+++ src/usr.bin/make/unit-tests/moderrs.mk Sun Aug 9 15:03:25 2020
@@ -1,4 +1,4 @@
-# $Id: moderrs.mk,v 1.12 2020/08/08 13:27:42 rillig Exp $
+# $Id: moderrs.mk,v 1.13 2020/08/09 15:03:25 rillig Exp $
#
# various modifier error tests
@@ -16,6 +16,7 @@ all: modwords
all: modexclam
all: mod-subst-delimiter
all: mod-regex-delimiter
+all: mod-regex-undefined-subexpression
all: mod-ts-parse
all: mod-t-parse
all: mod-ifelse-parse
@@ -124,6 +125,23 @@ mod-regex-delimiter:
@echo ${VAR:C,from,to,
@echo ${VAR:C,from,to,}
+# In regular expressions with alternatives, not all capturing groups are
+# always set; some may be missing. Warn about these.
+#
+# Since there is no way to turn off this warning, the combination of
+# alternative matches and capturing groups is not widely used.
+#
+# A newly added modifier 'U' such as in :C,(a.)|(b.),\1\2,U might be added
+# for treating undefined capturing groups as empty, but that would create a
+# syntactical ambiguity since the :S and :C modifiers are open-ended (see
+# mod-subst-chain). Luckily the modifier :U does not make sense after :C,
+# therefore this case does not happen in practice.
+# The sub-modifier for the :C modifier would have to be chosen wisely.
+mod-regex-undefined-subexpression:
+ @echo $@:
+ @echo ${FIB:C,1(.*),one\1,} # all ok
+ @echo ${FIB:C,1(.*)|2(.*),\1+\2,} # no match for subexpression
+
mod-ts-parse:
@echo $@:
@echo ${FIB:ts}