summaryrefslogtreecommitdiff
path: root/unit-tests/directive-export.mk
blob: d46b1dc01f271533a34af6694432bcf3bb20feef (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# $NetBSD: directive-export.mk,v 1.9 2023/08/20 20:48:32 rillig Exp $
#
# Tests for the .export directive.
#
# See also:
#	directive-misspellings.mk

# TODO: Implementation

INDIRECT=	indirect
VAR=		value $$ ${INDIRECT}

# Before 2020-12-13, this unusual expression invoked undefined behavior since
# it accessed out-of-bounds memory via Var_Export -> ExportVar -> MayExport.
.export ${:U }

# A variable is exported using the .export directive.
# During that, its value is expanded, just like almost everywhere else.
.export VAR
.if ${:!env | grep '^VAR'!} != "VAR=value \$ indirect"
.  error
.endif

# Undefining a variable that has been exported implicitly removes it from
# the environment of all child processes.
.undef VAR
.if ${:!env | grep '^VAR' || true!} != ""
.  error
.endif

# No syntactical argument means to export all variables.
.export

# An empty argument means no additional variables to export.
.export ${:U}


# Trigger the "This isn't going to end well" in ExportVarEnv.
EMPTY_SHELL=	${:sh}
.export EMPTY_SHELL	# only marked for export at this point
_!=		:;:	# Force the variable to be actually exported.


# If the '.export' directive exports a variable whose value contains a '$',
# the actual export action is deferred until a subprocess is started, assuming
# that only subprocesses access the environment variables.  The ':localtime'
# modifier depends on the 'TZ' environment variable, without any subprocess.
export TZ=${UTC}
# expect+1: 00:00:00
.info ${%T:L:localtime=86400}
INDIRECT_TZ=	${:UAmerica/Los_Angeles}
TZ=		${INDIRECT_TZ}
.export TZ
# expect+1: 00:00:00
.info ${%T:L:localtime=86400}
_!=	echo 'force exporting the environment variables'
# expect+1: 16:00:00
.info ${%T:L:localtime=86400}


all: