Home | History | Annotate | Line # | Download | only in unit-tests
directive-export.mk revision 1.7
      1 # $NetBSD: directive-export.mk,v 1.7 2021/02/16 18:12:46 rillig Exp $
      2 #
      3 # Tests for the .export directive.
      4 #
      5 # See also:
      6 #	directive-misspellings.mk
      7 
      8 # TODO: Implementation
      9 
     10 INDIRECT=	indirect
     11 VAR=		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 all:
     38 	@:;
     39