diff options
Diffstat (limited to 'unit-tests/directive-export-gmake.mk')
-rw-r--r-- | unit-tests/directive-export-gmake.mk | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/unit-tests/directive-export-gmake.mk b/unit-tests/directive-export-gmake.mk new file mode 100644 index 0000000000000..51de8fe55f64e --- /dev/null +++ b/unit-tests/directive-export-gmake.mk @@ -0,0 +1,64 @@ +# $NetBSD: directive-export-gmake.mk,v 1.2 2020/10/19 18:59:53 rillig Exp $ +# +# Tests for the export directive (without leading dot), as in GNU make. + +# The "export" directive only affects the environment of the make process +# and its child processes. It does not affect the global variables or any +# other variables. +VAR= before +export VAR=exported +.if ${VAR} != "before" +. error +.endif + +# Ensure that the name-value pair is actually exported. +.if ${:!echo "\$VAR"!} != "exported" +. error +.endif + +# This line looks like it would export 2 variables, but it doesn't. +# It only exports VAR and appends everything else as the variable value. +export VAR=exported VAR2=exported-as-well +.if ${:!echo "\$VAR"!} != "exported VAR2=exported-as-well" +. error ${:!echo "\$VAR"!} +.endif + +# Contrary to the usual variable assignments, spaces are significant +# after the '=' sign and are prepended to the value of the environment +# variable. +export VAR= leading spaces +.if ${:!echo "\$VAR"!} != " leading spaces" +. error +.endif + +# Contrary to the usual variable assignments, spaces are significant +# before the '=' sign and are appended to the name of the environment +# variable. +# +# Depending on the shell, environment variables with such exotic names +# may be silently discarded. One such shell is dash, which is the default +# shell on Ubuntu and Debian. +export VAR =trailing space in varname +.if ${:!env | grep trailing!} != "VAR =trailing space in varname" +. if ${:!env | grep trailing!} != "" # for dash +. error +. endif +.endif + +# The right-hand side of the exported variable is expanded exactly once. +TWICE= expanded twice +ONCE= expanded once, leaving $${TWICE} as-is +export VAR=${ONCE} +.if ${:!echo "\$VAR"!} != "expanded once, leaving \${TWICE} as-is" +. error +.endif + +# Undefined variables are allowed on the right-hand side, they expand +# to an empty string, as usual. +export VAR=an ${UNDEF} variable +.if ${:!echo "\$VAR"!} != "an variable" +. error +.endif + +all: + @:; |