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