]> git.proxmox.com Git - rustc.git/blob - vendor/cc/tests/test.rs
New upstream version 1.41.1+dfsg1
[rustc.git] / vendor / cc / tests / test.rs
1 use crate::support::Test;
2
3 mod support;
4
5 #[test]
6 fn gnu_smoke() {
7 let test = Test::gnu();
8 test.gcc().file("foo.c").compile("foo");
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");
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();
23 test.gcc().opt_level(1).file("foo.c").compile("foo");
24
25 test.cmd(0).must_have("-O1").must_not_have("-O2");
26 }
27
28 #[test]
29 fn gnu_opt_level_s() {
30 let test = Test::gnu();
31 test.gcc().opt_level_str("s").file("foo.c").compile("foo");
32
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");
39 }
40
41 #[test]
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() {
51 let test = Test::gnu();
52 test.gcc().debug(true).file("foo.c").compile("foo");
53 test.cmd(0).must_have("-g");
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");
76 }
77
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)
94 .flag("-Wno-missing-field-initializers")
95 .file("foo.c")
96 .compile("foo");
97
98 test.cmd(0).must_have("-Wall").must_have("-Wextra");
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");
125 }
126
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
136 test.cmd(0)
137 .must_have_in_order("-Wall", "-Wno-missing-field-initializers");
138 }
139
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)
148 .file("foo.c")
149 .compile("foo");
150
151 test.cmd(0).must_have("-fPIC").must_have("-m64");
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)
164 .file("foo.c")
165 .compile("foo");
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)
179 .file("foo.c")
180 .compile("foo");
181
182 test.cmd(0).must_have("-m32");
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)
195 .file("foo.c")
196 .compile("foo");
197
198 test.cmd(0).must_have("-fPIC");
199 }
200 }
201
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
216 #[test]
217 fn gnu_set_stdlib() {
218 let test = Test::gnu();
219 test.gcc()
220 .cpp_set_stdlib(Some("foo"))
221 .file("foo.c")
222 .compile("foo");
223
224 test.cmd(0).must_not_have("-stdlib=foo");
225 }
226
227 #[test]
228 fn gnu_include() {
229 let test = Test::gnu();
230 test.gcc().include("foo/bar").file("foo.c").compile("foo");
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()
239 .define("FOO", "bar")
240 .define("BAR", None)
241 .file("foo.c")
242 .compile("foo");
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();
250 test.gcc().file("foo.S").compile("foo");
251 test.cmd(0).must_have("foo.S");
252 }
253
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)
261 .compile("foo");
262
263 test.cmd(0).must_have("-shared").must_not_have("-static");
264 }
265
266 #[test]
267 fn gnu_flag_if_supported() {
268 if cfg!(windows) {
269 return;
270 }
271 let test = Test::gnu();
272 test.gcc()
273 .file("foo.c")
274 .flag("-v")
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)
281 .must_have("-v")
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) {
290 return;
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
299 test.cmd(0).must_have("-std=c++11");
300 }
301
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)
309 .compile("foo");
310
311 test.cmd(0).must_have("-static").must_not_have("-shared");
312 }
313
314 #[test]
315 fn msvc_smoke() {
316 let test = Test::msvc();
317 test.gcc().file("foo.c").compile("foo");
318
319 test.cmd(0)
320 .must_have("-O2")
321 .must_have("foo.c")
322 .must_not_have("-Z7")
323 .must_have("-c")
324 .must_have("-MD");
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();
331 test.gcc().opt_level(0).file("foo.c").compile("foo");
332
333 test.cmd(0).must_not_have("-O2");
334 }
335
336 #[test]
337 fn msvc_debug() {
338 let test = Test::msvc();
339 test.gcc().debug(true).file("foo.c").compile("foo");
340 test.cmd(0).must_have("-Z7");
341 }
342
343 #[test]
344 fn msvc_include() {
345 let test = Test::msvc();
346 test.gcc().include("foo/bar").file("foo.c").compile("foo");
347
348 test.cmd(0).must_have("-I").must_have("foo/bar");
349 }
350
351 #[test]
352 fn msvc_define() {
353 let test = Test::msvc();
354 test.gcc()
355 .define("FOO", "bar")
356 .define("BAR", None)
357 .file("foo.c")
358 .compile("foo");
359
360 test.cmd(0).must_have("-DFOO=bar").must_have("-DBAR");
361 }
362
363 #[test]
364 fn msvc_static_crt() {
365 let test = Test::msvc();
366 test.gcc().static_crt(true).file("foo.c").compile("foo");
367
368 test.cmd(0).must_have("-MT");
369 }
370
371 #[test]
372 fn msvc_no_static_crt() {
373 let test = Test::msvc();
374 test.gcc().static_crt(false).file("foo.c").compile("foo");
375
376 test.cmd(0).must_have("-MD");
377 }