xref: /freebsd/contrib/bmake/unit-tests/directive-export.mk (revision 5e3934b15a2741b2de6b217e77dc9d798d740804)
1# $NetBSD: directive-export.mk,v 1.9 2023/08/20 20:48:32 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
44# If the '.export' directive exports a variable whose value contains a '$',
45# the actual export action is deferred until a subprocess is started, assuming
46# that only subprocesses access the environment variables.  The ':localtime'
47# modifier depends on the 'TZ' environment variable, without any subprocess.
48export TZ=${UTC}
49# expect+1: 00:00:00
50.info ${%T:L:localtime=86400}
51INDIRECT_TZ=	${:UAmerica/Los_Angeles}
52TZ=		${INDIRECT_TZ}
53.export TZ
54# expect+1: 00:00:00
55.info ${%T:L:localtime=86400}
56_!=	echo 'force exporting the environment variables'
57# expect+1: 16:00:00
58.info ${%T:L:localtime=86400}
59
60
61all:
62