Module Name:    src
Committed By:   rillig
Date:           Sun Dec 17 14:07:22 UTC 2023

Modified Files:
        src/usr.bin/make/unit-tests: directive-include-guard.exp
            directive-include-guard.mk var-scope-local-legacy.exp
            var-scope-local-legacy.mk varmod-mtime.mk varmod-range.exp
            varmod-range.mk varmod-subst-regex.mk varmod-subst.mk

Log Message:
tests/make: extend tests for include guards and empty expressions


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 \
    src/usr.bin/make/unit-tests/directive-include-guard.exp
cvs rdiff -u -r1.15 -r1.16 \
    src/usr.bin/make/unit-tests/directive-include-guard.mk
cvs rdiff -u -r1.2 -r1.3 \
    src/usr.bin/make/unit-tests/var-scope-local-legacy.exp \
    src/usr.bin/make/unit-tests/var-scope-local-legacy.mk
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/make/unit-tests/varmod-mtime.mk
cvs rdiff -u -r1.10 -r1.11 src/usr.bin/make/unit-tests/varmod-range.exp
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/make/unit-tests/varmod-range.mk \
    src/usr.bin/make/unit-tests/varmod-subst-regex.mk
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/make/unit-tests/varmod-subst.mk

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/make/unit-tests/directive-include-guard.exp
diff -u src/usr.bin/make/unit-tests/directive-include-guard.exp:1.13 src/usr.bin/make/unit-tests/directive-include-guard.exp:1.14
--- src/usr.bin/make/unit-tests/directive-include-guard.exp:1.13	Sun Dec 17 09:17:16 2023
+++ src/usr.bin/make/unit-tests/directive-include-guard.exp	Sun Dec 17 14:07:22 2023
@@ -99,4 +99,6 @@ Parse_PushInput: file target-name-parent
 Parse_PushInput: file target-name-parenthesized.tmp, line 1
 Parse_PushInput: file target-call-parenthesized.tmp, line 1
 Parse_PushInput: file target-call-parenthesized.tmp, line 1
+Parse_PushInput: file multiline.tmp, line 1
+Skipping 'multiline.tmp' because 'MULTILINE' is defined
 exit status 0

Index: src/usr.bin/make/unit-tests/directive-include-guard.mk
diff -u src/usr.bin/make/unit-tests/directive-include-guard.mk:1.15 src/usr.bin/make/unit-tests/directive-include-guard.mk:1.16
--- src/usr.bin/make/unit-tests/directive-include-guard.mk:1.15	Sun Dec 17 09:17:16 2023
+++ src/usr.bin/make/unit-tests/directive-include-guard.mk	Sun Dec 17 14:07:22 2023
@@ -1,4 +1,4 @@
-# $NetBSD: directive-include-guard.mk,v 1.15 2023/12/17 09:17:16 rillig Exp $
+# $NetBSD: directive-include-guard.mk,v 1.16 2023/12/17 14:07:22 rillig Exp $
 #
 # Tests for multiple-inclusion guards in makefiles.
 #
@@ -601,6 +601,20 @@ LINES.target-call-parenthesized= \
 # expect: Parse_PushInput: file target-call-parenthesized.tmp, line 1
 # expect: Parse_PushInput: file target-call-parenthesized.tmp, line 1
 
+# If the '.if' or '.ifndef' directive spans more than a single line, it is
+# still recognized as a guard condition.  This case is entirely uncommon, but
+# at the point where the guard condition is checked, line continuations have
+# already been converted to spaces.
+CASES+=	multiline
+LINES.multiline= \
+	'.\' \
+	'  ifndef \' \
+	'  MULTILINE' \
+	'MULTILINE=' \
+	'.endif'
+# expect: Parse_PushInput: file multiline.tmp, line 1
+# expect: Skipping 'multiline.tmp' because 'MULTILINE' is defined
+
 
 # Now run all test cases by including each of the files twice and looking at
 # the debug output.  The files that properly guard against multiple inclusion

Index: src/usr.bin/make/unit-tests/var-scope-local-legacy.exp
diff -u src/usr.bin/make/unit-tests/var-scope-local-legacy.exp:1.2 src/usr.bin/make/unit-tests/var-scope-local-legacy.exp:1.3
--- src/usr.bin/make/unit-tests/var-scope-local-legacy.exp:1.2	Tue Sep 27 19:18:45 2022
+++ src/usr.bin/make/unit-tests/var-scope-local-legacy.exp	Sun Dec 17 14:07:22 2023
@@ -2,5 +2,5 @@
 : XY=undef_
 : AF=undef_
 : %D=undef_ %F=undef_
-: @D=._ @F=all_
+: @D=global-value_ @F=all_
 exit status 0
Index: src/usr.bin/make/unit-tests/var-scope-local-legacy.mk
diff -u src/usr.bin/make/unit-tests/var-scope-local-legacy.mk:1.2 src/usr.bin/make/unit-tests/var-scope-local-legacy.mk:1.3
--- src/usr.bin/make/unit-tests/var-scope-local-legacy.mk:1.2	Tue Sep 27 19:18:45 2022
+++ src/usr.bin/make/unit-tests/var-scope-local-legacy.mk	Sun Dec 17 14:07:22 2023
@@ -1,7 +1,24 @@
-# $NetBSD: var-scope-local-legacy.mk,v 1.2 2022/09/27 19:18:45 rillig Exp $
+# $NetBSD: var-scope-local-legacy.mk,v 1.3 2023/12/17 14:07:22 rillig Exp $
 #
 # Tests for legacy target-local variables, such as ${<F} or ${@D}.
 
+
+# In the global or command line scopes, the legacy forms are not recognized,
+# as the target-specific variables are not available either.  The expressions
+# are retained so that they can be resolved later, in the target scope.
+.if "${@D}" != "\${@D}"
+.  error
+.endif
+
+# It's possible to define variables of the legacy name in the global or
+# command line scope, and they override the target-local variables, leading to
+# unnecessary confusion.
+@D=	global-value
+.if "${@D}" != "global-value"
+.  error
+.endif
+
+
 all: .PHONY
 	# Only variables of length 2 can be legacy, this one cannot.
 	: LEN4=${LEN4:Uundef}_
@@ -13,5 +30,6 @@ all: .PHONY
 	# The variable '.MEMBER' is undefined, therefore '%D' and '%F' are
 	# undefined as well.
 	: %D=${%D:Uundef}_ %F=${%F:Uundef}_
-	# The directory name of the target is '.', its basename is 'all'.
+	# The directory name of the target is shadowed by the global variable,
+	# it would be '.' otherwise.  The basename is 'all'.
 	: @D=${@D:Uundef}_ @F=${@F:Uundef}_

Index: src/usr.bin/make/unit-tests/varmod-mtime.mk
diff -u src/usr.bin/make/unit-tests/varmod-mtime.mk:1.8 src/usr.bin/make/unit-tests/varmod-mtime.mk:1.9
--- src/usr.bin/make/unit-tests/varmod-mtime.mk:1.8	Sun Nov 19 12:11:34 2023
+++ src/usr.bin/make/unit-tests/varmod-mtime.mk	Sun Dec 17 14:07:22 2023
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-mtime.mk,v 1.8 2023/11/19 12:11:34 rillig Exp $
+# $NetBSD: varmod-mtime.mk,v 1.9 2023/12/17 14:07:22 rillig Exp $
 #
 # Tests for the ':mtime' variable modifier, which maps each word of the
 # expression to that file's modification time.
@@ -104,7 +104,7 @@ end:=	${%s:L:gmtime}
 
 # If the expression is irrelevant, the ':mtime' modifier is only parsed, it
 # does not perform any filesystem operations.
-.if 0 && ${anything:L:mtime}
+.if 0 && ${no/such/file:L:mtime=error}
 .  error
 .endif
 
@@ -117,3 +117,9 @@ end:=	${%s:L:gmtime}
 .else
 .  error
 .endif
+
+
+# An empty word list results in an empty mtime list.
+.if ${:U:mtime} != ""
+.  error
+.endif

Index: src/usr.bin/make/unit-tests/varmod-range.exp
diff -u src/usr.bin/make/unit-tests/varmod-range.exp:1.10 src/usr.bin/make/unit-tests/varmod-range.exp:1.11
--- src/usr.bin/make/unit-tests/varmod-range.exp:1.10	Thu Jun  1 20:56:35 2023
+++ src/usr.bin/make/unit-tests/varmod-range.exp	Sun Dec 17 14:07:22 2023
@@ -1,13 +1,14 @@
-make: "varmod-range.mk" line 55: Invalid number "x}Rest" != "Rest"" for ':range' modifier
-make: "varmod-range.mk" line 55: Malformed conditional ("${:U:range=x}Rest" != "Rest")
-make: "varmod-range.mk" line 66: Unknown modifier "x0"
-make: "varmod-range.mk" line 66: Malformed conditional ("${:U:range=0x0}Rest" != "Rest")
-make: "varmod-range.mk" line 84: Unknown modifier "rang"
-make: "varmod-range.mk" line 84: Malformed conditional ("${a b c:L:rang}Rest" != "Rest")
-make: "varmod-range.mk" line 93: Unknown modifier "rango"
-make: "varmod-range.mk" line 93: Malformed conditional ("${a b c:L:rango}Rest" != "Rest")
-make: "varmod-range.mk" line 102: Unknown modifier "ranger"
-make: "varmod-range.mk" line 102: Malformed conditional ("${a b c:L:ranger}Rest" != "Rest")
+make: "varmod-range.mk" line 43: Malformed conditional (${:range=5} != "")
+make: "varmod-range.mk" line 67: Invalid number "x}Rest" != "Rest"" for ':range' modifier
+make: "varmod-range.mk" line 67: Malformed conditional ("${:U:range=x}Rest" != "Rest")
+make: "varmod-range.mk" line 78: Unknown modifier "x0"
+make: "varmod-range.mk" line 78: Malformed conditional ("${:U:range=0x0}Rest" != "Rest")
+make: "varmod-range.mk" line 96: Unknown modifier "rang"
+make: "varmod-range.mk" line 96: Malformed conditional ("${a b c:L:rang}Rest" != "Rest")
+make: "varmod-range.mk" line 105: Unknown modifier "rango"
+make: "varmod-range.mk" line 105: Malformed conditional ("${a b c:L:rango}Rest" != "Rest")
+make: "varmod-range.mk" line 114: Unknown modifier "ranger"
+make: "varmod-range.mk" line 114: Malformed conditional ("${a b c:L:ranger}Rest" != "Rest")
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1

Index: src/usr.bin/make/unit-tests/varmod-range.mk
diff -u src/usr.bin/make/unit-tests/varmod-range.mk:1.9 src/usr.bin/make/unit-tests/varmod-range.mk:1.10
--- src/usr.bin/make/unit-tests/varmod-range.mk:1.9	Sun Nov 19 21:47:52 2023
+++ src/usr.bin/make/unit-tests/varmod-range.mk	Sun Dec 17 14:07:22 2023
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-range.mk,v 1.9 2023/11/19 21:47:52 rillig Exp $
+# $NetBSD: varmod-range.mk,v 1.10 2023/12/17 14:07:22 rillig Exp $
 #
 # Tests for the :range variable modifier, which generates sequences
 # of integers from the given range.
@@ -25,14 +25,26 @@
 .  error
 .endif
 
+# An empty expression results in a sequence of a single number, even though
+# the expression contains 0 words.
+.if ${:U:range} != "1"
+.  error
+.endif
+
 # The :range modifier can be given a parameter, which makes the generated
 # range independent from the value or the name of the expression.
-#
-# XXX: As of 2020-09-27, the :range=... modifier does not turn the undefined
-# expression into a defined one.  This looks like an oversight.
 .if "${:range=5}" != ""
 .  error
 .endif
+# XXX: As of 2023-12-17, the ':range=n' modifier does not turn the undefined
+# expression into a defined one, even though it does not depend on the value
+# of the expression.  This looks like an oversight.
+# expect+1: Malformed conditional (${:range=5} != "")
+.if ${:range=5} != ""
+.  error
+.else
+.  error
+.endif
 
 # Negative ranges don't make sense.
 # As of 2020-11-01, they are accepted though, using up all available memory.
Index: src/usr.bin/make/unit-tests/varmod-subst-regex.mk
diff -u src/usr.bin/make/unit-tests/varmod-subst-regex.mk:1.9 src/usr.bin/make/unit-tests/varmod-subst-regex.mk:1.10
--- src/usr.bin/make/unit-tests/varmod-subst-regex.mk:1.9	Sun Dec 10 14:30:51 2023
+++ src/usr.bin/make/unit-tests/varmod-subst-regex.mk	Sun Dec 17 14:07:22 2023
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-subst-regex.mk,v 1.9 2023/12/10 14:30:51 rillig Exp $
+# $NetBSD: varmod-subst-regex.mk,v 1.10 2023/12/17 14:07:22 rillig Exp $
 #
 # Tests for the :C,from,to, variable modifier.
 
@@ -85,10 +85,10 @@ all: unmatched-subexpression
 .endif
 
 
-# Contrary to the ':S' modifier, the ':C' modifier matches on an expression
+# Like the ':S' modifier, the ':C' modifier matches on an expression
 # that contains no words at all, but only if the regular expression matches an
 # empty string, for example, when the regular expression is anchored at the
-# beginning or the end.
+# beginning or the end of the word.
 .if "<${U:S,^,prefix,}> <${:U:C,^,prefix,}>" != "<> <prefix>"
 .  error
 .endif
@@ -126,7 +126,7 @@ mod-regex-limits:
 	@echo $@:22-missing:${:U1 23 456:C,(.).,\2\2,:Q}
 	@echo $@:22-ok:${:U1 23 456:C,(.)(.),\2\2,:Q}
 	# The :C modifier only handles single-digit capturing groups,
-	# which is more than enough for daily use.
+	# which is enough for all practical use cases.
 	@echo $@:capture:${:UabcdefghijABCDEFGHIJrest:C,(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.),\9\8\7\6\5\4\3\2\1\0\10\11\12,}
 
 mod-regex-errors:

Index: src/usr.bin/make/unit-tests/varmod-subst.mk
diff -u src/usr.bin/make/unit-tests/varmod-subst.mk:1.12 src/usr.bin/make/unit-tests/varmod-subst.mk:1.13
--- src/usr.bin/make/unit-tests/varmod-subst.mk:1.12	Fri Jun 16 07:20:45 2023
+++ src/usr.bin/make/unit-tests/varmod-subst.mk	Sun Dec 17 14:07:22 2023
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-subst.mk,v 1.12 2023/06/16 07:20:45 rillig Exp $
+# $NetBSD: varmod-subst.mk,v 1.13 2023/12/17 14:07:22 rillig Exp $
 #
 # Tests for the :S,from,to, variable modifier.
 
@@ -9,7 +9,8 @@ all: mod-subst-dollar
 
 WORDS=		sequences of letters
 
-# The empty pattern never matches anything.
+# The empty pattern never matches anything, except if it is anchored at the
+# beginning or the end of the word.
 .if ${WORDS:S,,,} != ${WORDS}
 .  error
 .endif
@@ -141,6 +142,22 @@ WORDS=		sequences of letters
 .endif
 
 
+# In an empty expression, the ':S' modifier matches a single time if the
+# search string is anchored at the beginning or at the end.
+.if ${:U:S,,out-of-nothing,} != ""
+.  error
+.endif
+.if ${:U:S,^,out-of-nothing,} != "out-of-nothing"
+.  error
+.endif
+.if ${:U:S,$,out-of-nothing,} != "out-of-nothing"
+.  error
+.endif
+.if ${:U:S,^$,out-of-nothing,} != "out-of-nothing"
+.  error
+.endif
+
+
 mod-subst:
 	@echo $@:
 	@echo :${:Ua b b c:S,a b,,:Q}:

Reply via email to