1
# $NetBSD: dollar.mk,v 1.2 2020/05/10 13:03:40 rillig Exp $
1
# $NetBSD: dollar.mk,v 1.3 2020/05/17 09:37:48 rillig Exp $
3
3
# Test the various places where a dollar character can appear and
4
4
# see what happens. There are lots of surprises here.
19
19
T= @testcase() { printf '%23s => <%s>\n' "$$@"; }; testcase
20
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'
23
31
$H 'Printing dollar from literals and variables'
25
33
$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' ''\$$\$$
34
$T '1 dollar literal' '$'
35
$T '1 dollar literal eol' ''$
36
$T '2 dollar literal' '$$'
37
$T '4 dollar literal' '$$$$'
30
39
$C 'Some hungry part of make eats all the dollars after a :U modifier.'
31
40
$T '1 dollar default' ''${:U$:Q}
58
67
$C 'The A is replaced because the $$$$ is reduced to a single $$,'
59
68
$C 'which is then resolved to the variable X with the value VAR_X.'
60
69
$C 'The effective character class becomes [VAR_XY].'
61
$T 'C,[$$XY],<&>,g' ''${DOLLAR_AXY:C,[$$XY],<&>,g:Q}
70
$T 'C,[$$$$XY],<&>,g' ''${DOLLAR_AXY:C,[$$XY],<&>,g:Q}
63
72
$H 'Dollar in :C pattern'
64
73
$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}
74
$T 'C,$$,dollar,g' ''${DOLLAR:C,$,dollar,g:Q}
75
$T 'C,$$$$,dollar,g' ''${DOLLAR:C,$$,dollar,g:Q}
68
77
$H 'Dollar in :S replacement'
69
78
$C 'For some reason, multiple dollars are folded into one.'