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.
This commit is contained in:
rillig 2020-11-15 14:07:53 +00:00
parent 6a13e2b2ff
commit e3d2e555ae
15 changed files with 110 additions and 80 deletions

View File

@ -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

View File

@ -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 @@ all:
# 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 @@ list-archive: ${ARCHIVE} pre post
# 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}

View File

@ -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 @@ all: clean-before interrupt-ordinary interrupt-phony interrupt-precious clean-af
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 }

View File

@ -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: prepare-dirs
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 @@ makeobjdir-direct:
# 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}

View File

@ -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 @@ that \
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 @@ on and on.
.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 @@ VAR= value
. 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 @@ WORDS= ${VAR:[#]} [#
. 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.

View File

@ -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

View File

@ -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.

View File

@ -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

View File

@ -2,6 +2,9 @@ make: "cond-func-defined.mk" line 23: warning: Missing closing parenthesis for d
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

View File

@ -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 @@ ${:UA B}= variable name with spaces
. 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:
@:;

View File

@ -1,5 +1,5 @@
make: "cond-func-empty.mk" line 150: Unclosed variable "WORD"
make: "cond-func-empty.mk" line 150: Malformed conditional (empty(WORD)
make: "cond-func-empty.mk" line 152: Unclosed variable "WORD"
make: "cond-func-empty.mk" line 152: Malformed conditional (empty(WORD)
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1

View File

@ -1,11 +1,10 @@
# $NetBSD: cond-func-empty.mk,v 1.9 2020/11/07 14:37:31 rillig Exp $
# $NetBSD: cond-func-empty.mk,v 1.10 2020/11/15 14:07:53 rillig Exp $
#
# Tests for the empty() function in .if conditions, which tests a variable
# expression for emptiness.
#
# Note that the argument in the parentheses is indeed a variable name,
# optionally followed by variable modifiers. This is like the defined()
# function.
# optionally followed by variable modifiers.
#
.undef UNDEF
@ -25,13 +24,15 @@ WORD= word
. error
.endif
# The :S modifier replaces the empty value with an actual word, and
# after that the expression is no longer empty. Because the variable
# was undefined in the first place, the expression has the flag VAR_JUNK
# but not VAR_KEEP, therefore it is still considered undefined.
# Only very few variable modifiers turn an undefined variable expression
# into a defined variable expression. The :U and :D modifiers belong to
# that group, but :S doesn't (see VAR_KEEP).
# The :S modifier replaces the empty value with an actual word. The
# expression is now no longer empty, but it is still possible to see whether
# the expression was based on an undefined variable. The expression has the
# flag VEF_UNDEF.
#
# The expression does not have the flag VEF_DEF though, therefore it is still
# considered undefined. Yes, indeed, undefined but not empty. There are a
# few variable modifiers that turn an undefined expression into a defined
# expression, among them :U and :D, but not :S.
#
# XXX: This is hard to explain to someone who doesn't know these
# implementation details.
@ -49,13 +50,14 @@ WORD= word
.endif
# And now to the surprising part. Applying the following :S modifier to the
# undefined variable makes it non-empty, but the marker VAR_JUNK is preserved
# nevertheless. The :U modifier that follows only looks at VAR_JUNK to decide
# whether the variable is defined or not. This kind of makes sense since the
# :U modifier tests the _variable_, not the _expression_.
# undefined expression makes it non-empty, but the marker VEF_UNDEF is
# preserved nevertheless. The :U modifier that follows only looks at the
# VEF_UNDEF flag to decide whether the variable is defined or not. This kind
# of makes sense since the :U modifier tests the _variable_, not the
# _expression_.
#
# But since the variable was undefined to begin with, the fallback value is
# used in this expression.
# But since the variable was undefined to begin with, the fallback value from
# the :U modifier is used in this expression.
#
.if ${UNDEF:S,^$,value,W:Ufallback} != "fallback"
. error
@ -128,7 +130,7 @@ ${:U }= space
# If everything goes well, the argument expands to "WORD", and that variable
# is defined at the beginning of this file. The surrounding 'W' and 'D'
# ensure that the parser in ParseEmptyArg has the correct position, both
# before and after the call to Var_ParsePP.
# before and after the call to Var_Parse.
.if empty(W${:UOR}D)
. error
.endif

View File

@ -1,15 +1,15 @@
make: "cond-func.mk" line 34: warning: Missing closing parenthesis for defined()
make: "cond-func.mk" line 34: Malformed conditional (!defined(A B))
make: "cond-func.mk" line 49: warning: Missing closing parenthesis for defined()
make: "cond-func.mk" line 49: Malformed conditional (!defined(A&B))
make: "cond-func.mk" line 52: warning: Missing closing parenthesis for defined()
make: "cond-func.mk" line 52: Malformed conditional (!defined(A|B))
make: "cond-func.mk" line 92: The empty variable is never defined.
make: "cond-func.mk" line 100: A plain function name is parsed as !empty(...).
make: "cond-func.mk" line 107: A plain function name is parsed as !empty(...).
make: "cond-func.mk" line 117: Symbols may start with a function name.
make: "cond-func.mk" line 122: Symbols may start with a function name.
make: "cond-func.mk" line 128: Malformed conditional (defined()
make: "cond-func.mk" line 36: warning: Missing closing parenthesis for defined()
make: "cond-func.mk" line 36: Malformed conditional (!defined(A B))
make: "cond-func.mk" line 51: warning: Missing closing parenthesis for defined()
make: "cond-func.mk" line 51: Malformed conditional (!defined(A&B))
make: "cond-func.mk" line 54: warning: Missing closing parenthesis for defined()
make: "cond-func.mk" line 54: Malformed conditional (!defined(A|B))
make: "cond-func.mk" line 94: The empty variable is never defined.
make: "cond-func.mk" line 102: A plain function name is parsed as !empty(...).
make: "cond-func.mk" line 109: A plain function name is parsed as !empty(...).
make: "cond-func.mk" line 119: Symbols may start with a function name.
make: "cond-func.mk" line 124: Symbols may start with a function name.
make: "cond-func.mk" line 130: Malformed conditional (defined()
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1

View File

@ -1,10 +1,12 @@
# $NetBSD: cond-func.mk,v 1.8 2020/11/10 20:44:18 rillig Exp $
# $NetBSD: cond-func.mk,v 1.9 2020/11/15 14:07:53 rillig Exp $
#
# Tests for those parts of the functions in .if conditions that are common
# among several functions.
#
# The below test uses the function defined(...) since it has no side-effects,
# the other functions (except empty(...)) would work equally well.
# the other functions (except empty(...)) would work equally well. The
# function empty is special because it uses a different parsing algorithm for
# its argument.
DEF= defined
${:UA B}= variable name with spaces

View File

@ -1,7 +1,9 @@
# $NetBSD: cond-late.mk,v 1.2 2020/07/25 20:37:46 rillig Exp $
# $NetBSD: cond-late.mk,v 1.3 2020/11/15 14:07:53 rillig Exp $
#
# Using the :? modifier, variable expressions can contain conditional
# expressions that are evaluated late. Any variables appearing in these
# expressions that are evaluated late, at expansion time.
#
# Any variables appearing in these
# conditions are expanded before parsing the condition. This is
# different from many other places.
#
@ -11,15 +13,15 @@
# They should also not contain operators like == or <, since these are
# actually interpreted as these operators. This is demonstrated below.
#
# If the order of evaluation were to change to first parse the condition
# and then expand the variables, the output would change from the
# current "yes no" to "yes yes", since both variables are non-empty.
all: cond-literal
COND.true= "yes" == "yes"
COND.false= "yes" != "yes"
# If the order of evaluation were to change to first parse the condition
# and then expand the variables, the output would change from the
# current "yes no" to "yes yes", since both variables are non-empty.
cond-literal:
@echo ${ ${COND.true} :?yes:no}
@echo ${ ${COND.false} :?yes:no}