xref: /freebsd/contrib/bmake/unit-tests/directive-export.mk (revision c66ec88fed842fbaad62c30d510644ceb7bd2d71)
1# $NetBSD: directive-export.mk,v 1.6 2020/12/13 01:07:54 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 argument means to export all variables.
32.export
33
34all:
35	@:;
36