xref: /freebsd/contrib/bmake/unit-tests/directive-export.mk (revision 06b9b3e0ad0dc3f0166b3e8f26ced68c271cf527)
1*06b9b3e0SSimon J. Gerraty# $NetBSD: directive-export.mk,v 1.6 2020/12/13 01:07:54 rillig Exp $
22c3632d1SSimon J. Gerraty#
32c3632d1SSimon J. Gerraty# Tests for the .export directive.
4*06b9b3e0SSimon J. Gerraty#
5*06b9b3e0SSimon J. Gerraty# See also:
6*06b9b3e0SSimon J. Gerraty#	directive-misspellings.mk
72c3632d1SSimon J. Gerraty
82c3632d1SSimon J. Gerraty# TODO: Implementation
92c3632d1SSimon J. Gerraty
10956e45f6SSimon J. GerratyINDIRECT=	indirect
11956e45f6SSimon J. GerratyVAR=		value $$ ${INDIRECT}
12956e45f6SSimon J. Gerraty
13*06b9b3e0SSimon J. Gerraty# Before 2020-12-13, this unusual expression invoked undefined behavior since
14*06b9b3e0SSimon J. Gerraty# it accessed out-of-bounds memory via Var_Export -> ExportVar -> MayExport.
15*06b9b3e0SSimon J. Gerraty.export ${:U }
16*06b9b3e0SSimon J. Gerraty
17956e45f6SSimon J. Gerraty# A variable is exported using the .export directive.
18956e45f6SSimon J. Gerraty# During that, its value is expanded, just like almost everywhere else.
19956e45f6SSimon J. Gerraty.export VAR
20956e45f6SSimon J. Gerraty.if ${:!env | grep '^VAR'!} != "VAR=value \$ indirect"
21956e45f6SSimon J. Gerraty.  error
22956e45f6SSimon J. Gerraty.endif
23956e45f6SSimon J. Gerraty
24956e45f6SSimon J. Gerraty# Undefining a variable that has been exported implicitly removes it from
25956e45f6SSimon J. Gerraty# the environment of all child processes.
26956e45f6SSimon J. Gerraty.undef VAR
27956e45f6SSimon J. Gerraty.if ${:!env | grep '^VAR' || true!} != ""
28956e45f6SSimon J. Gerraty.  error
29956e45f6SSimon J. Gerraty.endif
30956e45f6SSimon J. Gerraty
31*06b9b3e0SSimon J. Gerraty# No argument means to export all variables.
32*06b9b3e0SSimon J. Gerraty.export
33e2eeea75SSimon J. Gerraty
342c3632d1SSimon J. Gerratyall:
352c3632d1SSimon J. Gerraty	@:;
36