1# $NetBSD: directive-export.mk,v 1.8 2021/02/16 19:01:18 rillig Exp $
2#
3# Tests for the .export directive.
4#
5# See also:
6#	directive-misspellings.mk
7
8# TODO: Implementation
9
10INDIRECT=	indirect
11VAR=		value $$ ${INDIRECT}
12
13# Before 2020-12-13, this unusual expression invoked undefined behavior since
14# it accessed out-of-bounds memory via Var_Export -> ExportVar -> MayExport.
15.export ${:U }
16
17# A variable is exported using the .export directive.
18# During that, its value is expanded, just like almost everywhere else.
19.export VAR
20.if ${:!env | grep '^VAR'!} != "VAR=value \$ indirect"
21.  error
22.endif
23
24# Undefining a variable that has been exported implicitly removes it from
25# the environment of all child processes.
26.undef VAR
27.if ${:!env | grep '^VAR' || true!} != ""
28.  error
29.endif
30
31# No syntactical argument means to export all variables.
32.export
33
34# An empty argument means no additional variables to export.
35.export ${:U}
36
37
38# Trigger the "This isn't going to end well" in ExportVarEnv.
39EMPTY_SHELL=	${:sh}
40.export EMPTY_SHELL	# only marked for export at this point
41_!=		:;:	# Force the variable to be actually exported.
42
43
44all:
45