1 # $NetBSD: dollar.mk,v 1.4 2020/11/03 18:21:36 rillig Exp $
3 # Test the various places where a dollar sign can appear and
4 # see what happens. There are lots of surprises here.
7 LIST= plain 'single' "double" 'mix'"ed" back\ slashed
18 H= @header() { printf '\n%s\n\n' "$$*"; }; header
19 T= @testcase() { printf '%23s => <%s>\n' "$$@"; }; testcase
20 C= @comment() { printf '%s\n' "$$*"; }; comment
22 # These variable values are not accessed.
23 # The trailing dollar in the '1 dollar literal eol' test case accesses
24 # the empty variable instead, which is always guaranteed to be empty.
25 ${:U }= space-var-value
26 ${:U${.newline}}= newline-var-value
27 # But this one is accessed.
28 ${:U'}= single-quote-var-value'
31 $H 'Printing dollar from literals and variables'
33 $C 'To survive the parser, a dollar sign must be doubled.'
34 $T '1 dollar literal' '$'
35 $T '1 dollar literal eol' ''$
36 $T '2 dollar literal' '$$'
37 $T '4 dollar literal' '$$$$'
39 $C 'Some hungry part of make eats all the dollars after a :U modifier.'
40 $T '1 dollar default' ''${:U$:Q}
41 $T '2 dollar default' ''${:U$$:Q}
42 $T '4 dollar default' ''${:U$$$$:Q}
44 $C 'This works as expected.'
45 $T '1 dollar variable' ''${DOLLAR1:Q}
46 $T '2 dollar variable' ''${DOLLAR2:Q}
47 $T '4 dollar variable' ''${DOLLAR4:Q}
49 $C 'Some hungry part of make eats all the dollars after a :U modifier.'
50 $T '1 dollar var-default' ''${:U${DOLLAR1}:Q}
51 $T '2 dollar var-default' ''${:U${DOLLAR2}:Q}
52 $T '4 dollar var-default' ''${:U${DOLLAR4}:Q}
54 $H 'Dollar in :S pattern'
56 $T 'S,$$,word,' ''${DOLLAR_XY:S,$,word,:Q}
57 $T 'S,$$X,word,' ''${DOLLAR_XY:S,$X,word,:Q}
58 $T 'S,$$$$X,word,' ''${DOLLAR_XY:S,$$X,word,:Q}
59 $T 'S,$$$$$$X,word,' ''${DOLLAR_XY:S,$$$X,word,:Q}
61 $T 'S,$$X,replaced,' ''${X:S,$X,replaced,:Q}
62 $T 'S,$$$$X,replaced,' ''${X:S,$$X,replaced,:Q}
63 $T 'S,$$$$$$X,replaced,' ''${X:S,$$$X,replaced,:Q}
65 $H 'Dollar in :C character class'
67 $C 'The A is replaced because the $$$$ is reduced to a single $$,'
68 $C 'which is then resolved to the variable X with the value VAR_X.'
69 $C 'The effective character class becomes [VAR_XY].'
70 $T 'C,[$$$$XY],<&>,g' ''${DOLLAR_AXY:C,[$$XY],<&>,g:Q}
72 $H 'Dollar in :C pattern'
73 $C 'For some reason, multiple dollars are folded into one.'
74 $T 'C,$$,dollar,g' ''${DOLLAR:C,$,dollar,g:Q}
75 $T 'C,$$$$,dollar,g' ''${DOLLAR:C,$$,dollar,g:Q}
77 $H 'Dollar in :S replacement'
78 $C 'For some reason, multiple dollars are folded into one.'
79 $T 'S,word,a$$Xo,' ''${WORD:S,word,a$Xo,:Q}
80 $T 'S,word,a$$$$Xo,' ''${WORD:S,word,a$$Xo,:Q}
81 $T 'S,word,a$$$$$$Xo,' ''${WORD:S,word,a$$$Xo,:Q}