]> git.proxmox.com Git - rustc.git/blob - src/vendor/gcc/tests/test.rs
New upstream version 1.15.0+dfsg1
[rustc.git] / src / vendor / gcc / tests / test.rs
1 extern crate gcc;
2 extern crate tempdir;
3
4 use support::Test;
5
6 mod support;
7
8 #[test]
9 fn gnu_smoke() {
10 let test = Test::gnu();
11 test.gcc()
12 .file("foo.c").compile("libfoo.a");
13
14 test.cmd(0).must_have("-O2")
15 .must_have("foo.c")
16 .must_not_have("-g")
17 .must_have("-c")
18 .must_have("-ffunction-sections")
19 .must_have("-fdata-sections");
20 test.cmd(1).must_have(test.td.path().join("foo.o"));
21 }
22
23 #[test]
24 fn gnu_opt_level_1() {
25 let test = Test::gnu();
26 test.gcc()
27 .opt_level(1)
28 .file("foo.c").compile("libfoo.a");
29
30 test.cmd(0).must_have("-O1")
31 .must_not_have("-O2");
32 }
33
34 #[test]
35 fn gnu_opt_level_s() {
36 let test = Test::gnu();
37 test.gcc()
38 .opt_level_str("s")
39 .file("foo.c").compile("libfoo.a");
40
41 test.cmd(0).must_have("-Os")
42 .must_not_have("-O1")
43 .must_not_have("-O2")
44 .must_not_have("-O3")
45 .must_not_have("-Oz");
46 }
47
48 #[test]
49 fn gnu_debug() {
50 let test = Test::gnu();
51 test.gcc()
52 .debug(true)
53 .file("foo.c").compile("libfoo.a");
54 test.cmd(0).must_have("-g");
55 }
56
57 #[test]
58 fn gnu_x86_64() {
59 for vendor in &["unknown-linux-gnu", "apple-darwin"] {
60 let target = format!("x86_64-{}", vendor);
61 let test = Test::gnu();
62 test.gcc()
63 .target(&target)
64 .host(&target)
65 .file("foo.c").compile("libfoo.a");
66
67 test.cmd(0).must_have("-fPIC")
68 .must_have("-m64");
69 }
70 }
71
72 #[test]
73 fn gnu_x86_64_no_pic() {
74 for vendor in &["unknown-linux-gnu", "apple-darwin"] {
75 let target = format!("x86_64-{}", vendor);
76 let test = Test::gnu();
77 test.gcc()
78 .pic(false)
79 .target(&target)
80 .host(&target)
81 .file("foo.c").compile("libfoo.a");
82
83 test.cmd(0).must_not_have("-fPIC");
84 }
85 }
86
87 #[test]
88 fn gnu_i686() {
89 for vendor in &["unknown-linux-gnu", "apple-darwin"] {
90 let target = format!("i686-{}", vendor);
91 let test = Test::gnu();
92 test.gcc()
93 .target(&target)
94 .host(&target)
95 .file("foo.c").compile("libfoo.a");
96
97 test.cmd(0).must_not_have("-fPIC")
98 .must_have("-m32");
99 }
100 }
101
102 #[test]
103 fn gnu_i686_pic() {
104 for vendor in &["unknown-linux-gnu", "apple-darwin"] {
105 let target = format!("i686-{}", vendor);
106 let test = Test::gnu();
107 test.gcc()
108 .pic(true)
109 .target(&target)
110 .host(&target)
111 .file("foo.c").compile("libfoo.a");
112
113 test.cmd(0).must_have("-fPIC");
114 }
115 }
116
117 #[test]
118 fn gnu_set_stdlib() {
119 let test = Test::gnu();
120 test.gcc()
121 .cpp_set_stdlib(Some("foo"))
122 .file("foo.c").compile("libfoo.a");
123
124 test.cmd(0).must_not_have("-stdlib=foo");
125 }
126
127 #[test]
128 fn gnu_include() {
129 let test = Test::gnu();
130 test.gcc()
131 .include("foo/bar")
132 .file("foo.c").compile("libfoo.a");
133
134 test.cmd(0).must_have("-I").must_have("foo/bar");
135 }
136
137 #[test]
138 fn gnu_define() {
139 let test = Test::gnu();
140 test.gcc()
141 .define("FOO", Some("bar"))
142 .define("BAR", None)
143 .file("foo.c").compile("libfoo.a");
144
145 test.cmd(0).must_have("-DFOO=bar").must_have("-DBAR");
146 }
147
148 #[test]
149 fn gnu_compile_assembly() {
150 let test = Test::gnu();
151 test.gcc()
152 .file("foo.S").compile("libfoo.a");
153 test.cmd(0).must_have("foo.S");
154 }
155
156 #[test]
157 fn msvc_smoke() {
158 let test = Test::msvc();
159 test.gcc()
160 .file("foo.c").compile("libfoo.a");
161
162 test.cmd(0).must_have("/O2")
163 .must_have("foo.c")
164 .must_not_have("/Z7")
165 .must_have("/c");
166 test.cmd(1).must_have(test.td.path().join("foo.o"));
167 }
168
169 #[test]
170 fn msvc_opt_level_0() {
171 let test = Test::msvc();
172 test.gcc()
173 .opt_level(0)
174 .file("foo.c").compile("libfoo.a");
175
176 test.cmd(0).must_not_have("/O2");
177 }
178
179 #[test]
180 fn msvc_debug() {
181 let test = Test::msvc();
182 test.gcc()
183 .debug(true)
184 .file("foo.c").compile("libfoo.a");
185 test.cmd(0).must_have("/Z7");
186 }
187
188 #[test]
189 fn msvc_include() {
190 let test = Test::msvc();
191 test.gcc()
192 .include("foo/bar")
193 .file("foo.c").compile("libfoo.a");
194
195 test.cmd(0).must_have("/I").must_have("foo/bar");
196 }
197
198 #[test]
199 fn msvc_define() {
200 let test = Test::msvc();
201 test.gcc()
202 .define("FOO", Some("bar"))
203 .define("BAR", None)
204 .file("foo.c").compile("libfoo.a");
205
206 test.cmd(0).must_have("/DFOO=bar").must_have("/DBAR");
207 }