Home | History | Annotate | Line # | Download | only in unit-tests
var-op-sunsh.mk revision 1.1
      1 # $NetBSD: var-op-sunsh.mk,v 1.1 2020/10/04 06:53:15 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.
      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 # XXX: As of 2020-10-04, the ':sh' can even be followed by other characters.
     17 # This is neither documented by NetBSD make nor by Solaris make.
     18 VAR:shell=	echo colon-shell
     19 .if ${VAR} != "colon-shell"
     20 .  error
     21 .endif
     22 
     23 # XXX: Several colons can syntactically appear in a variable name.
     24 # Neither of these should be interpreted as the ':sh' assignment operator
     25 # modifier.
     26 VAR:shoe:shore=	echo two-colons
     27 .if ${VAR${:U\:}shoe} != "two-colons"
     28 .  error
     29 .endif
     30 
     31 #.MAKEFLAGS: -dcpv
     32 
     33 # XXX: As of 2020-10-04, the following expression is wrongly marked as
     34 # a parse error.  This is caused by the ':sh' modifier.
     35 #
     36 # There are two different syntactical elements that look exactly the same:
     37 # The variable modifier ':sh' and the assignment operator modifier ':sh'.
     38 # Intuitively this variable name contains the variable modifier, but the
     39 # parser sees it as operator modifier, in Parse_DoVar.
     40 #
     41 VAR.${:Uecho 123:sh}=	echo oops
     42 .if ${VAR.echo 123} != "oops"
     43 .  error
     44 .endif
     45 
     46 # XXX: Same pattern here. The ':sh' inside the nested expression is taken
     47 # for the assignment operator, even though it is escaped by a backslash.
     48 #
     49 VAR.${:U echo\:shell}=	echo oops
     50 .if ${VAR.${:U echo\\}} != "oops"
     51 .  error
     52 .endif
     53 
     54 # XXX: The word 'shift' is also affected since it starts with ':sh'.
     55 #
     56 VAR.key:shift=		echo Shift
     57 .if ${VAR.key} != "Shift"
     58 .  error
     59 .endif
     60 
     61 .MAKEFLAGS: -d0
     62 
     63 # XXX: Despite the error messages the exit status is still 0.
     64 
     65 all:
     66 	@:;
     67