Imported Upstream version 4.4
[platform/upstream/make.git] / tests / scripts / misc / bs-nl
1 #                                                                    -*-perl-*-
2 $description = "Test backslash-newline handling.";
3
4 $details = "";
5
6 # TEST #1
7 # -------
8
9 # Backslash-newlines in recipes
10
11 # These are basic backslash-newlines with no tricks
12 run_make_test("fast:;\@echo fa\\\nst\n",
13               '', 'fast');
14
15 run_make_test("slow:;\@: no-op; echo sl\\\now\n",
16               '', 'slow');
17
18 run_make_test("dquote:;\@echo \"dqu\\\note\"\n",
19               '', 'dquote');
20
21 # Single quotes don't behave the same in Windows
22 if ($port_type ne 'W32') {
23     run_make_test("squote:;\@echo 'squ\\\note'\n",
24               '', "squ\\\note");
25 }
26
27 # Ensure that a leading prefix character is omitted
28 run_make_test("fast:;\@echo fa\\\n\tst\n",
29               '', 'fast');
30
31 run_make_test("slow:;\@: no-op; echo sl\\\n\tow\n",
32               '', 'slow');
33
34 run_make_test("dquote:;\@echo \"dqu\\\n\tote\"\n",
35               '', 'dquote');
36
37 # Single quotes don't behave the same in Windows
38 if ($port_type ne 'W32') {
39     run_make_test("squote:;\@echo 'squ\\\n\tote'\n",
40               '', "squ\\\note");
41 }
42
43 # Ensure that ONLY the leading prefix character is omitted
44 run_make_test("fast:;\@echo fa\\\n\t  st\n",
45               '', 'fa st');
46
47 run_make_test("slow:;\@: no-op; echo sl\\\n\t\tow\n",
48               '', "sl ow");
49
50 run_make_test("dquote:;\@echo \"dqu\\\n\t    ote\"\n",
51               '', 'dqu    ote');
52
53 run_make_test("squote:;\@echo 'squ\\\n\t\t   ote'\n",
54               '', "squ\\\n\t   ote");
55
56 # Backslash-newlines in variable values
57
58 # Simple
59 run_make_test(q!
60 var = he\
61 llo
62 var:;@echo '|$(var)|'!,
63               '', "|he llo|");
64
65 # Condense trailing space
66 run_make_test(q!
67 var = he  \
68 llo
69 var:;@echo '|$(var)|'!,
70               '', "|he llo|");
71
72 # Remove leading space
73 run_make_test(q!
74 var = he\
75     llo
76 var:;@echo '|$(var)|'!,
77               '', "|he llo|");
78
79 # Multiple bs/nl condensed
80 run_make_test(q!
81 var = he\
82 \
83 \
84     llo
85 var:;@echo '|$(var)|'!,
86               '', "|he llo|");
87
88 # POSIX: Preserve trailing space
89 run_make_test(q!
90 .POSIX:
91 var = he  \
92 llo
93 var:;@echo '|$(var)|'!,
94               '', "|he   llo|");
95
96 # POSIX: One space per bs-nl
97 run_make_test(q!
98 .POSIX:
99 var = he\
100 \
101 \
102     llo
103 var:;@echo '|$(var)|'!,
104               '', "|he   llo|");
105
106 # Savannah #39035: handle whitespace in call
107 run_make_test(q!
108 f = echo $(1)
109 t:; @$(call f,"a \
110             b"); \
111         $(call f,"a \
112             b")
113 !,
114               '', "a b\na b\n");
115
116 # Savannah #38945: handle backslash CRLF
117 # We need our own makefile so we can set binmode
118 my $m1 = get_tmpfile();
119 open(MAKEFILE, "> $m1");
120 binmode(MAKEFILE);
121 print MAKEFILE "FOO = foo \\\r\n";
122 close(MAKEFILE);
123
124 my $m2 = get_tmpfile();
125 open(MAKEFILE, "> $m2");
126 print MAKEFILE "include $m1\ndefine BAR\nall: ; \@echo \$(FOO) bar\nendef\n\$(eval \$(BAR))\n";
127 close(MAKEFILE);
128
129 run_make_with_options($m2, '', get_logfile());
130 compare_output("foo bar\n", get_logfile(1));
131
132 # Test different types of whitespace, and bsnl inside functions
133
134 sub xlate
135 {
136     $_ = $_[0];
137     s/\\r/\r/g;
138     s/\\t/\t/g;
139     s/\\f/\f/g;
140     s/\\n/\n/g;
141     return $_;
142 }
143
144 run_make_test(xlate(q!
145 $(foreach\r  a \t , b\t  c \r ,$(info    $a  \r  )      )
146 all:;@:
147 !),
148               '', "b  \r  \nc  \r  \n");
149
150 run_make_test(xlate(q!
151 all:;@:$(foreach\r  a \t , b\t  c \r ,$(info    $a  \r  )      )
152 !),
153               '', "b  \r  \nc  \r  \n");
154
155 run_make_test(xlate(q!
156 $(foreach \
157 \r  a \t\
158  , b\t \
159  c \r ,$(info  \
160   $a  \r  )  \
161     )
162 all:;@:
163 !),
164               '', "b  \r  \nc  \r  \n");
165
166 run_make_test(xlate(q!
167 all:;@:$(foreach \
168 \r  a \t\
169  , b\t \
170  c \r ,$(info  \
171   $a  \r  )  \
172     )
173 !),
174               '', "b  \r  \nc  \r  \n");
175
176 run_make_test(xlate(q!
177 define FOO
178 $(foreach
179 \r  a \t
180  , b\t
181  c \r ,$(info
182   $a  \r  )
183     )
184 endef
185 $(FOO)
186 all:;@:
187 !),
188               '', "b  \r  \nc  \r  \n");
189
190 run_make_test(xlate(q!
191 define FOO
192 $(foreach
193 \r  a \t
194  , b\t
195  c \r ,$(info
196   $a  \r  )
197     )
198 endef
199 all:;@:$(FOO)
200 !),
201               '', "b  \r  \nc  \r  \n");
202
203 # Test variables in recipes that expand to multiple lines
204
205 run_make_test(q!
206 define var
207
208 echo foo
209
210
211 echo bar
212 endef
213 all:;$(var)
214 !,
215               '', "echo foo\nfoo\necho bar\nbar\n");
216
217 run_make_test(q!
218 define var
219
220 echo foo
221
222 @
223
224 echo bar
225 endef
226 all:;$(var)
227 !,
228               '', "echo foo\nfoo\necho bar\nbar\n");
229
230 1;