Home | History | Annotate | Line # | Download | only in unit-tests
directive-export-gmake.mk revision 1.2
      1  1.2  rillig # $NetBSD: directive-export-gmake.mk,v 1.2 2020/10/19 18:59:53 rillig Exp $
      2  1.1  rillig #
      3  1.1  rillig # Tests for the export directive (without leading dot), as in GNU make.
      4  1.1  rillig 
      5  1.1  rillig # The "export" directive only affects the environment of the make process
      6  1.1  rillig # and its child processes.  It does not affect the global variables or any
      7  1.1  rillig # other variables.
      8  1.1  rillig VAR=	before
      9  1.1  rillig export VAR=exported
     10  1.1  rillig .if ${VAR} != "before"
     11  1.1  rillig .  error
     12  1.1  rillig .endif
     13  1.1  rillig 
     14  1.1  rillig # Ensure that the name-value pair is actually exported.
     15  1.1  rillig .if ${:!echo "\$VAR"!} != "exported"
     16  1.1  rillig .  error
     17  1.1  rillig .endif
     18  1.1  rillig 
     19  1.1  rillig # This line looks like it would export 2 variables, but it doesn't.
     20  1.1  rillig # It only exports VAR and appends everything else as the variable value.
     21  1.1  rillig export VAR=exported VAR2=exported-as-well
     22  1.1  rillig .if ${:!echo "\$VAR"!} != "exported VAR2=exported-as-well"
     23  1.1  rillig .  error ${:!echo "\$VAR"!}
     24  1.1  rillig .endif
     25  1.1  rillig 
     26  1.1  rillig # Contrary to the usual variable assignments, spaces are significant
     27  1.1  rillig # after the '=' sign and are prepended to the value of the environment
     28  1.1  rillig # variable.
     29  1.1  rillig export VAR=  leading spaces
     30  1.1  rillig .if ${:!echo "\$VAR"!} != "  leading spaces"
     31  1.1  rillig .  error
     32  1.1  rillig .endif
     33  1.1  rillig 
     34  1.1  rillig # Contrary to the usual variable assignments, spaces are significant
     35  1.1  rillig # before the '=' sign and are appended to the name of the environment
     36  1.1  rillig # variable.
     37  1.2  rillig #
     38  1.2  rillig # Depending on the shell, environment variables with such exotic names
     39  1.2  rillig # may be silently discarded.  One such shell is dash, which is the default
     40  1.2  rillig # shell on Ubuntu and Debian.
     41  1.1  rillig export VAR =trailing space in varname
     42  1.1  rillig .if ${:!env | grep trailing!} != "VAR =trailing space in varname"
     43  1.2  rillig .  if ${:!env | grep trailing!} != "" # for dash
     44  1.2  rillig .    error
     45  1.2  rillig .  endif
     46  1.1  rillig .endif
     47  1.1  rillig 
     48  1.1  rillig # The right-hand side of the exported variable is expanded exactly once.
     49  1.1  rillig TWICE=	expanded twice
     50  1.1  rillig ONCE=	expanded once, leaving $${TWICE} as-is
     51  1.1  rillig export VAR=${ONCE}
     52  1.1  rillig .if ${:!echo "\$VAR"!} != "expanded once, leaving \${TWICE} as-is"
     53  1.1  rillig .  error
     54  1.1  rillig .endif
     55  1.1  rillig 
     56  1.1  rillig # Undefined variables are allowed on the right-hand side, they expand
     57  1.1  rillig # to an empty string, as usual.
     58  1.1  rillig export VAR=an ${UNDEF} variable
     59  1.1  rillig .if ${:!echo "\$VAR"!} != "an  variable"
     60  1.1  rillig .  error
     61  1.1  rillig .endif
     62  1.1  rillig 
     63  1.1  rillig all:
     64  1.1  rillig 	@:;
     65