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): move some of the :ts tests ...



details:   https://anonhg.NetBSD.org/src/rev/4de9b9ef6ab0
branches:  trunk
changeset: 943340:4de9b9ef6ab0
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Aug 31 19:58:21 2020 +0000

description:
make(1): move some of the :ts tests into a separate file

The successful cases can be easily tested in the .if conditions.  Around
these conditions, there is enough space for explaining the test cases
and their purpose.

The failure cases have been left in the file for now since they still
produce unwanted characters in the output.  These characters are not
produced when the parse error occurs in a conditional.

diffstat:

 usr.bin/make/unit-tests/modts.exp               |   31 ------
 usr.bin/make/unit-tests/modts.mk                |   16 ---
 usr.bin/make/unit-tests/varmod-to-separator.exp |   10 +-
 usr.bin/make/unit-tests/varmod-to-separator.mk  |  113 +++++++++++++++++++++++-
 4 files changed, 120 insertions(+), 50 deletions(-)

diffs (202 lines):

diff -r 0d92b8c3bda8 -r 4de9b9ef6ab0 usr.bin/make/unit-tests/modts.exp
--- a/usr.bin/make/unit-tests/modts.exp Mon Aug 31 19:51:30 2020 +0000
+++ b/usr.bin/make/unit-tests/modts.exp Mon Aug 31 19:58:21 2020 +0000
@@ -1,34 +1,3 @@
-LIST="one two three four five six"
-LIST:ts,="one,two,three,four,five,six"
-LIST:ts/:tu="ONE/TWO/THREE/FOUR/FIVE/SIX"
-LIST:ts::tu="ONE:TWO:THREE:FOUR:FIVE:SIX"
-LIST:ts:tu="ONETWOTHREEFOURFIVESIX"
-LIST:tu:ts/="ONE/TWO/THREE/FOUR/FIVE/SIX"
-LIST:ts:="one:two:three:four:five:six"
-LIST:ts="onetwothreefourfivesix"
-LIST:ts:S/two/2/="one2threefourfivesix"
-LIST:S/two/2/:ts="one2threefourfivesix"
-LIST:ts/:S/two/2/="one/2/three/four/five/six"
-Pretend the '/' in '/n' etc. below are back-slashes.
-LIST:ts/n="one
-two
-three
-four
-five
-six"
-LIST:ts/t="one two     three   four    five    six"
-LIST:ts/012:tu="ONE
-TWO
-THREE
-FOUR
-FIVE
-SIX"
-LIST:ts/xa:tu="ONE
-TWO
-THREE
-FOUR
-FIVE
-SIX"
 make: Bad modifier `:tx' for LIST
 LIST:tx="}"
 make: Bad modifier `:ts\X' for LIST
diff -r 0d92b8c3bda8 -r 4de9b9ef6ab0 usr.bin/make/unit-tests/modts.mk
--- a/usr.bin/make/unit-tests/modts.mk  Mon Aug 31 19:51:30 2020 +0000
+++ b/usr.bin/make/unit-tests/modts.mk  Mon Aug 31 19:58:21 2020 +0000
@@ -21,22 +21,6 @@
 .endif
 
 mod-ts:
-       @echo 'LIST="${LIST}"'
-       @echo 'LIST:ts,="${LIST:ts,}"'
-       @echo 'LIST:ts/:tu="${LIST:ts/:tu}"'
-       @echo 'LIST:ts::tu="${LIST:ts::tu}"'
-       @echo 'LIST:ts:tu="${LIST:ts:tu}"'
-       @echo 'LIST:tu:ts/="${LIST:tu:ts/}"'
-       @echo 'LIST:ts:="${LIST:ts:}"'
-       @echo 'LIST:ts="${LIST:ts}"'
-       @echo 'LIST:ts:S/two/2/="${LIST:ts:S/two/2/}"'
-       @echo 'LIST:S/two/2/:ts="${LIST:S/two/2/:ts}"'
-       @echo 'LIST:ts/:S/two/2/="${LIST:ts/:S/two/2/}"'
-       @echo "Pretend the '/' in '/n' etc. below are back-slashes."
-       @${PRINT} 'LIST:ts/n="${LIST:ts\n}"'
-       @${PRINT} 'LIST:ts/t="${LIST:ts\t}"'
-       @${PRINT} 'LIST:ts/012:tu="${LIST:ts\012:tu}"'
-       @${PRINT} 'LIST:ts/xa:tu="${LIST:ts\xa:tu}"'
        @${PRINT} 'LIST:tx="${LIST:tx}"'
        @${PRINT} 'LIST:ts/x:tu="${LIST:ts\X:tu}"'
        @${PRINT} 'FU_$@="${FU_${@:ts}:ts}"'
diff -r 0d92b8c3bda8 -r 4de9b9ef6ab0 usr.bin/make/unit-tests/varmod-to-separator.exp
--- a/usr.bin/make/unit-tests/varmod-to-separator.exp   Mon Aug 31 19:51:30 2020 +0000
+++ b/usr.bin/make/unit-tests/varmod-to-separator.exp   Mon Aug 31 19:58:21 2020 +0000
@@ -1,1 +1,9 @@
-exit status 0
+make: Bad modifier `:tx' for WORDS
+make: "varmod-to-separator.mk" line 104: Malformed conditional (${WORDS:tx} != "anything")
+make: "varmod-to-separator.mk" line 108: Parsing continues here.
+make: Bad modifier `:t\X' for WORDS
+make: "varmod-to-separator.mk" line 112: Malformed conditional (${WORDS:t\X} != "anything")
+make: "varmod-to-separator.mk" line 115: Parsing continues here.
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 1
diff -r 0d92b8c3bda8 -r 4de9b9ef6ab0 usr.bin/make/unit-tests/varmod-to-separator.mk
--- a/usr.bin/make/unit-tests/varmod-to-separator.mk    Mon Aug 31 19:51:30 2020 +0000
+++ b/usr.bin/make/unit-tests/varmod-to-separator.mk    Mon Aug 31 19:58:21 2020 +0000
@@ -1,9 +1,118 @@
-# $NetBSD: varmod-to-separator.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: varmod-to-separator.mk,v 1.3 2020/08/31 19:58:21 rillig Exp $
 #
 # Tests for the :ts variable modifier, which joins the words of the variable
 # using an arbitrary character as word separator.
 
-# TODO: Implementation
+WORDS= one two three four five six
+
+# The words are separated by a single space, just as usual.
+.if ${WORDS:ts } != "one two three four five six"
+.  warning Space as separator does not work.
+.endif
+
+# The separator can be an arbitrary character, for example a comma.
+.if ${WORDS:ts,} != "one,two,three,four,five,six"
+.  warning Comma as separator does not work.
+.endif
+
+# After the :ts modifier, other modifiers can follow.
+.if ${WORDS:ts/:tu} != "ONE/TWO/THREE/FOUR/FIVE/SIX"
+.  warning Chaining modifiers does not work.
+.endif
+
+# To use the ':' as the separator, just write it normally.
+# The first colon is the separator, the second ends the modifier.
+.if ${WORDS:ts::tu} != "ONE:TWO:THREE:FOUR:FIVE:SIX"
+.  warning Colon as separator does not work.
+.endif
+
+# When there is just a colon but no other character, the words are
+# "separated" by an empty string, that is, they are all squashed
+# together.
+.if ${WORDS:ts:tu} != "ONETWOTHREEFOURFIVESIX"
+.  warning Colon as separator does not work.
+.endif
+
+# Applying the :tu modifier first and then the :ts modifier does not change
+# anything since neither of these modifiers is related to how the string is
+# split into words.  Beware of separating the words using a single or double
+# quote though, or other special characters like dollar or backslash.
+#
+# This example also demonstrates that the closing brace is not interpreted
+# as a separator, but as the closing delimiter of the whole variable
+# expression.
+.if ${WORDS:tu:ts} != "ONETWOTHREEFOURFIVESIX"
+.  warning Colon as separator does not work.
+.endif
+
+# The '}' plays the same role as the ':' in the preceding examples.
+# Since there is a single character before it, that character is taken as
+# the separator.
+.if ${WORDS:tu:ts/} != "ONE/TWO/THREE/FOUR/FIVE/SIX"
+.  warning Colon as separator does not work.
+.endif
+
+# Now it gets interesting and ambiguous:  The separator could either be empty
+# since it is followed by a colon.  Or it could be the colon since that
+# colon is followed by the closing brace.  It's the latter case.
+.if ${WORDS:ts:} != "one:two:three:four:five:six"
+.  warning Colon followed by closing brace does not work.
+.endif
+
+# As in the ${WORDS:tu:ts} example above, the separator is empty.
+.if ${WORDS:ts} != "onetwothreefourfivesix"
+.  warning Empty separator before closing brace does not work.
+.endif
+
+# The :ts modifier can be followed by other modifiers.
+.if ${WORDS:ts:S/two/2/} != "one2threefourfivesix"
+.  warning Separator followed by :S modifier does not work.
+.endif
+
+# The :ts modifier can follow other modifiers.
+.if ${WORDS:S/two/2/:ts} != "one2threefourfivesix"
+.  warning :S modifier followed by :ts modifier does not work.
+.endif
+
+# The :ts modifier with an actual separator can be followed by other
+# modifiers.
+.if ${WORDS:ts/:S/two/2/} != "one/2/three/four/five/six"
+.  warning The :ts modifier followed by an :S modifier does not work.
+.endif
+
+# The separator can be \n, which is a newline.
+.if ${WORDS:[1..3]:ts\n} != "one${.newline}two${.newline}three"
+.  warning The separator \n does not produce a newline.
+.endif
+
+# The separator can be \t, which is a tab.
+.if ${WORDS:[1..3]:ts\t} != "one       two     three"
+.  warning The separator \t does not produce a tab.
+.endif
+
+# The separator can be given as octal number.
+.if ${WORDS:[1..3]:ts\012:tu} != "ONE${.newline}TWO${.newline}THREE"
+.  warning The separator \012 is not interpreted in octal ASCII.
+.endif
+
+# The separator can be given as hexadecimal number.
+.if ${WORDS:[1..3]:ts\xa:tu} != "ONE${.newline}TWO${.newline}THREE"
+.  warning The separator \xa is not interpreted in hexadecimal ASCII.
+.endif
+
+# In the :t modifier, the :t must be followed by any of A, l, s, u.
+.if ${WORDS:tx} != "anything"
+.  info This line is not reached because of the malformed condition.
+.  info If this line were reached, it would be visible in the -dcpv log.
+.endif
+.info Parsing continues here.
+
+# After the backslash, only n, t, an octal number, or x and a hexadecimal
+# number are allowed.
+.if ${WORDS:t\X} != "anything"
+.  info This line is not reached.
+.endif
+.info Parsing continues here.
 
 all:
        @:;



Home | Main Index | Thread Index | Old Index