Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make/unit-tests make(1): add test for undefined sube...



details:   https://anonhg.NetBSD.org/src/rev/ca035c7d8109
branches:  trunk
changeset: 974738:ca035c7d8109
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Aug 09 15:03:25 2020 +0000

description:
make(1): add test for undefined subexpression in the :C modifier

diffstat:

 usr.bin/make/unit-tests/moderrs.exp |   8 ++++++++
 usr.bin/make/unit-tests/moderrs.mk  |  20 +++++++++++++++++++-
 2 files changed, 27 insertions(+), 1 deletions(-)

diffs (59 lines):

diff -r 94754eb7fe81 -r ca035c7d8109 usr.bin/make/unit-tests/moderrs.exp
--- a/usr.bin/make/unit-tests/moderrs.exp       Sun Aug 09 15:02:52 2020 +0000
+++ b/usr.bin/make/unit-tests/moderrs.exp       Sun Aug 09 15:03:25 2020 +0000
@@ -89,6 +89,14 @@
 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
diff -r 94754eb7fe81 -r ca035c7d8109 usr.bin/make/unit-tests/moderrs.mk
--- a/usr.bin/make/unit-tests/moderrs.mk        Sun Aug 09 15:02:52 2020 +0000
+++ b/usr.bin/make/unit-tests/moderrs.mk        Sun Aug 09 15:03:25 2020 +0000
@@ -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:   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 @@
        @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}



Home | Main Index | Thread Index | Old Index