]>
Commit | Line | Data |
---|---|---|
60c5eb7d | 1 | use crate::support::Test; |
476ff2be SL |
2 | |
3 | mod support; | |
4 | ||
5 | #[test] | |
6 | fn gnu_smoke() { | |
7 | let test = Test::gnu(); | |
0531ce1d | 8 | test.gcc().file("foo.c").compile("foo"); |
8bb4bdeb XL |
9 | |
10 | test.cmd(0) | |
11 | .must_have("-O2") | |
12 | .must_have("foo.c") | |
13 | .must_not_have("-g") | |
14 | .must_have("-c") | |
15 | .must_have("-ffunction-sections") | |
16 | .must_have("-fdata-sections"); | |
476ff2be SL |
17 | test.cmd(1).must_have(test.td.path().join("foo.o")); |
18 | } | |
19 | ||
20 | #[test] | |
21 | fn gnu_opt_level_1() { | |
22 | let test = Test::gnu(); | |
0531ce1d | 23 | test.gcc().opt_level(1).file("foo.c").compile("foo"); |
476ff2be | 24 | |
0531ce1d | 25 | test.cmd(0).must_have("-O1").must_not_have("-O2"); |
476ff2be SL |
26 | } |
27 | ||
28 | #[test] | |
29 | fn gnu_opt_level_s() { | |
30 | let test = Test::gnu(); | |
0531ce1d | 31 | test.gcc().opt_level_str("s").file("foo.c").compile("foo"); |
476ff2be | 32 | |
8bb4bdeb XL |
33 | test.cmd(0) |
34 | .must_have("-Os") | |
35 | .must_not_have("-O1") | |
36 | .must_not_have("-O2") | |
37 | .must_not_have("-O3") | |
38 | .must_not_have("-Oz"); | |
476ff2be SL |
39 | } |
40 | ||
41 | #[test] | |
60c5eb7d XL |
42 | fn gnu_debug_fp_auto() { |
43 | let test = Test::gnu(); | |
44 | test.gcc().debug(true).file("foo.c").compile("foo"); | |
45 | test.cmd(0).must_have("-g"); | |
46 | test.cmd(0).must_have("-fno-omit-frame-pointer"); | |
47 | } | |
48 | ||
49 | #[test] | |
50 | fn gnu_debug_fp() { | |
476ff2be | 51 | let test = Test::gnu(); |
0531ce1d | 52 | test.gcc().debug(true).file("foo.c").compile("foo"); |
476ff2be | 53 | test.cmd(0).must_have("-g"); |
60c5eb7d XL |
54 | test.cmd(0).must_have("-fno-omit-frame-pointer"); |
55 | } | |
56 | ||
57 | #[test] | |
58 | fn gnu_debug_nofp() { | |
59 | let test = Test::gnu(); | |
60 | test.gcc() | |
61 | .debug(true) | |
62 | .force_frame_pointer(false) | |
63 | .file("foo.c") | |
64 | .compile("foo"); | |
65 | test.cmd(0).must_have("-g"); | |
66 | test.cmd(0).must_not_have("-fno-omit-frame-pointer"); | |
67 | ||
68 | let test = Test::gnu(); | |
69 | test.gcc() | |
70 | .force_frame_pointer(false) | |
71 | .debug(true) | |
72 | .file("foo.c") | |
73 | .compile("foo"); | |
74 | test.cmd(0).must_have("-g"); | |
75 | test.cmd(0).must_not_have("-fno-omit-frame-pointer"); | |
476ff2be SL |
76 | } |
77 | ||
ea8adc8c XL |
78 | #[test] |
79 | fn gnu_warnings_into_errors() { | |
80 | let test = Test::gnu(); | |
81 | test.gcc() | |
82 | .warnings_into_errors(true) | |
83 | .file("foo.c") | |
84 | .compile("foo"); | |
85 | ||
86 | test.cmd(0).must_have("-Werror"); | |
87 | } | |
88 | ||
89 | #[test] | |
90 | fn gnu_warnings() { | |
91 | let test = Test::gnu(); | |
92 | test.gcc() | |
93 | .warnings(true) | |
abe05a73 | 94 | .flag("-Wno-missing-field-initializers") |
ea8adc8c XL |
95 | .file("foo.c") |
96 | .compile("foo"); | |
97 | ||
0531ce1d | 98 | test.cmd(0).must_have("-Wall").must_have("-Wextra"); |
94b46f34 XL |
99 | } |
100 | ||
101 | #[test] | |
102 | fn gnu_extra_warnings0() { | |
103 | let test = Test::gnu(); | |
104 | test.gcc() | |
105 | .warnings(true) | |
106 | .extra_warnings(false) | |
107 | .flag("-Wno-missing-field-initializers") | |
108 | .file("foo.c") | |
109 | .compile("foo"); | |
110 | ||
111 | test.cmd(0).must_have("-Wall").must_not_have("-Wextra"); | |
112 | } | |
113 | ||
114 | #[test] | |
115 | fn gnu_extra_warnings1() { | |
116 | let test = Test::gnu(); | |
117 | test.gcc() | |
118 | .warnings(false) | |
119 | .extra_warnings(true) | |
120 | .flag("-Wno-missing-field-initializers") | |
121 | .file("foo.c") | |
122 | .compile("foo"); | |
123 | ||
124 | test.cmd(0).must_not_have("-Wall").must_have("-Wextra"); | |
ea8adc8c XL |
125 | } |
126 | ||
abe05a73 XL |
127 | #[test] |
128 | fn gnu_warnings_overridable() { | |
129 | let test = Test::gnu(); | |
130 | test.gcc() | |
131 | .warnings(true) | |
132 | .flag("-Wno-missing-field-initializers") | |
133 | .file("foo.c") | |
134 | .compile("foo"); | |
135 | ||
0531ce1d XL |
136 | test.cmd(0) |
137 | .must_have_in_order("-Wall", "-Wno-missing-field-initializers"); | |
abe05a73 XL |
138 | } |
139 | ||
476ff2be SL |
140 | #[test] |
141 | fn gnu_x86_64() { | |
142 | for vendor in &["unknown-linux-gnu", "apple-darwin"] { | |
143 | let target = format!("x86_64-{}", vendor); | |
144 | let test = Test::gnu(); | |
145 | test.gcc() | |
146 | .target(&target) | |
147 | .host(&target) | |
8bb4bdeb | 148 | .file("foo.c") |
ea8adc8c | 149 | .compile("foo"); |
476ff2be | 150 | |
0531ce1d | 151 | test.cmd(0).must_have("-fPIC").must_have("-m64"); |
476ff2be SL |
152 | } |
153 | } | |
154 | ||
155 | #[test] | |
156 | fn gnu_x86_64_no_pic() { | |
157 | for vendor in &["unknown-linux-gnu", "apple-darwin"] { | |
158 | let target = format!("x86_64-{}", vendor); | |
159 | let test = Test::gnu(); | |
160 | test.gcc() | |
161 | .pic(false) | |
162 | .target(&target) | |
163 | .host(&target) | |
8bb4bdeb | 164 | .file("foo.c") |
ea8adc8c | 165 | .compile("foo"); |
476ff2be SL |
166 | |
167 | test.cmd(0).must_not_have("-fPIC"); | |
168 | } | |
169 | } | |
170 | ||
171 | #[test] | |
172 | fn gnu_i686() { | |
173 | for vendor in &["unknown-linux-gnu", "apple-darwin"] { | |
174 | let target = format!("i686-{}", vendor); | |
175 | let test = Test::gnu(); | |
176 | test.gcc() | |
177 | .target(&target) | |
178 | .host(&target) | |
8bb4bdeb | 179 | .file("foo.c") |
ea8adc8c | 180 | .compile("foo"); |
476ff2be | 181 | |
0531ce1d | 182 | test.cmd(0).must_have("-m32"); |
476ff2be SL |
183 | } |
184 | } | |
185 | ||
186 | #[test] | |
187 | fn gnu_i686_pic() { | |
188 | for vendor in &["unknown-linux-gnu", "apple-darwin"] { | |
189 | let target = format!("i686-{}", vendor); | |
190 | let test = Test::gnu(); | |
191 | test.gcc() | |
192 | .pic(true) | |
193 | .target(&target) | |
194 | .host(&target) | |
8bb4bdeb | 195 | .file("foo.c") |
ea8adc8c | 196 | .compile("foo"); |
476ff2be SL |
197 | |
198 | test.cmd(0).must_have("-fPIC"); | |
199 | } | |
200 | } | |
201 | ||
0731742a XL |
202 | #[test] |
203 | fn gnu_x86_64_no_plt() { | |
204 | let target = "x86_64-unknown-linux-gnu"; | |
205 | let test = Test::gnu(); | |
206 | test.gcc() | |
207 | .pic(true) | |
208 | .use_plt(false) | |
209 | .target(&target) | |
210 | .host(&target) | |
211 | .file("foo.c") | |
212 | .compile("foo"); | |
213 | test.cmd(0).must_have("-fno-plt"); | |
214 | } | |
215 | ||
476ff2be SL |
216 | #[test] |
217 | fn gnu_set_stdlib() { | |
218 | let test = Test::gnu(); | |
219 | test.gcc() | |
220 | .cpp_set_stdlib(Some("foo")) | |
8bb4bdeb | 221 | .file("foo.c") |
ea8adc8c | 222 | .compile("foo"); |
476ff2be SL |
223 | |
224 | test.cmd(0).must_not_have("-stdlib=foo"); | |
225 | } | |
226 | ||
227 | #[test] | |
228 | fn gnu_include() { | |
229 | let test = Test::gnu(); | |
0531ce1d | 230 | test.gcc().include("foo/bar").file("foo.c").compile("foo"); |
476ff2be SL |
231 | |
232 | test.cmd(0).must_have("-I").must_have("foo/bar"); | |
233 | } | |
234 | ||
235 | #[test] | |
236 | fn gnu_define() { | |
237 | let test = Test::gnu(); | |
238 | test.gcc() | |
ea8adc8c | 239 | .define("FOO", "bar") |
476ff2be | 240 | .define("BAR", None) |
8bb4bdeb | 241 | .file("foo.c") |
ea8adc8c | 242 | .compile("foo"); |
476ff2be SL |
243 | |
244 | test.cmd(0).must_have("-DFOO=bar").must_have("-DBAR"); | |
245 | } | |
246 | ||
247 | #[test] | |
248 | fn gnu_compile_assembly() { | |
249 | let test = Test::gnu(); | |
0531ce1d | 250 | test.gcc().file("foo.S").compile("foo"); |
476ff2be SL |
251 | test.cmd(0).must_have("foo.S"); |
252 | } | |
253 | ||
041b39d2 XL |
254 | #[test] |
255 | fn gnu_shared() { | |
256 | let test = Test::gnu(); | |
257 | test.gcc() | |
258 | .file("foo.c") | |
259 | .shared_flag(true) | |
260 | .static_flag(false) | |
ea8adc8c | 261 | .compile("foo"); |
041b39d2 | 262 | |
0531ce1d | 263 | test.cmd(0).must_have("-shared").must_not_have("-static"); |
041b39d2 XL |
264 | } |
265 | ||
ea8adc8c XL |
266 | #[test] |
267 | fn gnu_flag_if_supported() { | |
268 | if cfg!(windows) { | |
0531ce1d | 269 | return; |
ea8adc8c XL |
270 | } |
271 | let test = Test::gnu(); | |
272 | test.gcc() | |
273 | .file("foo.c") | |
b7449926 | 274 | .flag("-v") |
ea8adc8c XL |
275 | .flag_if_supported("-Wall") |
276 | .flag_if_supported("-Wflag-does-not-exist") | |
277 | .flag_if_supported("-std=c++11") | |
278 | .compile("foo"); | |
279 | ||
280 | test.cmd(0) | |
b7449926 | 281 | .must_have("-v") |
ea8adc8c XL |
282 | .must_have("-Wall") |
283 | .must_not_have("-Wflag-does-not-exist") | |
284 | .must_not_have("-std=c++11"); | |
285 | } | |
286 | ||
287 | #[test] | |
288 | fn gnu_flag_if_supported_cpp() { | |
289 | if cfg!(windows) { | |
0531ce1d | 290 | return; |
ea8adc8c XL |
291 | } |
292 | let test = Test::gnu(); | |
293 | test.gcc() | |
294 | .cpp(true) | |
295 | .file("foo.cpp") | |
296 | .flag_if_supported("-std=c++11") | |
297 | .compile("foo"); | |
298 | ||
0531ce1d | 299 | test.cmd(0).must_have("-std=c++11"); |
ea8adc8c XL |
300 | } |
301 | ||
041b39d2 XL |
302 | #[test] |
303 | fn gnu_static() { | |
304 | let test = Test::gnu(); | |
305 | test.gcc() | |
306 | .file("foo.c") | |
307 | .shared_flag(false) | |
308 | .static_flag(true) | |
ea8adc8c | 309 | .compile("foo"); |
041b39d2 | 310 | |
0531ce1d | 311 | test.cmd(0).must_have("-static").must_not_have("-shared"); |
041b39d2 XL |
312 | } |
313 | ||
476ff2be SL |
314 | #[test] |
315 | fn msvc_smoke() { | |
316 | let test = Test::msvc(); | |
0531ce1d | 317 | test.gcc().file("foo.c").compile("foo"); |
8bb4bdeb XL |
318 | |
319 | test.cmd(0) | |
60c5eb7d | 320 | .must_have("-O2") |
8bb4bdeb | 321 | .must_have("foo.c") |
60c5eb7d XL |
322 | .must_not_have("-Z7") |
323 | .must_have("-c") | |
324 | .must_have("-MD"); | |
476ff2be SL |
325 | test.cmd(1).must_have(test.td.path().join("foo.o")); |
326 | } | |
327 | ||
328 | #[test] | |
329 | fn msvc_opt_level_0() { | |
330 | let test = Test::msvc(); | |
0531ce1d | 331 | test.gcc().opt_level(0).file("foo.c").compile("foo"); |
476ff2be | 332 | |
60c5eb7d | 333 | test.cmd(0).must_not_have("-O2"); |
476ff2be SL |
334 | } |
335 | ||
336 | #[test] | |
337 | fn msvc_debug() { | |
338 | let test = Test::msvc(); | |
0531ce1d | 339 | test.gcc().debug(true).file("foo.c").compile("foo"); |
60c5eb7d | 340 | test.cmd(0).must_have("-Z7"); |
476ff2be SL |
341 | } |
342 | ||
343 | #[test] | |
344 | fn msvc_include() { | |
345 | let test = Test::msvc(); | |
0531ce1d | 346 | test.gcc().include("foo/bar").file("foo.c").compile("foo"); |
476ff2be | 347 | |
60c5eb7d | 348 | test.cmd(0).must_have("-I").must_have("foo/bar"); |
476ff2be SL |
349 | } |
350 | ||
351 | #[test] | |
352 | fn msvc_define() { | |
353 | let test = Test::msvc(); | |
354 | test.gcc() | |
ea8adc8c | 355 | .define("FOO", "bar") |
476ff2be | 356 | .define("BAR", None) |
8bb4bdeb | 357 | .file("foo.c") |
ea8adc8c | 358 | .compile("foo"); |
476ff2be | 359 | |
60c5eb7d | 360 | test.cmd(0).must_have("-DFOO=bar").must_have("-DBAR"); |
476ff2be | 361 | } |
7cac9316 XL |
362 | |
363 | #[test] | |
364 | fn msvc_static_crt() { | |
365 | let test = Test::msvc(); | |
0531ce1d | 366 | test.gcc().static_crt(true).file("foo.c").compile("foo"); |
7cac9316 | 367 | |
60c5eb7d | 368 | test.cmd(0).must_have("-MT"); |
7cac9316 XL |
369 | } |
370 | ||
371 | #[test] | |
372 | fn msvc_no_static_crt() { | |
373 | let test = Test::msvc(); | |
0531ce1d | 374 | test.gcc().static_crt(false).file("foo.c").compile("foo"); |
7cac9316 | 375 | |
60c5eb7d | 376 | test.cmd(0).must_have("-MD"); |
7cac9316 | 377 | } |