Home | History | Annotate | Line # | Download | only in unit-tests
dollar.mk revision 1.1
      1 # $NetBSD: dollar.mk,v 1.1 2020/05/10 12:34:01 rillig Exp $
      2 #
      3 # Test the various places where a dollar character can appear and
      4 # see what happens.  There are lots of surprises here.
      5 #
      6 
      7 LIST=		plain 'single' "double" 'mix'"ed" back\ slashed
      8 WORD=		word
      9 
     10 DOLLAR1=	$
     11 DOLLAR2=	$$
     12 DOLLAR4=	$$$$
     13 
     14 X=		VAR_X
     15 DOLLAR_XY=	$$XY
     16 DOLLAR_AXY=	$$AXY
     17 
     18 H=	@header()	{ printf '\n%s\n\n' "$$*"; }; header
     19 T=	@testcase()	{ printf '%23s => <%s>\n' "$$@"; }; testcase
     20 C=	@comment()	{ printf '%s\n' "$$*"; }; comment
     21 
     22 all:
     23 	$H 'Printing dollar from literals and variables'
     24 
     25 	$C 'To survive the parser, a dollar character must be doubled.'
     26 	$T	'1 dollar literal'	''\$
     27 	$T	'2 dollar literal'	''\$$
     28 	$T	'4 dollar literal'	''\$$\$$
     29 
     30 	$C 'Some hungry part of make eats all the dollars after a :U modifier.'
     31 	$T	'1 dollar default'	''${:U$:Q}
     32 	$T	'2 dollar default'	''${:U$$:Q}
     33 	$T	'4 dollar default'	''${:U$$$$:Q}
     34 
     35 	$C 'This works as expected.'
     36 	$T	'1 dollar variable'	''${DOLLAR1:Q}
     37 	$T	'2 dollar variable'	''${DOLLAR2:Q}
     38 	$T	'4 dollar variable'	''${DOLLAR4:Q}
     39 
     40 	$C 'Some hungry part of make eats all the dollars after a :U modifier.'
     41 	$T	'1 dollar var-default'	''${U:${DOLLAR1}:Q}
     42 	$T	'2 dollar var-default'	''${U:${DOLLAR2}:Q}
     43 	$T	'4 dollar var-default'	''${U:${DOLLAR4}:Q}
     44 
     45 	$H 'Dollar in :S pattern'
     46 
     47 	$T	'S,$$,word,'		''${DOLLAR_XY:S,$,word,:Q}
     48 	$T	'S,$$X,word,'		''${DOLLAR_XY:S,$X,word,:Q}
     49 	$T	'S,$$$$X,word,'		''${DOLLAR_XY:S,$$X,word,:Q}
     50 	$T	'S,$$$$$$X,word,'	''${DOLLAR_XY:S,$$$X,word,:Q}
     51 
     52 	$T	'S,$$X,replaced,'	''${X:S,$X,replaced,:Q}
     53 	$T	'S,$$$$X,replaced,'	''${X:S,$$X,replaced,:Q}
     54 	$T	'S,$$$$$$X,replaced,'	''${X:S,$$$X,replaced,:Q}
     55 
     56 	$H 'Dollar in :C character class'
     57 
     58 	$C 'The A is replaced because the $$$$ is reduced to a single $$,'
     59 	$C 'which is then resolved to the variable X with the value VAR_X.'
     60 	$C 'The effective character class becomes [VAR_XY].'
     61 	$T	'C,[$$XY],<&>,g'	''${DOLLAR_AXY:C,[$$XY],<&>,g:Q}
     62 
     63 	$H 'Dollar in :C pattern'
     64 	$C 'For some reason, multiple dollars are folded into one.'
     65 	$T	'C,$$,word,'		''${DOLLAR:C,$,dollar,g:Q}
     66 	$T	'C,$$$$,word,'		''${DOLLAR:C,$$,dollar,g:Q}
     67 
     68 	$H 'Dollar in :S replacement'
     69 	$C 'For some reason, multiple dollars are folded into one.'
     70 	$T	'S,word,a$$Xo,'		''${WORD:S,word,a$Xo,:Q}
     71 	$T	'S,word,a$$$$Xo,'	''${WORD:S,word,a$$Xo,:Q}
     72 	$T	'S,word,a$$$$$$Xo,'	''${WORD:S,word,a$$$Xo,:Q}
     73