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