~vcs-imports/pmake/main

« back to all changes in this revision

Viewing changes to unit-tests/dollar.mk

  • Committer: rillig
  • Date: 2020-05-17 09:37:48 UTC
  • Revision ID: rillig-20200517093748-6spf1oi19kwibgng
usr.bin/make: fix test for dollar and backslash at eol

The previous version of this test relied on the way how the shell
interprets a lonely backslash at the end of the line.  The NetBSD and
FreeBSD shells print the backslash, while Bash doesn't.

While here, make the escaping a bit simpler and align the test
descriptions with the actual test data.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 $
2
2
#
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
21
21
 
 
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'
 
29
 
22
30
all:
23
31
        $H 'Printing dollar from literals and variables'
24
32
 
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'      '$$$$'
29
38
 
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}
62
71
 
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}
67
76
 
68
77
        $H 'Dollar in :S replacement'
69
78
        $C 'For some reason, multiple dollars are folded into one.'