]>
git.proxmox.com Git - rustc.git/blob - vendor/cc/tests/test.rs
1 use crate::support
::Test
;
5 // Some tests check that a flag is *not* present. These tests might fail if the flag is set in the
6 // CFLAGS or CXXFLAGS environment variables. This function clears the CFLAGS and CXXFLAGS
7 // variables to make sure that the tests can run correctly.
9 std
::env
::set_var("CFLAGS", "");
10 std
::env
::set_var("CXXFLAGS", "");
17 let test
= Test
::gnu();
18 test
.gcc().file("foo.c").compile("foo");
25 .must_have("-ffunction-sections")
26 .must_have("-fdata-sections");
27 test
.cmd(1).must_have(test
.td
.path().join("foo.o"));
31 fn gnu_opt_level_1() {
34 let test
= Test
::gnu();
35 test
.gcc().opt_level(1).file("foo.c").compile("foo");
37 test
.cmd(0).must_have("-O1").must_not_have("-O2");
41 fn gnu_opt_level_s() {
44 let test
= Test
::gnu();
45 test
.gcc().opt_level_str("s").file("foo.c").compile("foo");
52 .must_not_have("-Oz");
56 fn gnu_debug_fp_auto() {
57 let test
= Test
::gnu();
58 test
.gcc().debug(true).file("foo.c").compile("foo");
59 test
.cmd(0).must_have("-g");
60 test
.cmd(0).must_have("-fno-omit-frame-pointer");
65 let test
= Test
::gnu();
66 test
.gcc().debug(true).file("foo.c").compile("foo");
67 test
.cmd(0).must_have("-g");
68 test
.cmd(0).must_have("-fno-omit-frame-pointer");
75 let test
= Test
::gnu();
78 .force_frame_pointer(false)
81 test
.cmd(0).must_have("-g");
82 test
.cmd(0).must_not_have("-fno-omit-frame-pointer");
84 let test
= Test
::gnu();
86 .force_frame_pointer(false)
90 test
.cmd(0).must_have("-g");
91 test
.cmd(0).must_not_have("-fno-omit-frame-pointer");
95 fn gnu_warnings_into_errors() {
96 let test
= Test
::gnu();
98 .warnings_into_errors(true)
102 test
.cmd(0).must_have("-Werror");
107 let test
= Test
::gnu();
110 .flag("-Wno-missing-field-initializers")
114 test
.cmd(0).must_have("-Wall").must_have("-Wextra");
118 fn gnu_extra_warnings0() {
121 let test
= Test
::gnu();
124 .extra_warnings(false)
125 .flag("-Wno-missing-field-initializers")
129 test
.cmd(0).must_have("-Wall").must_not_have("-Wextra");
133 fn gnu_extra_warnings1() {
136 let test
= Test
::gnu();
139 .extra_warnings(true)
140 .flag("-Wno-missing-field-initializers")
144 test
.cmd(0).must_not_have("-Wall").must_have("-Wextra");
148 fn gnu_warnings_overridable() {
151 let test
= Test
::gnu();
154 .flag("-Wno-missing-field-initializers")
159 .must_have_in_order("-Wall", "-Wno-missing-field-initializers");
164 for vendor
in &["unknown-linux-gnu", "apple-darwin"] {
165 let target
= format
!("x86_64-{}", vendor
);
166 let test
= Test
::gnu();
173 test
.cmd(0).must_have("-fPIC").must_have("-m64");
178 fn gnu_x86_64_no_pic() {
181 for vendor
in &["unknown-linux-gnu", "apple-darwin"] {
182 let target
= format
!("x86_64-{}", vendor
);
183 let test
= Test
::gnu();
191 test
.cmd(0).must_not_have("-fPIC");
197 for vendor
in &["unknown-linux-gnu", "apple-darwin"] {
198 let target
= format
!("i686-{}", vendor
);
199 let test
= Test
::gnu();
206 test
.cmd(0).must_have("-m32");
212 for vendor
in &["unknown-linux-gnu", "apple-darwin"] {
213 let target
= format
!("i686-{}", vendor
);
214 let test
= Test
::gnu();
222 test
.cmd(0).must_have("-fPIC");
227 fn gnu_x86_64_no_plt() {
228 let target
= "x86_64-unknown-linux-gnu";
229 let test
= Test
::gnu();
237 test
.cmd(0).must_have("-fno-plt");
241 fn gnu_set_stdlib() {
244 let test
= Test
::gnu();
246 .cpp_set_stdlib(Some("foo"))
250 test
.cmd(0).must_not_have("-stdlib=foo");
255 let test
= Test
::gnu();
256 test
.gcc().include("foo/bar").file("foo.c").compile("foo");
258 test
.cmd(0).must_have("-I").must_have("foo/bar");
263 let test
= Test
::gnu();
265 .define("FOO", "bar")
270 test
.cmd(0).must_have("-DFOO=bar").must_have("-DBAR");
274 fn gnu_compile_assembly() {
275 let test
= Test
::gnu();
276 test
.gcc().file("foo.S").compile("foo");
277 test
.cmd(0).must_have("foo.S");
284 let test
= Test
::gnu();
291 test
.cmd(0).must_have("-shared").must_not_have("-static");
295 fn gnu_flag_if_supported() {
301 let test
= Test
::gnu();
305 .flag_if_supported("-Wall")
306 .flag_if_supported("-Wflag-does-not-exist")
307 .flag_if_supported("-std=c++11")
313 .must_not_have("-Wflag-does-not-exist")
314 .must_not_have("-std=c++11");
318 fn gnu_flag_if_supported_cpp() {
322 let test
= Test
::gnu();
326 .flag_if_supported("-std=c++11")
329 test
.cmd(0).must_have("-std=c++11");
336 let test
= Test
::gnu();
343 test
.cmd(0).must_have("-static").must_not_have("-shared");
350 let test
= Test
::msvc();
351 test
.gcc().file("foo.c").compile("foo");
356 .must_not_have("-Z7")
359 test
.cmd(1).must_have(test
.td
.path().join("foo.o"));
363 fn msvc_opt_level_0() {
366 let test
= Test
::msvc();
367 test
.gcc().opt_level(0).file("foo.c").compile("foo");
369 test
.cmd(0).must_not_have("-O2");
374 let test
= Test
::msvc();
375 test
.gcc().debug(true).file("foo.c").compile("foo");
376 test
.cmd(0).must_have("-Z7");
381 let test
= Test
::msvc();
382 test
.gcc().include("foo/bar").file("foo.c").compile("foo");
384 test
.cmd(0).must_have("-I").must_have("foo/bar");
389 let test
= Test
::msvc();
391 .define("FOO", "bar")
396 test
.cmd(0).must_have("-DFOO=bar").must_have("-DBAR");
400 fn msvc_static_crt() {
401 let test
= Test
::msvc();
402 test
.gcc().static_crt(true).file("foo.c").compile("foo");
404 test
.cmd(0).must_have("-MT");
408 fn msvc_no_static_crt() {
409 let test
= Test
::msvc();
410 test
.gcc().static_crt(false).file("foo.c").compile("foo");
412 test
.cmd(0).must_have("-MD");