diff options
Diffstat (limited to 'unit-tests/directive-undef.mk')
-rw-r--r-- | unit-tests/directive-undef.mk | 46 |
1 files changed, 42 insertions, 4 deletions
diff --git a/unit-tests/directive-undef.mk b/unit-tests/directive-undef.mk index 41ea6b5bf8fa..5ac7d939c71e 100644 --- a/unit-tests/directive-undef.mk +++ b/unit-tests/directive-undef.mk @@ -1,4 +1,4 @@ -# $NetBSD: directive-undef.mk,v 1.10 2021/02/16 18:02:19 rillig Exp $ +# $NetBSD: directive-undef.mk,v 1.12 2022/03/26 12:44:57 rillig Exp $ # # Tests for the .undef directive. # @@ -43,11 +43,11 @@ 3= 3 ${:U1 2 3}= one two three VARNAMES= 1 2 3 -.undef ${VARNAMES} # undefines the variable "1 2 3" -.if !defined(${:U1 2 3}) +.undef ${VARNAMES} # undefines the variables "1", "2" and "3" +.if ${${:U1 2 3}} != "one two three" # still there . error .endif -.if ${1:U_}${2:U_}${3:U_} != "___" # these are still defined +.if ${1:U_}${2:U_}${3:U_} != "___" # these have been undefined . error .endif @@ -104,4 +104,42 @@ UT_EXPORTED= exported-value .endif +# When an exported variable is undefined, the variable is removed both from +# the global scope as well as from the environment. +DIRECT= direct +INDIRECT= in-${DIRECT} +.export DIRECT INDIRECT +.if ${DIRECT} != "direct" +. error +.endif +.if ${INDIRECT} != "in-direct" +. error +.endif + +# Deletes the variables from the global scope and also from the environment. +# This applies to both variables, even though 'INDIRECT' is not actually +# exported yet since it refers to another variable. +.undef DIRECT # Separate '.undef' directives, +.undef INDIRECT # for backwards compatibility. + +.if ${DIRECT:Uundefined} != "undefined" +. error +.endif +.if ${INDIRECT:Uundefined} != "undefined" +. error +.endif + + +# Since var.c 1.570 from 2020-10-06 and before var.c 1.1014 from 2022-03-26, +# make ran into an assertion failure when trying to undefine a variable that +# was based on an environment variable. +.if ${ENV_VAR} != "env-value" # see ./Makefile, ENV.directive-undef +. error +.endif +ENV_VAR+= appended # moves the short-lived variable to the + # global scope +.undef ENV_VAR # removes the variable from both the global + # scope and from the environment + + all: |