Home | History | Annotate | Line # | Download | only in unit-tests
directive-undef.mk revision 1.10
      1  1.10  rillig # $NetBSD: directive-undef.mk,v 1.10 2021/02/16 18:02:19 rillig Exp $
      2   1.1  rillig #
      3   1.2  rillig # Tests for the .undef directive.
      4   1.6  rillig #
      5   1.6  rillig # See also:
      6   1.6  rillig #	directive-misspellings.mk
      7   1.1  rillig 
      8   1.9  rillig # Before var.c 1.737 from 2020-12-19, .undef only undefined the first
      9   1.9  rillig # variable, silently skipping all further variable names.
     10   1.9  rillig #
     11   1.9  rillig # Before var.c 1.761 from 2020-12-22, .undef complained about too many
     12   1.9  rillig # arguments.
     13   1.9  rillig #
     14   1.9  rillig # Since var.c 1.761 from 2020-12-22, .undef handles multiple variable names
     15   1.9  rillig # just like the .export directive.
     16   1.3  rillig 1=		1
     17   1.3  rillig 2=		2
     18   1.3  rillig 3=		3
     19   1.3  rillig .undef 1 2 3
     20   1.9  rillig .if ${1:U_}${2:U_}${3:U_} != ___
     21   1.4  rillig .  warning $1$2$3
     22   1.3  rillig .endif
     23   1.1  rillig 
     24   1.8  rillig 
     25   1.8  rillig # Without any arguments, until var.c 1.736 from 2020-12-19, .undef tried
     26   1.8  rillig # to delete the variable with the empty name, which never exists; see
     27   1.8  rillig # varname-empty.mk.  Since var.c 1.737 from 2020-12-19, .undef complains
     28   1.8  rillig # about a missing argument.
     29   1.8  rillig .undef
     30   1.8  rillig 
     31   1.8  rillig 
     32   1.8  rillig # Trying to delete the variable with the empty name is ok, it just won't
     33   1.8  rillig # ever do anything since that variable is never defined.
     34   1.8  rillig .undef ${:U}
     35   1.8  rillig 
     36   1.8  rillig 
     37   1.9  rillig # The argument of .undef is first expanded exactly once and then split into
     38   1.9  rillig # words, just like everywhere else.  This prevents variables whose names
     39   1.9  rillig # contain spaces or unbalanced 'single' or "double" quotes from being
     40   1.9  rillig # undefined, but these characters do not appear in variables names anyway.
     41   1.8  rillig 1=		1
     42   1.8  rillig 2=		2
     43   1.8  rillig 3=		3
     44   1.8  rillig ${:U1 2 3}=	one two three
     45   1.8  rillig VARNAMES=	1 2 3
     46   1.8  rillig .undef ${VARNAMES}		# undefines the variable "1 2 3"
     47   1.9  rillig .if !defined(${:U1 2 3})
     48   1.8  rillig .  error
     49   1.8  rillig .endif
     50   1.9  rillig .if ${1:U_}${2:U_}${3:U_} != "___"	# these are still defined
     51   1.8  rillig .  error
     52   1.8  rillig .endif
     53   1.5  rillig 
     54   1.7  rillig 
     55   1.9  rillig # A variable named " " cannot be undefined.  There's no practical use case
     56   1.9  rillig # for such variables anyway.
     57   1.7  rillig SPACE=		${:U }
     58   1.7  rillig ${SPACE}=	space
     59   1.7  rillig .if !defined(${SPACE})
     60   1.7  rillig .  error
     61   1.7  rillig .endif
     62   1.7  rillig .undef ${SPACE}
     63   1.9  rillig .if !defined(${SPACE})
     64   1.7  rillig .  error
     65   1.7  rillig .endif
     66   1.7  rillig 
     67   1.7  rillig 
     68   1.9  rillig # A variable named "$" can be undefined since the argument to .undef is
     69   1.9  rillig # expanded exactly once, before being split into words.
     70   1.7  rillig DOLLAR=		$$
     71   1.7  rillig ${DOLLAR}=	dollar
     72   1.7  rillig .if !defined(${DOLLAR})
     73   1.7  rillig .  error
     74   1.7  rillig .endif
     75   1.7  rillig .undef ${DOLLAR}
     76   1.7  rillig .if defined(${DOLLAR})
     77   1.7  rillig .  error
     78   1.7  rillig .endif
     79   1.7  rillig 
     80   1.7  rillig 
     81   1.9  rillig # Since var.c 1.762 from 2020-12-22, parse errors in the argument should be
     82   1.9  rillig # properly detected and should stop the .undef directive from doing any work.
     83   1.9  rillig #
     84   1.9  rillig # As of var.c 1.762, this doesn't happen though because the error handling
     85   1.9  rillig # in Var_Parse and Var_Subst is not done properly.
     86   1.9  rillig .undef ${VARNAMES:L:Z}
     87   1.9  rillig 
     88   1.9  rillig 
     89  1.10  rillig UT_EXPORTED=	exported-value
     90  1.10  rillig .export UT_EXPORTED
     91  1.10  rillig .if ${:!echo "\${UT_EXPORTED:-not-exported}"!} != "exported-value"
     92  1.10  rillig .  error
     93  1.10  rillig .endif
     94  1.10  rillig .if !${.MAKE.EXPORTED:MUT_EXPORTED}
     95  1.10  rillig .  error
     96  1.10  rillig .endif
     97  1.10  rillig .undef UT_EXPORTED		# XXX: does not update .MAKE.EXPORTED
     98  1.10  rillig .if ${:!echo "\${UT_EXPORTED:-not-exported}"!} != "not-exported"
     99  1.10  rillig .  error
    100  1.10  rillig .endif
    101  1.10  rillig .if ${.MAKE.EXPORTED:MUT_EXPORTED}
    102  1.10  rillig .  warning UT_EXPORTED is still listed in .MAKE.EXPORTED even though $\
    103  1.10  rillig 	   it is not exported anymore.
    104  1.10  rillig .endif
    105  1.10  rillig 
    106  1.10  rillig 
    107   1.1  rillig all:
    108