Module Name:    src
Committed By:   rillig
Date:           Sat Jun  1 18:44:05 UTC 2024

Modified Files:
        src/usr.bin/make/unit-tests: directive-export-literal.exp
            directive-export-literal.mk varmod-head.mk varmod-sysv.exp
            varmod-sysv.mk varmod-tail.mk varmod-to-separator.exp
            varmod-to-separator.mk varmod.exp varmod.mk
            varname-dot-make-level.exp varname-dot-make-level.mk

Log Message:
tests/make: test more modifiers and special variables


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 \
    src/usr.bin/make/unit-tests/directive-export-literal.exp \
    src/usr.bin/make/unit-tests/varmod-tail.mk
cvs rdiff -u -r1.7 -r1.8 \
    src/usr.bin/make/unit-tests/directive-export-literal.mk
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/make/unit-tests/varmod-head.mk
cvs rdiff -u -r1.10 -r1.11 src/usr.bin/make/unit-tests/varmod-sysv.exp
cvs rdiff -u -r1.16 -r1.17 src/usr.bin/make/unit-tests/varmod-sysv.mk
cvs rdiff -u -r1.12 -r1.13 \
    src/usr.bin/make/unit-tests/varmod-to-separator.exp
cvs rdiff -u -r1.14 -r1.15 src/usr.bin/make/unit-tests/varmod-to-separator.mk
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/make/unit-tests/varmod.exp
cvs rdiff -u -r1.11 -r1.12 src/usr.bin/make/unit-tests/varmod.mk
cvs rdiff -u -r1.1 -r1.2 \
    src/usr.bin/make/unit-tests/varname-dot-make-level.exp
cvs rdiff -u -r1.2 -r1.3 \
    src/usr.bin/make/unit-tests/varname-dot-make-level.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-export-literal.exp
diff -u src/usr.bin/make/unit-tests/directive-export-literal.exp:1.4 src/usr.bin/make/unit-tests/directive-export-literal.exp:1.5
--- src/usr.bin/make/unit-tests/directive-export-literal.exp:1.4	Mon Oct  5 19:27:48 2020
+++ src/usr.bin/make/unit-tests/directive-export-literal.exp	Sat Jun  1 18:44:05 2024
@@ -1,2 +1,5 @@
 value with ${UNEXPANDED} expression
+value literal
+value indirect
+value ${indirect:L}
 exit status 0
Index: src/usr.bin/make/unit-tests/varmod-tail.mk
diff -u src/usr.bin/make/unit-tests/varmod-tail.mk:1.4 src/usr.bin/make/unit-tests/varmod-tail.mk:1.5
--- src/usr.bin/make/unit-tests/varmod-tail.mk:1.4	Sun Dec 20 22:57:40 2020
+++ src/usr.bin/make/unit-tests/varmod-tail.mk	Sat Jun  1 18:44:05 2024
@@ -1,8 +1,16 @@
-# $NetBSD: varmod-tail.mk,v 1.4 2020/12/20 22:57:40 rillig Exp $
+# $NetBSD: varmod-tail.mk,v 1.5 2024/06/01 18:44:05 rillig Exp $
 #
 # Tests for the :T variable modifier, which returns the basename of each of
 # the words in the variable value.
 
+
+# If the ':T' is not directly followed by a delimiting ':' or '}', the
+# ':from=to' modifier is tried as a fallback.
+.if ${:U Tail :Tail=replaced} != "replaced"
+.  error
+.endif
+
+
 all:
 .for path in a/b/c def a.b.c a.b/c a a.a .gitignore a a.a trailing/
 	@echo "tail (basename) of '"${path:Q}"' is '"${path:T:Q}"'"

Index: src/usr.bin/make/unit-tests/directive-export-literal.mk
diff -u src/usr.bin/make/unit-tests/directive-export-literal.mk:1.7 src/usr.bin/make/unit-tests/directive-export-literal.mk:1.8
--- src/usr.bin/make/unit-tests/directive-export-literal.mk:1.7	Sun Dec 13 01:07:54 2020
+++ src/usr.bin/make/unit-tests/directive-export-literal.mk	Sat Jun  1 18:44:05 2024
@@ -1,4 +1,4 @@
-# $NetBSD: directive-export-literal.mk,v 1.7 2020/12/13 01:07:54 rillig Exp $
+# $NetBSD: directive-export-literal.mk,v 1.8 2024/06/01 18:44:05 rillig Exp $
 #
 # Tests for the .export-literal directive, which exports a variable value
 # without expanding it.
@@ -9,5 +9,28 @@ UT_VAR=		value with ${UNEXPANDED} expres
 
 .export-literal			# oops: missing argument
 
+# After a variable whose value does not contain a '$' is exported, a following
+# .export-literal can be skipped, to avoid a setenv call, which may leak
+# memory on some platforms.
+UT_TWICE_LITERAL=	value literal
+.export UT_TWICE_LITERAL
+.export-literal UT_TWICE_LITERAL
+
+# XXX: After an .export, an .export-literal has no effect, even when the
+# variable value contains a '$'.
+UT_TWICE_EXPR=		value ${indirect:L}
+.export UT_TWICE_EXPR
+.export-literal UT_TWICE_EXPR
+
+# After an .export, an .unexport resets the variable's exported state,
+# re-enabling a later .export-literal.
+UT_TWICE_EXPR_UNEXPORT=	value ${indirect:L}
+.export UT_TWICE_EXPR_UNEXPORT
+.unexport UT_TWICE_EXPR_UNEXPORT
+.export-literal UT_TWICE_EXPR_UNEXPORT
+
 all:
 	@echo "$$UT_VAR"
+	@echo "$$UT_TWICE_LITERAL"
+	@echo "$$UT_TWICE_EXPR"
+	@echo "$$UT_TWICE_EXPR_UNEXPORT"

Index: src/usr.bin/make/unit-tests/varmod-head.mk
diff -u src/usr.bin/make/unit-tests/varmod-head.mk:1.5 src/usr.bin/make/unit-tests/varmod-head.mk:1.6
--- src/usr.bin/make/unit-tests/varmod-head.mk:1.5	Sun Jul 10 21:11:49 2022
+++ src/usr.bin/make/unit-tests/varmod-head.mk	Sat Jun  1 18:44:05 2024
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-head.mk,v 1.5 2022/07/10 21:11:49 rillig Exp $
+# $NetBSD: varmod-head.mk,v 1.6 2024/06/01 18:44:05 rillig Exp $
 #
 # Tests for the :H variable modifier, which returns the dirname of
 # each of the words in the variable value.
@@ -61,4 +61,10 @@ _!=	echo "The modifier ':H' generates an
 .  error
 .endif
 
+# If the ':H' is not directly followed by a delimiting ':' or '}', the
+# ':from=to' modifier is tried as a fallback.
+.if ${:U Head :Head=replaced} != "replaced"
+.  error
+.endif
+
 all: .PHONY

Index: src/usr.bin/make/unit-tests/varmod-sysv.exp
diff -u src/usr.bin/make/unit-tests/varmod-sysv.exp:1.10 src/usr.bin/make/unit-tests/varmod-sysv.exp:1.11
--- src/usr.bin/make/unit-tests/varmod-sysv.exp:1.10	Thu Jun  1 20:56:35 2023
+++ src/usr.bin/make/unit-tests/varmod-sysv.exp	Sat Jun  1 18:44:05 2024
@@ -145,6 +145,8 @@ pre-middle-suffix        pre%ffix=NPre% 
 suffix                   pre%ffix=NPre%NS         "suffix"
 prefix                   pre%ffix=NPre%NS         "prefix"
 pre-middle-suffix        pre%ffix=NPre%NS         "NPre-middle-suNS"
+make: Unfinished modifier for "error" ('}' missing)
+make: "varmod-sysv.mk" line 259: Malformed conditional (${error:L:from=$(}))
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1

Index: src/usr.bin/make/unit-tests/varmod-sysv.mk
diff -u src/usr.bin/make/unit-tests/varmod-sysv.mk:1.16 src/usr.bin/make/unit-tests/varmod-sysv.mk:1.17
--- src/usr.bin/make/unit-tests/varmod-sysv.mk:1.16	Sun Nov 19 21:47:52 2023
+++ src/usr.bin/make/unit-tests/varmod-sysv.mk	Sat Jun  1 18:44:05 2024
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-sysv.mk,v 1.16 2023/11/19 21:47:52 rillig Exp $
+# $NetBSD: varmod-sysv.mk,v 1.17 2024/06/01 18:44:05 rillig Exp $
 #
 # Tests for the variable modifier ':from=to', which replaces the suffix
 # "from" with "to".  It can also use '%' as a wildcard.
@@ -252,4 +252,12 @@ INDIRECT=	1:${VALUE} 2:$${VALUE} 4:$$$${
 .  endfor
 .endfor
 
+
+# The error case of an unfinished ':from=to' modifier after the '=' requires
+# an expression that is missing the closing '}'.
+# expect+1: Malformed conditional (${error:L:from=$(}))
+.if ${error:L:from=$(})
+.endif
+
+
 all:

Index: src/usr.bin/make/unit-tests/varmod-to-separator.exp
diff -u src/usr.bin/make/unit-tests/varmod-to-separator.exp:1.12 src/usr.bin/make/unit-tests/varmod-to-separator.exp:1.13
--- src/usr.bin/make/unit-tests/varmod-to-separator.exp:1.12	Sat Apr 20 10:18:55 2024
+++ src/usr.bin/make/unit-tests/varmod-to-separator.exp	Sat Jun  1 18:44:05 2024
@@ -2,24 +2,28 @@ make: "varmod-to-separator.mk" line 155:
 make: "varmod-to-separator.mk" line 155: Malformed conditional (${WORDS:[1..3]:ts\400:tu})
 make: "varmod-to-separator.mk" line 171: while evaluating variable "WORDS": Invalid character number at "100:tu}"
 make: "varmod-to-separator.mk" line 171: Malformed conditional (${WORDS:[1..3]:ts\x100:tu})
+make: "varmod-to-separator.mk" line 180: while evaluating variable "word": Invalid character number at ",}"
+make: "varmod-to-separator.mk" line 180: Malformed conditional (${word:L:ts\x,})
+make: "varmod-to-separator.mk" line 187: while evaluating variable "word": Invalid character number at "112233445566778899}"
+make: "varmod-to-separator.mk" line 187: Malformed conditional (${word:L:ts\x112233445566778899})
 make: Bad modifier ":ts\-300" for variable "WORDS"
-make: "varmod-to-separator.mk" line 179: Malformed conditional (${WORDS:[1..3]:ts\-300:tu})
+make: "varmod-to-separator.mk" line 192: Malformed conditional (${WORDS:[1..3]:ts\-300:tu})
 make: Bad modifier ":ts\8" for variable "1 2 3"
-make: "varmod-to-separator.mk" line 188: Malformed conditional (${1 2 3:L:ts\8:tu})
+make: "varmod-to-separator.mk" line 201: Malformed conditional (${1 2 3:L:ts\8:tu})
 make: Bad modifier ":ts\100L" for variable "1 2 3"
-make: "varmod-to-separator.mk" line 196: Malformed conditional (${1 2 3:L:ts\100L})
+make: "varmod-to-separator.mk" line 209: Malformed conditional (${1 2 3:L:ts\100L})
 make: Bad modifier ":ts\x40g" for variable "1 2 3"
-make: "varmod-to-separator.mk" line 204: Malformed conditional (${1 2 3:L:ts\x40g})
+make: "varmod-to-separator.mk" line 217: Malformed conditional (${1 2 3:L:ts\x40g})
 make: Bad modifier ":tx" for variable "WORDS"
-make: "varmod-to-separator.mk" line 214: Malformed conditional (${WORDS:tx})
+make: "varmod-to-separator.mk" line 227: Malformed conditional (${WORDS:tx})
 make: Bad modifier ":ts\X" for variable "WORDS"
-make: "varmod-to-separator.mk" line 223: Malformed conditional (${WORDS:ts\X})
+make: "varmod-to-separator.mk" line 236: Malformed conditional (${WORDS:ts\X})
 make: Bad modifier ":t\X" for variable "WORDS"
-make: "varmod-to-separator.mk" line 232: Malformed conditional (${WORDS:t\X} != "anything")
+make: "varmod-to-separator.mk" line 245: Malformed conditional (${WORDS:t\X} != "anything")
 make: Bad modifier ":ts\69" for variable ""
-make: "varmod-to-separator.mk" line 249: Malformed conditional (${:Ua b:ts\69})
-make: "varmod-to-separator.mk" line 258: while evaluating "${:Ua b:ts\x1F60E}": Invalid character number at "1F60E}"
-make: "varmod-to-separator.mk" line 258: Malformed conditional (${:Ua b:ts\x1F60E})
+make: "varmod-to-separator.mk" line 262: Malformed conditional (${:Ua b:ts\69})
+make: "varmod-to-separator.mk" line 271: while evaluating "${:Ua b:ts\x1F60E}": Invalid character number at "1F60E}"
+make: "varmod-to-separator.mk" line 271: Malformed conditional (${:Ua b:ts\x1F60E})
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1

Index: src/usr.bin/make/unit-tests/varmod-to-separator.mk
diff -u src/usr.bin/make/unit-tests/varmod-to-separator.mk:1.14 src/usr.bin/make/unit-tests/varmod-to-separator.mk:1.15
--- src/usr.bin/make/unit-tests/varmod-to-separator.mk:1.14	Sat Apr 20 10:18:55 2024
+++ src/usr.bin/make/unit-tests/varmod-to-separator.mk	Sat Jun  1 18:44:05 2024
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-to-separator.mk,v 1.14 2024/04/20 10:18:55 rillig Exp $
+# $NetBSD: varmod-to-separator.mk,v 1.15 2024/06/01 18:44:05 rillig Exp $
 #
 # Tests for the :ts variable modifier, which joins the words of the variable
 # using an arbitrary character as word separator.
@@ -174,6 +174,19 @@ WORDS=	one two three four five six
 .  warning The separator \x100 is accepted even though it is out of bounds.
 .endif
 
+# The number after ':ts\x' must be hexadecimal.
+# expect+2: while evaluating variable "word": Invalid character number at ",}"
+# expect+1: Malformed conditional (${word:L:ts\x,})
+.if ${word:L:ts\x,}
+.endif
+
+# The hexadecimal number must be in the range of 'unsigned long' on all
+# supported platforms.
+# expect+2: while evaluating variable "word": Invalid character number at "112233445566778899}"
+# expect+1: Malformed conditional (${word:L:ts\x112233445566778899})
+.if ${word:L:ts\x112233445566778899}
+.endif
+
 # Negative numbers are not allowed for the separator character.
 # expect+1: Malformed conditional (${WORDS:[1..3]:ts\-300:tu})
 .if ${WORDS:[1..3]:ts\-300:tu}

Index: src/usr.bin/make/unit-tests/varmod.exp
diff -u src/usr.bin/make/unit-tests/varmod.exp:1.9 src/usr.bin/make/unit-tests/varmod.exp:1.10
--- src/usr.bin/make/unit-tests/varmod.exp:1.9	Sat Apr 20 10:18:56 2024
+++ src/usr.bin/make/unit-tests/varmod.exp	Sat Jun  1 18:44:05 2024
@@ -3,6 +3,12 @@ make: "varmod.mk" line 101: Invalid vari
 make: "varmod.mk" line 107: while evaluating "${:Uword:@word@${word}$@} != "word"": Dollar followed by nothing
 make: "varmod.mk" line 117: while evaluating variable "VAR": Missing delimiter ':' after modifier "P"
 make: "varmod.mk" line 119: Missing argument for ".error"
+make: Bad modifier ":[99333000222000111000]" for variable "word"
+make: "varmod.mk" line 125: Malformed conditional (${word:L:[99333000222000111000]})
+make: Bad modifier ":[2147483648]" for variable "word"
+make: "varmod.mk" line 128: Malformed conditional (${word:L:[2147483648]})
+make: "varmod.mk" line 135: while evaluating variable "word": Invalid number "99333000222000111000}" for ':range' modifier
+make: "varmod.mk" line 135: Malformed conditional (${word:L:range=99333000222000111000})
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1

Index: src/usr.bin/make/unit-tests/varmod.mk
diff -u src/usr.bin/make/unit-tests/varmod.mk:1.11 src/usr.bin/make/unit-tests/varmod.mk:1.12
--- src/usr.bin/make/unit-tests/varmod.mk:1.11	Sat Apr 20 10:18:56 2024
+++ src/usr.bin/make/unit-tests/varmod.mk	Sat Jun  1 18:44:05 2024
@@ -1,4 +1,4 @@
-# $NetBSD: varmod.mk,v 1.11 2024/04/20 10:18:56 rillig Exp $
+# $NetBSD: varmod.mk,v 1.12 2024/06/01 18:44:05 rillig Exp $
 #
 # Tests for variable modifiers, such as :Q, :S,from,to or :Ufallback.
 #
@@ -119,4 +119,18 @@ VAR=	STOP
 .  error
 .endif
 
-all: # nothing
+# Test the word selection modifier ':[n]' with a very large number that is
+# larger than ULONG_MAX for any supported platform.
+# expect+1: Malformed conditional (${word:L:[99333000222000111000]})
+.if ${word:L:[99333000222000111000]}
+.endif
+# expect+1: Malformed conditional (${word:L:[2147483648]})
+.if ${word:L:[2147483648]}
+.endif
+
+# Test the range generation modifier ':range=n' with a very large number that
+# is larger than SIZE_MAX for any supported platform.
+# expect+2: Malformed conditional (${word:L:range=99333000222000111000})
+# expect+1: while evaluating variable "word": Invalid number "99333000222000111000}" for ':range' modifier
+.if ${word:L:range=99333000222000111000}
+.endif

Index: src/usr.bin/make/unit-tests/varname-dot-make-level.exp
diff -u src/usr.bin/make/unit-tests/varname-dot-make-level.exp:1.1 src/usr.bin/make/unit-tests/varname-dot-make-level.exp:1.2
--- src/usr.bin/make/unit-tests/varname-dot-make-level.exp:1.1	Sun Aug 16 12:07:52 2020
+++ src/usr.bin/make/unit-tests/varname-dot-make-level.exp	Sat Jun  1 18:44:05 2024
@@ -1 +1,4 @@
+level 1: variable 0, env 1
+level 2: variable 1, env 2
+level 3: variable 2, env 3
 exit status 0

Index: src/usr.bin/make/unit-tests/varname-dot-make-level.mk
diff -u src/usr.bin/make/unit-tests/varname-dot-make-level.mk:1.2 src/usr.bin/make/unit-tests/varname-dot-make-level.mk:1.3
--- src/usr.bin/make/unit-tests/varname-dot-make-level.mk:1.2	Sun Aug 16 14:25:16 2020
+++ src/usr.bin/make/unit-tests/varname-dot-make-level.mk	Sat Jun  1 18:44:05 2024
@@ -1,8 +1,22 @@
-# $NetBSD: varname-dot-make-level.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: varname-dot-make-level.mk,v 1.3 2024/06/01 18:44:05 rillig Exp $
 #
-# Tests for the special .MAKE.LEVEL variable.
+# Tests for the special .MAKE.LEVEL variable, which informs about the
+# recursion level.  It is related to the environment variable MAKELEVEL,
+# even though they don't have the same value.
 
-# TODO: Implementation
+level_1: .PHONY
+	@printf 'level 1: variable %s, env %s\n' ${.MAKE.LEVEL} "$$${.MAKE.LEVEL.ENV}"
+	@${MAKE} -f ${MAKEFILE} level_2
 
-all:
-	@:;
+level_2: .PHONY
+	@printf 'level 2: variable %s, env %s\n' ${.MAKE.LEVEL} "$$${.MAKE.LEVEL.ENV}"
+	@${MAKE} -f ${MAKEFILE} level_3
+
+level_3: .PHONY
+	@printf 'level 3: variable %s, env %s\n' ${.MAKE.LEVEL} "$$${.MAKE.LEVEL.ENV}"
+
+# The .unexport-env directive clears the environment, except for the
+# MAKE_LEVEL variable.
+.if make(level_2)
+.unexport-env
+.endif

Reply via email to