summaryrefslogtreecommitdiffstats
path: root/src/kmk/tests/scripts/misc/bs-nl
blob: fc323ce91b7d0b4fce29aa5678efae0e07290196 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#                                                                    -*-perl-*-
$description = "Test backslash-newline handling.";

$details = "";

# TEST #1
# -------

# Backslash-newlines in recipes

# These are basic backslash-newlines with no tricks
run_make_test("fast:;\@echo fa\\\nst\n",
              '', 'fast');

run_make_test("slow:;\@: no-op; echo sl\\\now\n",
              '', 'slow');

run_make_test("dquote:;\@echo \"dqu\\\note\"\n",
              '', 'dquote');

run_make_test("squote:;\@echo 'squ\\\note'\n",
              '', "squ\\\note");

# Ensure that a leading prefix character is omitted
run_make_test("fast:;\@echo fa\\\n\tst\n",
              '', 'fast');

run_make_test("slow:;\@: no-op; echo sl\\\n\tow\n",
              '', 'slow');

run_make_test("dquote:;\@echo \"dqu\\\n\tote\"\n",
              '', 'dquote');

run_make_test("squote:;\@echo 'squ\\\n\tote'\n",
              '', "squ\\\note");

# Ensure that ONLY the leading prefix character is omitted
run_make_test("fast:;\@echo fa\\\n\t  st\n",
              '', 'fa st');

run_make_test("slow:;\@: no-op; echo sl\\\n\t\tow\n",
              '', "sl ow");

run_make_test("dquote:;\@echo \"dqu\\\n\t    ote\"\n",
              '', 'dqu    ote');

run_make_test("squote:;\@echo 'squ\\\n\t\t   ote'\n",
              '', "squ\\\n\t   ote");

# Backslash-newlines in variable values

# Simple
run_make_test(q!
var = he\
llo
var:;@echo '|$(var)|'!,
              '', "|he llo|");

# Condense trailing space
run_make_test(q!
var = he  \
llo
var:;@echo '|$(var)|'!,
              '', "|he llo|");

# Remove leading space
run_make_test(q!
var = he\
    llo
var:;@echo '|$(var)|'!,
              '', "|he llo|");

# Multiple bs/nl condensed
run_make_test(q!
var = he\
\
\
    llo
var:;@echo '|$(var)|'!,
              '', "|he llo|");

# POSIX: Preserve trailing space
run_make_test(q!
.POSIX:
x = y
var = he  \
llo
var:;@echo '|$(var)|'!,
              '', "|he   llo|");

# POSIX: One space per bs-nl
run_make_test(q!
.POSIX:
x = y
var = he\
\
\
    llo
var:;@echo '|$(var)|'!,
              '', "|he   llo|");

# Savannah #39035: handle whitespace in call
run_make_test(q!
f = echo $(1)
t:; @$(call f,"a \
            b"); \
        $(call f,"a \
            b")
!,
              '', "a b\na b\n");

# Savannah #38945: handle backslash CRLF
# We need our own makefile so we can set binmode
my $m1 = get_tmpfile();
open(MAKEFILE, "> $m1");
binmode(MAKEFILE);
print MAKEFILE "FOO = foo \\\r\n";
close(MAKEFILE);

my $m2 = get_tmpfile();
open(MAKEFILE, "> $m2");
print MAKEFILE "include $m1\ndefine BAR\nall: ; \@echo \$(FOO) bar\nendef\n\$(eval \$(BAR))\n";
close(MAKEFILE);

run_make_with_options($m2, '', get_logfile());
compare_output("foo bar\n", get_logfile(1));

# Test different types of whitespace, and bsnl inside functions

sub xlate
{
    $_ = $_[0];
    s/\\r/\r/g;
    s/\\t/\t/g;
    s/\\f/\f/g;
    s/\\v/\v/g;
    s/\\n/\n/g;
    return $_;
}

run_make_test(xlate(q!
$(foreach\r  a \t , b\t  c \r ,$(info    $a  \r  )      )
all:;@:
!),
              '', "b  \r  \nc  \r  \n");

run_make_test(xlate(q!
all:;@:$(foreach\r  a \t , b\t  c \r ,$(info    $a  \r  )      )
!),
              '', "b  \r  \nc  \r  \n");

run_make_test(xlate(q!
$(foreach \
\r  a \t\
 , b\t \
 c \r ,$(info  \
  $a  \r  )  \
    )
all:;@:
!),
              '', "b  \r  \nc  \r  \n");

run_make_test(xlate(q!
all:;@:$(foreach \
\r  a \t\
 , b\t \
 c \r ,$(info  \
  $a  \r  )  \
    )
!),
              '', "b  \r  \nc  \r  \n");

run_make_test(xlate(q!
define FOO
$(foreach
\r  a \t
 , b\t
 c \r ,$(info
  $a  \r  )
    )
endef
$(FOO)
all:;@:
!),
              '', "b  \r  \nc  \r  \n");

run_make_test(xlate(q!
define FOO
$(foreach
\r  a \t
 , b\t
 c \r ,$(info
  $a  \r  )
    )
endef
all:;@:$(FOO)
!),
              '', "b  \r  \nc  \r  \n");

# Test variables in recipes that expand to multiple lines

run_make_test(q!
define var

echo foo


echo bar
endef
all:;$(var)
!,
              '', "echo foo\nfoo\necho bar\nbar\n");

run_make_test(q!
define var

echo foo

@

echo bar
endef
all:;$(var)
!,
              '', "echo foo\nfoo\necho bar\nbar\n");

1;