Home | History | Annotate | Line # | Download | only in unit-tests
var-op-sunsh.mk revision 1.2
      1 # $NetBSD: var-op-sunsh.mk,v 1.2 2020/10/04 07:49:45 rillig Exp $
      2 #
      3 # Tests for the :sh= variable assignment operator, which runs its right-hand
      4 # side through the shell.  It is a seldom-used alternative to the !=
      5 # assignment operator, adopted from Sun make.
      6 
      7 .MAKEFLAGS: -dL			# Enable sane error messages
      8 
      9 # This is the idiomatic form of the Sun shell assignment operator.
     10 # The assignment operator is directly preceded by the ':sh'.
     11 VAR:sh=		echo colon-sh
     12 .if ${VAR} != "colon-sh"
     13 .  error
     14 .endif
     15 
     16 # It is also possible to have whitespace around the :sh assignment
     17 # operator modifier.
     18 VAR :sh =	echo colon-sh-spaced
     19 .if ${VAR} != "colon-sh-spaced"
     20 .  error
     21 .endif
     22 
     23 # Until 2020-10-04, the ':sh' could even be followed by other characters.
     24 # This was neither documented by NetBSD make nor by Solaris make and was
     25 # an implementation error.
     26 #
     27 # Since 2020-10-04, this is a normal variable assignment using the '='
     28 # assignment operator.
     29 VAR:shell=	echo colon-shell
     30 .if ${${:UVAR\:shell}} != "echo colon-shell"
     31 .  error
     32 .endif
     33 
     34 # Several colons can syntactically appear in a variable name.
     35 # Until 2020-10-04, the last of them was interpreted as the ':sh'
     36 # assignment operator.
     37 #
     38 # Since 2020-10-04, the colons are part of the variable name.
     39 VAR:shoe:shore=	echo two-colons
     40 .if ${${:UVAR\:shoe\:shore}} != "echo two-colons"
     41 .  error
     42 .endif
     43 
     44 # Until 2020-10-04, the following expression was wrongly marked as
     45 # a parse error.  This was because the parser for variable assignments
     46 # just looked for the previous ":sh", without taking any contextual
     47 # information into account.
     48 #
     49 # There are two different syntactical elements that look exactly the same:
     50 # The variable modifier ':sh' and the assignment operator modifier ':sh'.
     51 # Intuitively this variable name contains the variable modifier, but until
     52 # 2020-10-04, the parser regarded it as an assignment operator modifier, in
     53 # Parse_DoVar.
     54 VAR.${:Uecho 123:sh}=	ok-123
     55 .if ${VAR.123} != "ok-123"
     56 .  error
     57 .endif
     58 
     59 # Same pattern here. Until 2020-10-04, the ':sh' inside the nested expression
     60 # was taken for the :sh assignment operator modifier, even though it was
     61 # escaped by a backslash.
     62 VAR.${:U echo\:shell}=	ok-shell
     63 .if ${VAR.${:U echo\:shell}} != "ok-shell"
     64 .  error
     65 .endif
     66 
     67 # Until 2020-10-04, the word 'shift' was also affected since it starts with
     68 # ':sh'.
     69 VAR.key:shift=		Shift
     70 .if ${${:UVAR.key\:shift}} != "Shift"
     71 .  error
     72 .endif
     73 
     74 all:
     75 	@:;
     76