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): migrate SysV modifier test ...



details:   https://anonhg.NetBSD.org/src/rev/a9fc8e95be05
branches:  trunk
changeset: 976888:a9fc8e95be05
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Oct 06 21:05:21 2020 +0000

description:
make(1): migrate SysV modifier test to use the preprocessor

When both the expected and the actual expression are written in the same
line of the same file, it is easier to compare them and to document
anything interesting.  The exp file doesn't provide any space for
comments or explanations.

diffstat:

 usr.bin/make/unit-tests/varmod-sysv.exp |    7 --
 usr.bin/make/unit-tests/varmod-sysv.mk  |  111 ++++++++++++++++++++-----------
 2 files changed, 70 insertions(+), 48 deletions(-)

diffs (147 lines):

diff -r bf1c8068d3c0 -r a9fc8e95be05 usr.bin/make/unit-tests/varmod-sysv.exp
--- a/usr.bin/make/unit-tests/varmod-sysv.exp   Tue Oct 06 18:47:07 2020 +0000
+++ b/usr.bin/make/unit-tests/varmod-sysv.exp   Tue Oct 06 21:05:21 2020 +0000
@@ -1,8 +1,1 @@
-ax:Q b c d eb
-bcd.e
-&
-anchor-dollar: value
-anchor-dollar: valux
-mismatch: file.cpp file.h
-mismatch: renamed.c other.c
 exit status 0
diff -r bf1c8068d3c0 -r a9fc8e95be05 usr.bin/make/unit-tests/varmod-sysv.mk
--- a/usr.bin/make/unit-tests/varmod-sysv.mk    Tue Oct 06 18:47:07 2020 +0000
+++ b/usr.bin/make/unit-tests/varmod-sysv.mk    Tue Oct 06 21:05:21 2020 +0000
@@ -1,61 +1,90 @@
-# $NetBSD: varmod-sysv.mk,v 1.3 2020/08/23 14:52:06 rillig Exp $
+# $NetBSD: varmod-sysv.mk,v 1.4 2020/10/06 21:05:21 rillig Exp $
 #
 # Tests for the ${VAR:from=to} variable modifier, which replaces the suffix
 # "from" with "to".  It can also use '%' as a wildcard.
 #
 # This modifier is applied when the other modifiers don't match exactly.
 
-all: words ampersand anchor-dollar mismatch
+all:
 
 # The :Q looks like a modifier but isn't.
 # It is part of the replacement string.
-words:
-       @echo a${a b c d e:L:%a=x:Q}b
+.if ${a b c d e:L:%a=x:Q} != "x:Q b c d e"
+.  error
+.endif
 
 # Before 2020-07-19, an ampersand could be used in the replacement part
-# of a SysV substitution modifier.  This was probably a copy-and-paste
-# mistake since the SysV modifier code looked a lot like the code for the
-# :S and :C modifiers.  The ampersand is not mentioned in the manual page.
-ampersand:
-       @echo ${:U${a.bcd.e:L:a.%=%}:Q}
-       @echo ${:U${a.bcd.e:L:a.%=&}:Q}
+# of a SysV substitution modifier, and it was replaced with the whole match,
+# just like in the :S modifier.
+#
+# This was probably a copy-and-paste mistake since the code for the SysV
+# modifier looked a lot like the code for the :S and :C modifiers.
+# The ampersand is not mentioned in the manual page.
+.if ${a.bcd.e:L:a.%=%} != "bcd.e"
+.  error
+.endif
+# Before 2020-07-19, the result of the expression was "a.bcd.e".
+.if ${a.bcd.e:L:a.%=&} != "&"
+.  error
+.endif
 
 # Before 2020-07-20, when a SysV modifier was parsed, a single dollar
-# before the '=' was interpreted as an anchor, which doesn't make sense
-# since the anchor was discarded immediately.
-anchor-dollar:
-       @echo $@: ${:U${value:L:e$=x}:Q}
-       @echo $@: ${:U${value:L:e=x}:Q}
+# before the '=' was parsed (but not interpreted) as an anchor.
+# Parsing something without then evaluating it accordingly doesn't make
+# sense.
+.if ${value:L:e$=x} != "value"
+.  error
+.endif
+# Before 2020-07-20, the modifier ":e$=x" was parsed as having a left-hand
+# side "e" and a right-hand side "x".  The dollar was parsed (but not
+# interpreted) as 'anchor at the end'.  Therefore the modifier was equivalent
+# to ":e=x", which doesn't match the string "value$".  Therefore the whole
+# expression evaluated to "value$".
+.if ${${:Uvalue\$}:L:e$=x} != "valux"
+.  error
+.endif
+.if ${value:L:e=x} != "valux"
+.  error
+.endif
 
 # Words that don't match are copied unmodified.
-# The % placeholder can be anywhere in the string.
-mismatch:
-       @echo $@: ${:Ufile.c file.h:%.c=%.cpp}
-       @echo $@: ${:Ufile.c other.c:file.%=renamed.%}
+.if ${:Ufile.c file.h:%.c=%.cpp} != "file.cpp file.h"
+.  error
+.endif
+
+# The % placeholder can be anywhere in the string, it doesn't have to be at
+# the beginning of the pattern.
+.if ${:Ufile.c other.c:file.%=renamed.%} != "renamed.c other.c"
+.  error
+.endif
 
 # Trying to cover all possible variants of the SysV modifier.
 LIST=  one two
-EXPR.1=        ${LIST:o=X}
-EXP.1= one twX
-EXPR.2=        ${LIST:o=}
-EXP.2= one tw
-EXPR.3=        ${LIST:o=%}
-EXP.3= one tw%
-EXPR.4=        ${LIST:%o=X}
-EXP.4= one X
-EXPR.5=        ${LIST:o%=X}
-EXP.5= X two
-EXPR.6=        ${LIST:o%e=X}
-EXP.6= X two
-EXPR.7=        ${LIST:o%%e=X}          # Only the first '%' is the wildcard.
-EXP.7= one two                 # None of the words contains a literal '%'.
-EXPR.8=        ${LIST:%=%%}
-EXP.8= one% two%
-EXPR.9=        ${LIST:%nes=%xxx}       # lhs is longer than the word "one"
-EXP.9= one two
 
-.for i in ${:U:range=9}
-.if ${EXPR.$i} != ${EXP.$i}
-.warning test case $i expected "${EXP.$i}", got "${EXPR.$i}
+.if ${LIST:o=X} != "one twX"
+.  error
+.endif
+.if ${LIST:o=} != "one tw"
+.  error
+.endif
+.if ${LIST:o=%} != "one tw%"
+.  error
+.endif
+.if ${LIST:%o=X} != "one X"
+.  error
 .endif
-.endfor
+.if ${LIST:o%=X} != "X two"
+.  error
+.endif
+.if ${LIST:o%e=X} != "X two"
+.  error
+.endif
+.if ${LIST:o%%e=X} != "one two"        # Only the first '%' is the wildcard.
+.  error
+.endif
+.if ${LIST:%=%%} != "one% two%"        # None of the words contains a literal '%'.
+.  error
+.endif
+.if ${LIST:%nes=%xxx} != "one two" # lhs is longer than the word "one"
+.  error
+.endif



Home | Main Index | Thread Index | Old Index