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 and tutorial for i...



details:   https://anonhg.NetBSD.org/src/rev/7c833d7ad2b4
branches:  trunk
changeset: 1016801:7c833d7ad2b4
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Dec 01 22:16:36 2020 +0000

description:
make(1): add test and tutorial for indirect modifiers

diffstat:

 distrib/sets/lists/tests/mi                 |   4 +-
 usr.bin/make/unit-tests/Makefile            |   3 +-
 usr.bin/make/unit-tests/varmod-indirect.exp |   1 +
 usr.bin/make/unit-tests/varmod-indirect.mk  |  72 +++++++++++++++++++++++++++++
 4 files changed, 78 insertions(+), 2 deletions(-)

diffs (116 lines):

diff -r 7c8efbd03024 -r 7c833d7ad2b4 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Tue Dec 01 22:09:43 2020 +0000
+++ b/distrib/sets/lists/tests/mi       Tue Dec 01 22:16:36 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.981 2020/12/01 20:37:30 rillig Exp $
+# $NetBSD: mi,v 1.982 2020/12/01 22:16:36 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -5387,6 +5387,8 @@
 ./usr/tests/usr.bin/make/unit-tests/varmod-head.mk                             tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/varmod-ifelse.exp                          tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/varmod-ifelse.mk                           tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/varmod-indirect.exp                                tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/varmod-indirect.mk                         tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/varmod-l-name-to-value.exp                 tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/varmod-l-name-to-value.mk                  tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/varmod-localtime.exp                       tests-usr.bin-tests     compattestfile,atf
diff -r 7c8efbd03024 -r 7c833d7ad2b4 usr.bin/make/unit-tests/Makefile
--- a/usr.bin/make/unit-tests/Makefile  Tue Dec 01 22:09:43 2020 +0000
+++ b/usr.bin/make/unit-tests/Makefile  Tue Dec 01 22:16:36 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.233 2020/12/01 20:37:30 rillig Exp $
+# $NetBSD: Makefile,v 1.234 2020/12/01 22:16:36 rillig Exp $
 #
 # Unit tests for make(1)
 #
@@ -318,6 +318,7 @@
 TESTS+=                varmod-hash
 TESTS+=                varmod-head
 TESTS+=                varmod-ifelse
+TESTS+=                varmod-indirect
 TESTS+=                varmod-l-name-to-value
 TESTS+=                varmod-localtime
 TESTS+=                varmod-loop
diff -r 7c8efbd03024 -r 7c833d7ad2b4 usr.bin/make/unit-tests/varmod-indirect.exp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/varmod-indirect.exp       Tue Dec 01 22:16:36 2020 +0000
@@ -0,0 +1,1 @@
+exit status 0
diff -r 7c8efbd03024 -r 7c833d7ad2b4 usr.bin/make/unit-tests/varmod-indirect.mk
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/varmod-indirect.mk        Tue Dec 01 22:16:36 2020 +0000
@@ -0,0 +1,72 @@
+# $NetBSD: varmod-indirect.mk,v 1.1 2020/12/01 22:16:36 rillig Exp $
+#
+# Tests for indirect variable modifiers, such as in ${VAR:${M_modifiers}}.
+# These can be used for very basic purposes like converting a string to either
+# uppercase or lowercase, as well as for fairly advanced modifiers that first
+# look like line noise and are hard to decipher.
+#
+# TODO: Since when are indirect modifiers supported?
+
+
+# The nested variable expression expands to "tu", and this is interpreted as
+# a variable modifier for the value "Upper", resulting in "UPPER".
+.if ${Upper:L:${:Utu}} != "UPPER"
+.  error
+.endif
+
+# The nested variable expression expands to "tl", and this is interpreted as
+# a variable modifier for the value "Lower", resulting in "lower".
+.if ${Lower:L:${:Utl}} != "lower"
+.  error
+.endif
+
+
+# The nested variable expression is ${1 != 1:?Z:tl}, consisting of the
+# condition "1 != 1", the then-branch "Z" and the else-branch "tl".  Since
+# the condition evaluates to false, the then-branch is ignored (it would
+# have been an unknown modifier anyway) and the ":tl" modifier is applied.
+.if ${Mixed:L:${1 != 1:?Z:tl}} != "mixed"
+.  error
+.endif
+
+
+# The indirect modifier can also replace an ':L' modifier, which allows for
+# brain twisters since by reading the expression alone, it is not possible
+# to say whether the variable name will be evaluated as a variable name or
+# as the immediate value of the expression.
+VAR=   value
+M_ExpandVar=   # an empty modifier
+M_VarAsValue=  L
+#
+.if ${VAR:${M_ExpandVar}} != "value"
+.  error
+.endif
+.if ${VAR:${M_VarAsValue}} != "VAR"
+.  error
+.endif
+
+# The indirect modifier M_ListToSkip, when applied to a list of patterns,
+# expands to a sequence of ':N' modifiers, each of which filters one of the
+# patterns.  This list of patterns can then be applied to another variable
+# to actually filter that variable.
+#
+M_ListToSkip=  @pat@N$${pat}@:ts:
+#
+# The dollar signs need to be doubled in the above modifier expression,
+# otherwise they would be expanded too early, that is, when parsing the
+# modifier itself.
+#
+# In the following example, M_NoPrimes expands to 'N2:N3:N5:N7:N1[1379]'.
+# The 'N' comes from the expression 'N${pat}', the separating colons come
+# from the modifier ':ts:'.
+#
+#.MAKEFLAGS: -dcv              # Uncomment this line to see the details
+#
+PRIMES=                2 3 5 7 1[1379]
+M_NoPrimes=    ${PRIMES:${M_ListToSkip}}
+.if ${:U:range=20:${M_NoPrimes}} != "1 4 6 8 9 10 12 14 15 16 18 20"
+.  error
+.endif
+.MAKEFLAGS: -d0
+
+all:



Home | Main Index | Thread Index | Old Index