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): clean up some tests



details:   https://anonhg.NetBSD.org/src/rev/ea42afcce16a
branches:  trunk
changeset: 946082:ea42afcce16a
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Nov 15 14:07:53 2020 +0000

description:
make(1): clean up some tests

Fix some mistakes in comments.

Improve some comments to be easier understandable.

Inline variables that are irrelevant for the test at hand (RUN,
MAKE_CMD).

Remove references to functions and constants that have since been removed
or renamed.

diffstat:

 usr.bin/make/unit-tests/archive-suffix.mk     |   4 +-
 usr.bin/make/unit-tests/archive.mk            |  30 ++++++++++------------
 usr.bin/make/unit-tests/cmd-interrupt.mk      |   4 +-
 usr.bin/make/unit-tests/cmdline.mk            |  11 +++----
 usr.bin/make/unit-tests/comment.mk            |  12 ++++++---
 usr.bin/make/unit-tests/cond-cmp-string.exp   |   8 +++---
 usr.bin/make/unit-tests/cond-cmp-string.mk    |  17 +++++++++---
 usr.bin/make/unit-tests/cond-func-commands.mk |   5 ++-
 usr.bin/make/unit-tests/cond-func-defined.exp |   3 ++
 usr.bin/make/unit-tests/cond-func-defined.mk  |  14 +++++++++-
 usr.bin/make/unit-tests/cond-func-empty.exp   |   4 +-
 usr.bin/make/unit-tests/cond-func-empty.mk    |  36 ++++++++++++++------------
 usr.bin/make/unit-tests/cond-func.exp         |  24 +++++++++---------
 usr.bin/make/unit-tests/cond-func.mk          |   6 +++-
 usr.bin/make/unit-tests/cond-late.mk          |  12 +++++---
 15 files changed, 110 insertions(+), 80 deletions(-)

diffs (truncated from 465 to 300 lines):

diff -r 3b2fcef542b2 -r ea42afcce16a usr.bin/make/unit-tests/archive-suffix.mk
--- a/usr.bin/make/unit-tests/archive-suffix.mk Sun Nov 15 14:04:26 2020 +0000
+++ b/usr.bin/make/unit-tests/archive-suffix.mk Sun Nov 15 14:07:53 2020 +0000
@@ -1,11 +1,11 @@
-# $NetBSD: archive-suffix.mk,v 1.2 2020/11/07 00:07:02 rillig Exp $
+# $NetBSD: archive-suffix.mk,v 1.3 2020/11/15 14:07:53 rillig Exp $
 #
 # Between 2020-08-23 and 2020-08-30, the below code produced an assertion
 # failure in Var_SetWithFlags, triggered by Compat_Make, when setting the
 # .IMPSRC of an archive node to its .TARGET.
 #
 # The code assumed that the .TARGET variable of every node would be set, but
-# but that is not guaranteed.
+# that is not guaranteed.
 #
 # Between 2016-03-15 and 2016-03-16 the behavior of the below code changed.
 # Until 2016-03-15, it remade the target, starting with 2016-03-16 it says
diff -r 3b2fcef542b2 -r ea42afcce16a usr.bin/make/unit-tests/archive.mk
--- a/usr.bin/make/unit-tests/archive.mk        Sun Nov 15 14:04:26 2020 +0000
+++ b/usr.bin/make/unit-tests/archive.mk        Sun Nov 15 14:07:53 2020 +0000
@@ -1,18 +1,15 @@
-# $NetBSD: archive.mk,v 1.10 2020/10/09 06:44:42 rillig Exp $
+# $NetBSD: archive.mk,v 1.11 2020/11/15 14:07:53 rillig Exp $
 #
 # Very basic demonstration of handling archives, based on the description
 # in PSD.doc/tutorial.ms.
 #
 # This test aims at covering the code, not at being an introduction to
-# archive handling. That's why it is more complicated and detailed than
-# strictly necessary.
+# archive handling. That's why it deviates from the tutorial style of
+# several other tests.
 
 ARCHIVE=       libprog.a
 FILES=         archive.mk modmisc.mk varmisc.mk
 
-MAKE_CMD=      ${.MAKE} -f ${MAKEFILE}
-RUN?=          @set -eu;
-
 all:
 .if ${.PARSEDIR:tA} != ${.CURDIR:tA}
        @cd ${MAKEFILE:H} && cp ${FILES} [at]*.mk ${.CURDIR}
@@ -20,13 +17,13 @@
 # The following targets create and remove files.  The filesystem cache in
 # dir.c would probably not handle this correctly, therefore each of the
 # targets is run in its separate sub-make.
-       ${RUN} ${MAKE_CMD} remove-archive
-       ${RUN} ${MAKE_CMD} create-archive
-       ${RUN} ${MAKE_CMD} list-archive
-       ${RUN} ${MAKE_CMD} list-archive-wildcard
-       ${RUN} ${MAKE_CMD} depend-on-existing-member
-       ${RUN} ${MAKE_CMD} depend-on-nonexistent-member
-       ${RUN} ${MAKE_CMD} remove-archive
+       @${MAKE} -f ${MAKEFILE} remove-archive
+       @${MAKE} -f ${MAKEFILE} create-archive
+       @${MAKE} -f ${MAKEFILE} list-archive
+       @${MAKE} -f ${MAKEFILE} list-archive-wildcard
+       @${MAKE} -f ${MAKEFILE} depend-on-existing-member
+       @${MAKE} -f ${MAKEFILE} depend-on-nonexistent-member
+       @${MAKE} -f ${MAKEFILE} remove-archive
 
 create-archive: ${ARCHIVE} pre post
 
@@ -43,15 +40,16 @@
 
 # XXX: I had expected that this dependency would select all *.mk files from
 # the archive.  Instead, the globbing is done in the current directory.
+#
 # To prevent an overly long file list, the pattern is restricted to [at]*.mk.
 list-archive-wildcard: ${ARCHIVE}([at]*.mk) pre post
-       ${RUN} printf '%s\n' ${.ALLSRC:O:@member@${.TARGET:Q}': '${member:Q}@}
+       @printf '%s\n' ${.ALLSRC:O:@member@${.TARGET:Q}': '${member:Q}@}
 
 depend-on-existing-member: ${ARCHIVE}(archive.mk) pre post
-       ${RUN} echo $@
+       @echo $@
 
 depend-on-nonexistent-member: ${ARCHIVE}(nonexistent.mk) pre post
-       ${RUN} echo $@
+       @echo $@
 
 remove-archive: pre post
        rm -f ${ARCHIVE}
diff -r 3b2fcef542b2 -r ea42afcce16a usr.bin/make/unit-tests/cmd-interrupt.mk
--- a/usr.bin/make/unit-tests/cmd-interrupt.mk  Sun Nov 15 14:04:26 2020 +0000
+++ b/usr.bin/make/unit-tests/cmd-interrupt.mk  Sun Nov 15 14:07:53 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: cmd-interrupt.mk,v 1.2 2020/08/28 18:16:22 rillig Exp $
+# $NetBSD: cmd-interrupt.mk,v 1.3 2020/11/15 14:07:53 rillig Exp $
 #
 # Tests for interrupting a command.
 #
@@ -22,7 +22,7 @@
 clean-before clean-after: .PHONY
        @rm -f cmd-interrupt-ordinary cmd-interrupt-phony cmd-interrupt-precious
 
-interrupt-ordinary: .PHONY
+interrupt-ordinary:
        @${.MAKE} ${MAKEFLAGS} -f ${MAKEFILE} cmd-interrupt-ordinary || true
        # The ././ is necessary to work around the file cache.
        @echo ${.TARGET}: ${exists(././cmd-interrupt-ordinary) :? error : ok }
diff -r 3b2fcef542b2 -r ea42afcce16a usr.bin/make/unit-tests/cmdline.mk
--- a/usr.bin/make/unit-tests/cmdline.mk        Sun Nov 15 14:04:26 2020 +0000
+++ b/usr.bin/make/unit-tests/cmdline.mk        Sun Nov 15 14:07:53 2020 +0000
@@ -1,8 +1,7 @@
-# $NetBSD: cmdline.mk,v 1.1 2020/07/28 22:44:44 rillig Exp $
+# $NetBSD: cmdline.mk,v 1.2 2020/11/15 14:07:53 rillig Exp $
 #
 # Tests for command line parsing and related special variables.
 
-RUN?=          @set -eu;
 TMPBASE?=      /tmp
 SUB1=          a7b41170-53f8-4cc2-bc5c-e4c3dd93ec45    # just a random UUID
 SUB2=          6a8899d2-d227-4b55-9b6b-f3c8eeb83fd5    # just a random UUID
@@ -14,14 +13,14 @@
 all: makeobjdir-direct makeobjdir-indirect
 
 prepare-dirs:
-       ${RUN} rm -rf ${DIR2} ${DIR12}
-       ${RUN} mkdir -p ${DIR2} ${DIR12}
+       @rm -rf ${DIR2} ${DIR12}
+       @mkdir -p ${DIR2} ${DIR12}
 
 # The .OBJDIR can be set via the MAKEOBJDIR command line variable.
 # It must be a command line variable; an environment variable would not work.
 makeobjdir-direct:
        @echo $@:
-       ${RUN} ${MAKE_CMD} MAKEOBJDIR=${DIR2} show-objdir
+       @${MAKE_CMD} MAKEOBJDIR=${DIR2} show-objdir
 
 # The .OBJDIR can be set via the MAKEOBJDIR command line variable,
 # and that variable could even contain the usual modifiers.
@@ -31,7 +30,7 @@
 # see MAKE_CMD.
 makeobjdir-indirect:
        @echo $@:
-       ${RUN} ${MAKE_CMD} MAKEOBJDIR='$${TMPBASE}/$${SUB2}' show-objdir
+       @${MAKE_CMD} MAKEOBJDIR='$${TMPBASE}/$${SUB2}' show-objdir
 
 show-objdir:
        @echo $@: ${.OBJDIR:Q}
diff -r 3b2fcef542b2 -r ea42afcce16a usr.bin/make/unit-tests/comment.mk
--- a/usr.bin/make/unit-tests/comment.mk        Sun Nov 15 14:04:26 2020 +0000
+++ b/usr.bin/make/unit-tests/comment.mk        Sun Nov 15 14:07:53 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: comment.mk,v 1.2 2020/09/07 19:17:36 rillig Exp $
+# $NetBSD: comment.mk,v 1.3 2020/11/15 14:07:53 rillig Exp $
 #
 # Demonstrate how comments are written in makefiles.
 
@@ -12,7 +12,7 @@
 goes \
 on and on.
 
- # Comments can be indented, but that is rather unusual.
+ # Comments can be indented with spaces, but that is rather unusual.
 
        # Comments can be indented with a tab.
        # These are not shell commands, they are just makefile comments.
@@ -21,6 +21,8 @@
 .endif                 # And after the closing directive.
 
 VAR=                   # This comment makes the variable value empty.
+                       # ParseGetLine removes any whitespace before the
+                       # comment.
 .if ${VAR} != ""
 .  error
 .endif
@@ -35,7 +37,9 @@
 .  error
 .endif
 
-# This is NOT an escaped comment due to the double backslashes \\
+# This comment ends with 2 backslashes.  An even number of backslashes does
+# not count as a line continuation, therefore the variable assignment that
+# follows is actively interpreted. \\
 VAR=   not part of the comment
 .if ${VAR} != "not part of the comment"
 .  error
@@ -55,7 +59,7 @@
 .  error
 .endif
 
-# An odd number of comment signs makes a line continuation, \\\
+# An odd number of backslashes makes a line continuation, \\\
 no matter if it is 3 or 5 \\\\\
 or 9 backslashes. \\\\\\\\\
 This is the last line of the comment.
diff -r 3b2fcef542b2 -r ea42afcce16a usr.bin/make/unit-tests/cond-cmp-string.exp
--- a/usr.bin/make/unit-tests/cond-cmp-string.exp       Sun Nov 15 14:04:26 2020 +0000
+++ b/usr.bin/make/unit-tests/cond-cmp-string.exp       Sun Nov 15 14:07:53 2020 +0000
@@ -1,8 +1,8 @@
 make: "cond-cmp-string.mk" line 18: Malformed conditional (str != str)
-make: "cond-cmp-string.mk" line 37: Malformed conditional ("string" != "str""ing")
-make: "cond-cmp-string.mk" line 42: warning: String comparison operator must be either == or !=
-make: "cond-cmp-string.mk" line 42: Malformed conditional (!("value" = "value"))
-make: "cond-cmp-string.mk" line 49: Malformed conditional (!("value" === "value"))
+make: "cond-cmp-string.mk" line 42: Malformed conditional ("string" != "str""ing")
+make: "cond-cmp-string.mk" line 49: warning: String comparison operator must be either == or !=
+make: "cond-cmp-string.mk" line 49: Malformed conditional (!("value" = "value"))
+make: "cond-cmp-string.mk" line 56: Malformed conditional (!("value" === "value"))
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1
diff -r 3b2fcef542b2 -r ea42afcce16a usr.bin/make/unit-tests/cond-cmp-string.mk
--- a/usr.bin/make/unit-tests/cond-cmp-string.mk        Sun Nov 15 14:04:26 2020 +0000
+++ b/usr.bin/make/unit-tests/cond-cmp-string.mk        Sun Nov 15 14:07:53 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: cond-cmp-string.mk,v 1.12 2020/11/08 23:00:09 rillig Exp $
+# $NetBSD: cond-cmp-string.mk,v 1.13 2020/11/15 14:07:53 rillig Exp $
 #
 # Tests for string comparisons in .if conditions.
 
@@ -19,9 +19,14 @@
 .  error
 .endif
 
-# The left-hand side of the comparison requires a defined variable.
-# The variable named "" is not defined, but applying the :U modifier to it
-# makes it "kind of defined" (see VAR_KEEP).  Therefore it is ok here.
+# The left-hand side of the comparison requires that any variable expression
+# is defined.
+#
+# The variable named "" is never defined, nevertheless it can be used as a
+# starting point for variable expressions.  Applying the :U modifier to such
+# an undefined expression turns it into a defined expression.
+#
+# See ApplyModifier_Defined and VEF_DEF.
 .if ${:Ustr} != "str"
 .  error
 .endif
@@ -33,9 +38,11 @@
 .endif
 
 # It is not possible to concatenate two string literals to form a single
-# string.
+# string.  In C, Python and the shell this is possible, but not in make.
 .if "string" != "str""ing"
 .  error
+.else
+.  error
 .endif
 
 # There is no = operator for strings.
diff -r 3b2fcef542b2 -r ea42afcce16a usr.bin/make/unit-tests/cond-func-commands.mk
--- a/usr.bin/make/unit-tests/cond-func-commands.mk     Sun Nov 15 14:04:26 2020 +0000
+++ b/usr.bin/make/unit-tests/cond-func-commands.mk     Sun Nov 15 14:07:53 2020 +0000
@@ -1,10 +1,11 @@
-# $NetBSD: cond-func-commands.mk,v 1.4 2020/10/24 08:46:08 rillig Exp $
+# $NetBSD: cond-func-commands.mk,v 1.5 2020/11/15 14:07:53 rillig Exp $
 #
 # Tests for the commands() function in .if conditions.
 
 .MAIN: all
 
-# The target "target" does not exist yet, therefore it cannot have commands.
+# At this point, the target 'target' does not exist yet, therefore it cannot
+# have commands.  Sounds obvious, but good to know that it is really so.
 .if commands(target)
 .  error
 .endif
diff -r 3b2fcef542b2 -r ea42afcce16a usr.bin/make/unit-tests/cond-func-defined.exp
--- a/usr.bin/make/unit-tests/cond-func-defined.exp     Sun Nov 15 14:04:26 2020 +0000
+++ b/usr.bin/make/unit-tests/cond-func-defined.exp     Sun Nov 15 14:07:53 2020 +0000
@@ -2,6 +2,9 @@
 make: "cond-func-defined.mk" line 23: Malformed conditional (!defined(A B))
 make: "cond-func-defined.mk" line 33: warning: Missing closing parenthesis for defined()
 make: "cond-func-defined.mk" line 33: Malformed conditional (defined(DEF)
+make: "cond-func-defined.mk" line 45: In .for loops, variable expressions for the loop variables are
+make: "cond-func-defined.mk" line 46: substituted at evaluation time.  There is no actual variable
+make: "cond-func-defined.mk" line 47: involved, even if it feels like it.
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1
diff -r 3b2fcef542b2 -r ea42afcce16a usr.bin/make/unit-tests/cond-func-defined.mk
--- a/usr.bin/make/unit-tests/cond-func-defined.mk      Sun Nov 15 14:04:26 2020 +0000
+++ b/usr.bin/make/unit-tests/cond-func-defined.mk      Sun Nov 15 14:07:53 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: cond-func-defined.mk,v 1.6 2020/11/07 14:40:51 rillig Exp $
+# $NetBSD: cond-func-defined.mk,v 1.7 2020/11/15 14:07:53 rillig Exp $
 #
 # Tests for the defined() function in .if conditions.
 
@@ -36,5 +36,17 @@
 .  error
 .endif
 
+# Variables from .for loops are not defined.
+# See directive-for.mk for more details.
+.for var in value
+.  if defined(var)
+.    error
+.  else
+.    info In .for loops, variable expressions for the loop variables are
+.    info substituted at evaluation time.  There is no actual variable
+.    info involved, even if it feels like it.
+.  endif
+.endfor
+
 all:



Home | Main Index | Thread Index | Old Index