]> git.proxmox.com Git - cargo.git/blame - tests/testsuite/profile_config.rs
Auto merge of #7755 - lu-zero:rustc-crate-type, r=alexcrichton
[cargo.git] / tests / testsuite / profile_config.rs
CommitLineData
83571aee
EH
1//! Tests for profiles defined in config files.
2
61fb34b0 3use cargo_test_support::{basic_lib_manifest, paths, project};
2f7b5225 4
0e0d9688 5#[cargo_test]
2f7b5225 6fn profile_config_gated() {
7fe2fbc8 7 let p = project()
2f7b5225
EH
8 .file("Cargo.toml", &basic_lib_manifest("foo"))
9 .file("src/lib.rs", "")
10 .file(
11 ".cargo/config",
12 r#"
13 [profile.dev]
14 debug = 1
15 "#,
fecb7246
AC
16 )
17 .build();
2f7b5225 18
85984a87
DW
19 p.cargo("build -v")
20 .with_stderr_contains(
21 "\
84a80d8f 22[WARNING] profiles in config files require `-Z config-profile` command-line option
2f7b5225 23",
fecb7246
AC
24 )
25 .with_stderr_contains("[..]-C debuginfo=2[..]")
85984a87 26 .run();
2f7b5225
EH
27}
28
0e0d9688 29#[cargo_test]
2f7b5225 30fn profile_config_validate_warnings() {
7fe2fbc8 31 let p = project()
dda81d31 32 .file("Cargo.toml", &basic_lib_manifest("foo"))
fecb7246 33 .file("src/lib.rs", "")
2f7b5225
EH
34 .file(
35 ".cargo/config",
36 r#"
37 [profile.test]
38 opt-level = 3
39
40 [profile.asdf]
41 opt-level = 3
42
43 [profile.dev]
44 bad-key = true
45
46 [profile.dev.build-override]
47 bad-key-bo = true
48
fcfe0b89 49 [profile.dev.package.bar]
2f7b5225
EH
50 bad-key-bar = true
51 "#,
fecb7246
AC
52 )
53 .build();
2f7b5225 54
85984a87
DW
55 p.cargo("build -Z config-profile")
56 .masquerade_as_nightly_cargo()
57 .with_stderr_unordered(
84a80d8f 58 "\
91015d52
EH
59[WARNING] unused config key `profile.asdf` in `[..].cargo/config`
60[WARNING] unused config key `profile.test` in `[..].cargo/config`
61[WARNING] unused config key `profile.dev.bad-key` in `[..].cargo/config`
62[WARNING] unused config key `profile.dev.package.bar.bad-key-bar` in `[..].cargo/config`
63[WARNING] unused config key `profile.dev.build-override.bad-key-bo` in `[..].cargo/config`
84a80d8f
EH
64[COMPILING] foo [..]
65[FINISHED] [..]
2f7b5225 66",
fecb7246
AC
67 )
68 .run();
2f7b5225
EH
69}
70
0e0d9688 71#[cargo_test]
2f7b5225 72fn profile_config_error_paths() {
7fe2fbc8 73 let p = project()
2f7b5225
EH
74 .file("Cargo.toml", &basic_lib_manifest("foo"))
75 .file("src/lib.rs", "")
76 .file(
77 ".cargo/config",
78 r#"
79 [profile.dev]
80 opt-level = 3
81 "#,
fecb7246
AC
82 )
83 .file(
2f7b5225
EH
84 paths::home().join(".cargo/config"),
85 r#"
86 [profile.dev]
87 rpath = "foo"
88 "#,
fecb7246
AC
89 )
90 .build();
2f7b5225 91
85984a87
DW
92 p.cargo("build -Z config-profile")
93 .masquerade_as_nightly_cargo()
94 .with_status(101)
95 .with_stderr(
2f7b5225 96 "\
89f43938 97[ERROR] failed to parse manifest at `[CWD]/Cargo.toml`
2f7b5225
EH
98
99Caused by:
05400b80 100 error in [..].cargo/config: `profile.dev.rpath` expected true/false, but found a string
2f7b5225 101",
fecb7246
AC
102 )
103 .run();
2f7b5225
EH
104}
105
0e0d9688 106#[cargo_test]
2f7b5225 107fn profile_config_validate_errors() {
7fe2fbc8 108 let p = project()
dda81d31 109 .file("Cargo.toml", &basic_lib_manifest("foo"))
fecb7246 110 .file("src/lib.rs", "")
2f7b5225
EH
111 .file(
112 ".cargo/config",
113 r#"
fcfe0b89 114 [profile.dev.package.foo]
2f7b5225
EH
115 panic = "abort"
116 "#,
fecb7246
AC
117 )
118 .build();
2f7b5225 119
85984a87
DW
120 p.cargo("build -Z config-profile")
121 .masquerade_as_nightly_cargo()
122 .with_status(101)
123 .with_stderr(
2f7b5225 124 "\
2b6fd6f0 125[ERROR] config profile `profile.dev` is not valid
2f7b5225
EH
126
127Caused by:
fcfe0b89 128 `panic` may not be specified in a `package` profile
2f7b5225 129",
fecb7246
AC
130 )
131 .run();
2f7b5225
EH
132}
133
0e0d9688 134#[cargo_test]
2f7b5225 135fn profile_config_syntax_errors() {
7fe2fbc8 136 let p = project()
2f7b5225
EH
137 .file("Cargo.toml", &basic_lib_manifest("foo"))
138 .file("src/lib.rs", "")
139 .file(
140 ".cargo/config",
141 r#"
142 [profile.dev]
143 codegen-units = "foo"
144 "#,
fecb7246
AC
145 )
146 .build();
2f7b5225 147
85984a87
DW
148 p.cargo("build -Z config-profile")
149 .masquerade_as_nightly_cargo()
150 .with_status(101)
151 .with_stderr(
2f7b5225
EH
152 "\
153[ERROR] failed to parse manifest at [..]
154
155Caused by:
05400b80 156 error in [..].cargo/config: `profile.dev.codegen-units` expected an integer, but found a string
2f7b5225 157",
fecb7246
AC
158 )
159 .run();
2f7b5225
EH
160}
161
0e0d9688 162#[cargo_test]
2f7b5225 163fn profile_config_override_spec_multiple() {
7fe2fbc8 164 let p = project()
2f7b5225
EH
165 .file(
166 "Cargo.toml",
167 r#"
2f7b5225
EH
168 [package]
169 name = "foo"
170 version = "0.0.1"
171
172 [dependencies]
173 bar = { path = "bar" }
174 "#,
fecb7246
AC
175 )
176 .file(
2f7b5225
EH
177 ".cargo/config",
178 r#"
fcfe0b89 179 [profile.dev.package.bar]
2f7b5225
EH
180 opt-level = 3
181
fcfe0b89 182 [profile.dev.package."bar:0.5.0"]
2f7b5225
EH
183 opt-level = 3
184 "#,
fecb7246
AC
185 )
186 .file("src/lib.rs", "")
dda81d31 187 .file("bar/Cargo.toml", &basic_lib_manifest("bar"))
fecb7246 188 .file("bar/src/lib.rs", "")
2f7b5225
EH
189 .build();
190
191 // Unfortunately this doesn't tell you which file, hopefully it's not too
192 // much of a problem.
85984a87
DW
193 p.cargo("build -v -Z config-profile")
194 .masquerade_as_nightly_cargo()
195 .with_status(101)
196 .with_stderr(
2f7b5225 197 "\
fcfe0b89
EH
198[ERROR] multiple package overrides in profile `dev` match package `bar v0.5.0 ([..])`
199found package specs: bar, bar:0.5.0",
fecb7246
AC
200 )
201 .run();
2f7b5225
EH
202}
203
0e0d9688 204#[cargo_test]
2f7b5225
EH
205fn profile_config_all_options() {
206 // Ensure all profile options are supported.
7fe2fbc8 207 let p = project()
2b6fd6f0 208 .file("src/main.rs", "fn main() {}")
2f7b5225
EH
209 .file(
210 ".cargo/config",
211 r#"
212 [profile.release]
213 opt-level = 1
214 debug = true
215 debug-assertions = true
216 overflow-checks = false
217 rpath = true
218 lto = true
219 codegen-units = 2
220 panic = "abort"
221 incremental = true
222 "#,
fecb7246
AC
223 )
224 .build();
2f7b5225 225
85984a87
DW
226 p.cargo("build --release -v -Z config-profile")
227 .masquerade_as_nightly_cargo()
2b6fd6f0 228 .env_remove("CARGO_INCREMENTAL")
85984a87 229 .with_stderr(
2f7b5225
EH
230 "\
231[COMPILING] foo [..]
232[RUNNING] `rustc --crate-name foo [..] \
233 -C opt-level=1 \
234 -C panic=abort \
2b6fd6f0 235 -C lto \
2f7b5225
EH
236 -C codegen-units=2 \
237 -C debuginfo=2 \
238 -C debug-assertions=on \
239 -C overflow-checks=off [..]\
2b6fd6f0
EH
240 -C rpath [..]\
241 -C incremental=[..]
2f7b5225
EH
242[FINISHED] release [optimized + debuginfo] [..]
243",
fecb7246
AC
244 )
245 .run();
2f7b5225
EH
246}
247
0e0d9688 248#[cargo_test]
2f7b5225
EH
249fn profile_config_override_precedence() {
250 // Config values take precedence over manifest values.
7fe2fbc8 251 let p = project()
2f7b5225
EH
252 .file(
253 "Cargo.toml",
254 r#"
2f7b5225
EH
255 [package]
256 name = "foo"
257 version = "0.0.1"
258
259 [dependencies]
260 bar = {path = "bar"}
261
262 [profile.dev]
263 codegen-units = 2
264
fcfe0b89 265 [profile.dev.package.bar]
2f7b5225
EH
266 opt-level = 3
267 "#,
fecb7246
AC
268 )
269 .file("src/lib.rs", "")
dda81d31 270 .file("bar/Cargo.toml", &basic_lib_manifest("bar"))
fecb7246 271 .file("bar/src/lib.rs", "")
2f7b5225
EH
272 .file(
273 ".cargo/config",
274 r#"
fcfe0b89 275 [profile.dev.package.bar]
2f7b5225
EH
276 opt-level = 2
277 "#,
fecb7246
AC
278 )
279 .build();
2f7b5225 280
85984a87
DW
281 p.cargo("build -v -Z config-profile")
282 .masquerade_as_nightly_cargo()
283 .with_stderr(
2f7b5225
EH
284 "\
285[COMPILING] bar [..]
286[RUNNING] `rustc --crate-name bar [..] -C opt-level=2 -C codegen-units=2 [..]
287[COMPILING] foo [..]
288[RUNNING] `rustc --crate-name foo [..]-C codegen-units=2 [..]
289[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]",
fecb7246
AC
290 )
291 .run();
2f7b5225
EH
292}
293
0e0d9688 294#[cargo_test]
2f7b5225 295fn profile_config_no_warn_unknown_override() {
7fe2fbc8 296 let p = project()
dda81d31 297 .file("Cargo.toml", &basic_lib_manifest("foo"))
fecb7246 298 .file("src/lib.rs", "")
2f7b5225
EH
299 .file(
300 ".cargo/config",
301 r#"
fcfe0b89 302 [profile.dev.package.bar]
2f7b5225
EH
303 codegen-units = 4
304 "#,
fecb7246
AC
305 )
306 .build();
2f7b5225 307
85984a87
DW
308 p.cargo("build -Z config-profile")
309 .masquerade_as_nightly_cargo()
310 .with_stderr_does_not_contain("[..]warning[..]")
311 .run();
2f7b5225
EH
312}
313
0e0d9688 314#[cargo_test]
2f7b5225 315fn profile_config_mixed_types() {
7fe2fbc8 316 let p = project()
2f7b5225
EH
317 .file("Cargo.toml", &basic_lib_manifest("foo"))
318 .file("src/lib.rs", "")
319 .file(
320 ".cargo/config",
321 r#"
322 [profile.dev]
323 opt-level = 3
324 "#,
fecb7246
AC
325 )
326 .file(
2f7b5225
EH
327 paths::home().join(".cargo/config"),
328 r#"
329 [profile.dev]
330 opt-level = 's'
331 "#,
fecb7246
AC
332 )
333 .build();
2f7b5225 334
85984a87
DW
335 p.cargo("build -v -Z config-profile")
336 .masquerade_as_nightly_cargo()
337 .with_stderr_contains("[..]-C opt-level=3 [..]")
338 .run();
2f7b5225 339}