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 Add unit tests for variable modifier...



details:   https://anonhg.NetBSD.org/src/rev/a821f672f6cd
branches:  trunk
changeset: 1005134:a821f672f6cd
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Nov 30 00:38:51 2019 +0000

description:
Add unit tests for variable modifiers like :M and :N

diffstat:

 usr.bin/make/unit-tests/Makefile        |   3 +-
 usr.bin/make/unit-tests/varmod-edge.exp |   7 +++
 usr.bin/make/unit-tests/varmod-edge.mk  |  70 +++++++++++++++++++++++++++++++++
 3 files changed, 79 insertions(+), 1 deletions(-)

diffs (102 lines):

diff -r 67b3436e095b -r a821f672f6cd usr.bin/make/unit-tests/Makefile
--- a/usr.bin/make/unit-tests/Makefile  Sat Nov 30 00:28:27 2019 +0000
+++ b/usr.bin/make/unit-tests/Makefile  Sat Nov 30 00:38:51 2019 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.53 2018/05/24 00:25:44 christos Exp $
+# $NetBSD: Makefile,v 1.54 2019/11/30 00:38:51 rillig Exp $
 #
 # Unit tests for make(1)
 # The main targets are:
@@ -50,6 +50,7 @@
        unexport-env \
        varcmd \
        varmisc \
+       varmod-edge \
        varquote \
        varshell
 
diff -r 67b3436e095b -r a821f672f6cd usr.bin/make/unit-tests/varmod-edge.exp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/varmod-edge.exp   Sat Nov 30 00:38:51 2019 +0000
@@ -0,0 +1,7 @@
+make: Unclosed variable specification (expecting '}') for "" (value "*)") modifier U
+ok M-paren
+ok M-mixed
+ok M-nest-mix
+ok M-nest-brk
+ok M-pat-err
+exit status 0
diff -r 67b3436e095b -r a821f672f6cd usr.bin/make/unit-tests/varmod-edge.mk
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/varmod-edge.mk    Sat Nov 30 00:38:51 2019 +0000
@@ -0,0 +1,70 @@
+# $NetBSD: varmod-edge.mk,v 1.1 2019/11/30 00:38:51 rillig Exp $
+#
+# Tests for edge cases in variable modifiers.
+#
+# These tests demonstrate the current implementation in small examples.
+# They may contain surprising behavior.
+#
+# Each test consists of:
+# - INP, the input to the test
+# - MOD, the expression for testing the modifier
+# - EXP, the expected output
+
+TESTS+=                M-paren
+INP.M-paren=   (parentheses) {braces} (opening closing) ()
+MOD.M-paren=   ${INP.M-paren:M(*)}
+EXP.M-paren=   (parentheses) ()
+
+# The first closing brace matches the opening parenthesis.
+# The second closing brace actually ends the variable expression.
+#
+# XXX: This is unexpected but rarely occurs in practice.
+TESTS+=                M-mixed
+INP.M-mixed=   (paren-brace} (
+MOD.M-mixed=   ${INP.M-mixed:M(*}}
+EXP.M-mixed=   (paren-brace}
+
+# When the :M and :N modifiers are parsed, the pattern finishes as soon
+# as open_parens + open_braces == closing_parens + closing_braces. This
+# means that ( and } form a matching pair.
+#
+# Nested variable expressions are not parsed as such. Instead, only the
+# parentheses and braces are counted. This leads to a parse error since
+# the nested expression is not "${:U*)}" but only "${:U*)", which is
+# missing the closing brace. The expression is evaluated anyway.
+# The final brace in the output comes from the end of M.nest-mix.
+#
+# XXX: This is unexpected but rarely occurs in practice.
+TESTS+=                M-nest-mix
+INP.M-nest-mix=        (parentheses)
+MOD.M-nest-mix=        ${INP.M-nest-mix:M${:U*)}}
+EXP.M-nest-mix=        (parentheses)}
+
+# In contrast to parentheses and braces, the brackets are not counted
+# when the :M modifier is parsed since Makefile variables only take the
+# ${VAR} or $(VAR) forms, but not $[VAR].
+#
+# The final ] in the pattern is needed to close the character class.
+TESTS+=                M-nest-brk
+INP.M-nest-brk=        [ [[ [[[
+MOD.M-nest-brk=        ${INP.M-nest-brk:M${:U[[[[[]}}
+EXP.M-nest-brk=        [
+
+# The pattern in the nested variable has an unclosed character class.
+# No error is reported though, and the pattern is closed implicitly.
+#
+# XXX: It is unexpected that no error is reported.
+TESTS+=                M-pat-err
+INP.M-pat-err= [ [[ [[[
+MOD.M-pat-err= ${INP.M-pat-err:M${:U[[}}
+EXP.M-pat-err= [
+
+all:
+.for test in ${TESTS}
+.  if ${MOD.${test}} == ${EXP.${test}}
+       @printf 'ok %s\n' ${test:Q}''
+.  else
+       @printf 'error in %s: expected %s, got %s\n' \
+               ${test:Q}'' ${EXP.${test}:Q}'' ${MOD.${test}:Q}''
+.  endif
+.endfor



Home | Main Index | Thread Index | Old Index