tests/make: test more modifiers and special variables

This commit is contained in:
rillig 2024-06-01 18:44:05 +00:00
parent aee3d42c8f
commit 518dc17b32
12 changed files with 126 additions and 22 deletions

View File

@ -1,2 +1,5 @@
value with ${UNEXPANDED} expression
value literal
value indirect
value ${indirect:L}
exit status 0

View File

@ -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} expression
.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"

View File

@ -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 empty word." 1>&2; echo
. 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

View File

@ -145,6 +145,8 @@ pre-middle-suffix pre%ffix=NPre% "NPre-middle-su"
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

View File

@ -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:$$$${VALUE}
. 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:

View File

@ -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}"'"

View File

@ -2,24 +2,28 @@ make: "varmod-to-separator.mk" line 155: while evaluating variable "WORDS": Inva
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

View File

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

View File

@ -3,6 +3,12 @@ make: "varmod.mk" line 101: Invalid variable name ':', at "$:L} != """
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

View File

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

View File

@ -1 +1,4 @@
level 1: variable 0, env 1
level 2: variable 1, env 2
level 3: variable 2, env 3
exit status 0

View File

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