Matthew Maurer | f4d8f81 | 2020-03-27 13:14:30 -0700 | [diff] [blame] | 1 | //! Tests for named profiles. |
| 2 | |
Chris Wailes | 54272ac | 2021-09-09 16:08:13 -0700 | [diff] [blame] | 3 | use cargo_test_support::paths::CargoPathExt; |
Chih-Hung Hsieh | 2ccedcd | 2019-12-19 15:10:50 -0800 | [diff] [blame] | 4 | use cargo_test_support::{basic_lib_manifest, project}; |
| 5 | |
| 6 | #[cargo_test] |
Chris Wailes | 54272ac | 2021-09-09 16:08:13 -0700 | [diff] [blame] | 7 | fn gated() { |
| 8 | let p = project().file("src/lib.rs", "").build(); |
| 9 | // `rustc`, `fix`, and `check` have had `--profile` before custom named profiles. |
| 10 | // Without unstable, these shouldn't be allowed to access non-legacy names. |
| 11 | for command in [ |
| 12 | "rustc", "fix", "check", "bench", "clean", "install", "test", "build", "doc", "run", |
| 13 | "rustdoc", |
| 14 | ] { |
| 15 | p.cargo(command) |
| 16 | .arg("--profile=release") |
| 17 | .with_status(101) |
| 18 | .with_stderr("error: usage of `--profile` requires `-Z unstable-options`") |
| 19 | .run(); |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | #[cargo_test] |
Chih-Hung Hsieh | 2ccedcd | 2019-12-19 15:10:50 -0800 | [diff] [blame] | 24 | fn inherits_on_release() { |
| 25 | let p = project() |
| 26 | .file( |
| 27 | "Cargo.toml", |
| 28 | r#" |
Thiébaud Weksteen | 3b664ca | 2020-11-26 14:41:59 +0100 | [diff] [blame] | 29 | cargo-features = ["named-profiles"] |
Chih-Hung Hsieh | 2ccedcd | 2019-12-19 15:10:50 -0800 | [diff] [blame] | 30 | |
Thiébaud Weksteen | 3b664ca | 2020-11-26 14:41:59 +0100 | [diff] [blame] | 31 | [package] |
| 32 | name = "foo" |
| 33 | version = "0.0.1" |
| 34 | authors = [] |
Chih-Hung Hsieh | 2ccedcd | 2019-12-19 15:10:50 -0800 | [diff] [blame] | 35 | |
Thiébaud Weksteen | 3b664ca | 2020-11-26 14:41:59 +0100 | [diff] [blame] | 36 | [profile.release] |
| 37 | inherits = "dev" |
| 38 | "#, |
Chih-Hung Hsieh | 2ccedcd | 2019-12-19 15:10:50 -0800 | [diff] [blame] | 39 | ) |
| 40 | .file("src/lib.rs", "") |
| 41 | .build(); |
| 42 | |
| 43 | p.cargo("build") |
| 44 | .masquerade_as_nightly_cargo() |
| 45 | .with_status(101) |
| 46 | .with_stderr( |
| 47 | "\ |
Matthew Maurer | 859223d | 2020-03-27 12:47:38 -0700 | [diff] [blame] | 48 | [ERROR] `inherits` must not be specified in root profile `release` |
Chih-Hung Hsieh | 2ccedcd | 2019-12-19 15:10:50 -0800 | [diff] [blame] | 49 | ", |
| 50 | ) |
| 51 | .run(); |
| 52 | } |
| 53 | |
| 54 | #[cargo_test] |
| 55 | fn missing_inherits() { |
| 56 | let p = project() |
| 57 | .file( |
| 58 | "Cargo.toml", |
| 59 | r#" |
Thiébaud Weksteen | 3b664ca | 2020-11-26 14:41:59 +0100 | [diff] [blame] | 60 | cargo-features = ["named-profiles"] |
Chih-Hung Hsieh | 2ccedcd | 2019-12-19 15:10:50 -0800 | [diff] [blame] | 61 | |
Thiébaud Weksteen | 3b664ca | 2020-11-26 14:41:59 +0100 | [diff] [blame] | 62 | [package] |
| 63 | name = "foo" |
| 64 | version = "0.0.1" |
| 65 | authors = [] |
Chih-Hung Hsieh | 2ccedcd | 2019-12-19 15:10:50 -0800 | [diff] [blame] | 66 | |
Thiébaud Weksteen | 3b664ca | 2020-11-26 14:41:59 +0100 | [diff] [blame] | 67 | [profile.release-lto] |
| 68 | codegen-units = 7 |
| 69 | "#, |
Chih-Hung Hsieh | 2ccedcd | 2019-12-19 15:10:50 -0800 | [diff] [blame] | 70 | ) |
| 71 | .file("src/lib.rs", "") |
| 72 | .build(); |
| 73 | |
| 74 | p.cargo("build") |
| 75 | .masquerade_as_nightly_cargo() |
| 76 | .with_status(101) |
| 77 | .with_stderr( |
| 78 | "\ |
Matthew Maurer | 859223d | 2020-03-27 12:47:38 -0700 | [diff] [blame] | 79 | [ERROR] profile `release-lto` is missing an `inherits` directive \ |
| 80 | (`inherits` is required for all profiles except `dev` or `release`) |
| 81 | ", |
Chih-Hung Hsieh | 2ccedcd | 2019-12-19 15:10:50 -0800 | [diff] [blame] | 82 | ) |
| 83 | .run(); |
| 84 | } |
| 85 | |
| 86 | #[cargo_test] |
| 87 | fn invalid_profile_name() { |
| 88 | let p = project() |
| 89 | .file( |
| 90 | "Cargo.toml", |
| 91 | r#" |
Thiébaud Weksteen | 3b664ca | 2020-11-26 14:41:59 +0100 | [diff] [blame] | 92 | cargo-features = ["named-profiles"] |
Chih-Hung Hsieh | 2ccedcd | 2019-12-19 15:10:50 -0800 | [diff] [blame] | 93 | |
Thiébaud Weksteen | 3b664ca | 2020-11-26 14:41:59 +0100 | [diff] [blame] | 94 | [package] |
| 95 | name = "foo" |
| 96 | version = "0.0.1" |
| 97 | authors = [] |
Chih-Hung Hsieh | 2ccedcd | 2019-12-19 15:10:50 -0800 | [diff] [blame] | 98 | |
Thiébaud Weksteen | 3b664ca | 2020-11-26 14:41:59 +0100 | [diff] [blame] | 99 | [profile.'.release-lto'] |
| 100 | inherits = "release" |
| 101 | codegen-units = 7 |
| 102 | "#, |
Chih-Hung Hsieh | 2ccedcd | 2019-12-19 15:10:50 -0800 | [diff] [blame] | 103 | ) |
| 104 | .file("src/lib.rs", "") |
| 105 | .build(); |
| 106 | |
| 107 | p.cargo("build") |
| 108 | .masquerade_as_nightly_cargo() |
| 109 | .with_status(101) |
| 110 | .with_stderr( |
| 111 | "\ |
| 112 | [ERROR] failed to parse manifest at [..] |
| 113 | |
| 114 | Caused by: |
Chris Wailes | 54272ac | 2021-09-09 16:08:13 -0700 | [diff] [blame] | 115 | invalid character `.` in profile name `.release-lto` |
| 116 | Allowed characters are letters, numbers, underscore, and hyphen. |
| 117 | ", |
Chih-Hung Hsieh | 2ccedcd | 2019-12-19 15:10:50 -0800 | [diff] [blame] | 118 | ) |
| 119 | .run(); |
| 120 | } |
| 121 | |
| 122 | #[cargo_test] |
Chris Wailes | 54272ac | 2021-09-09 16:08:13 -0700 | [diff] [blame] | 123 | #[ignore] // dir-name is currently disabled |
Chih-Hung Hsieh | 2ccedcd | 2019-12-19 15:10:50 -0800 | [diff] [blame] | 124 | fn invalid_dir_name() { |
| 125 | let p = project() |
| 126 | .file( |
| 127 | "Cargo.toml", |
| 128 | r#" |
Thiébaud Weksteen | 3b664ca | 2020-11-26 14:41:59 +0100 | [diff] [blame] | 129 | cargo-features = ["named-profiles"] |
Chih-Hung Hsieh | 2ccedcd | 2019-12-19 15:10:50 -0800 | [diff] [blame] | 130 | |
Thiébaud Weksteen | 3b664ca | 2020-11-26 14:41:59 +0100 | [diff] [blame] | 131 | [package] |
| 132 | name = "foo" |
| 133 | version = "0.0.1" |
| 134 | authors = [] |
Chih-Hung Hsieh | 2ccedcd | 2019-12-19 15:10:50 -0800 | [diff] [blame] | 135 | |
Thiébaud Weksteen | 3b664ca | 2020-11-26 14:41:59 +0100 | [diff] [blame] | 136 | [profile.'release-lto'] |
| 137 | inherits = "release" |
| 138 | dir-name = ".subdir" |
| 139 | codegen-units = 7 |
| 140 | "#, |
Chih-Hung Hsieh | 2ccedcd | 2019-12-19 15:10:50 -0800 | [diff] [blame] | 141 | ) |
| 142 | .file("src/lib.rs", "") |
| 143 | .build(); |
| 144 | |
| 145 | p.cargo("build") |
| 146 | .masquerade_as_nightly_cargo() |
| 147 | .with_status(101) |
| 148 | .with_stderr( |
| 149 | "\ |
| 150 | [ERROR] failed to parse manifest at [..] |
| 151 | |
| 152 | Caused by: |
| 153 | Invalid character `.` in dir-name: `.subdir`", |
| 154 | ) |
| 155 | .run(); |
| 156 | } |
| 157 | |
| 158 | #[cargo_test] |
Chris Wailes | 54272ac | 2021-09-09 16:08:13 -0700 | [diff] [blame] | 159 | fn dir_name_disabled() { |
| 160 | let p = project() |
| 161 | .file( |
| 162 | "Cargo.toml", |
| 163 | r#" |
| 164 | cargo-features = ["named-profiles"] |
| 165 | |
| 166 | [package] |
| 167 | name = "foo" |
| 168 | version = "0.1.0" |
| 169 | |
| 170 | [profile.release-lto] |
| 171 | inherits = "release" |
| 172 | dir-name = "lto" |
| 173 | lto = true |
| 174 | "#, |
| 175 | ) |
| 176 | .file("src/lib.rs", "") |
| 177 | .build(); |
| 178 | |
| 179 | p.cargo("build") |
| 180 | .masquerade_as_nightly_cargo() |
| 181 | .with_status(101) |
| 182 | .with_stderr( |
| 183 | "\ |
| 184 | error: failed to parse manifest at `[ROOT]/foo/Cargo.toml` |
| 185 | |
| 186 | Caused by: |
| 187 | dir-name=\"lto\" in profile `release-lto` is not currently allowed, \ |
| 188 | directory names are tied to the profile name for custom profiles |
| 189 | ", |
| 190 | ) |
| 191 | .run(); |
| 192 | } |
| 193 | |
| 194 | #[cargo_test] |
Chih-Hung Hsieh | 2ccedcd | 2019-12-19 15:10:50 -0800 | [diff] [blame] | 195 | fn invalid_inherits() { |
| 196 | let p = project() |
| 197 | .file( |
| 198 | "Cargo.toml", |
| 199 | r#" |
Thiébaud Weksteen | 3b664ca | 2020-11-26 14:41:59 +0100 | [diff] [blame] | 200 | cargo-features = ["named-profiles"] |
Chih-Hung Hsieh | 2ccedcd | 2019-12-19 15:10:50 -0800 | [diff] [blame] | 201 | |
Thiébaud Weksteen | 3b664ca | 2020-11-26 14:41:59 +0100 | [diff] [blame] | 202 | [package] |
| 203 | name = "foo" |
| 204 | version = "0.0.1" |
| 205 | authors = [] |
Chih-Hung Hsieh | 2ccedcd | 2019-12-19 15:10:50 -0800 | [diff] [blame] | 206 | |
Thiébaud Weksteen | 3b664ca | 2020-11-26 14:41:59 +0100 | [diff] [blame] | 207 | [profile.'release-lto'] |
| 208 | inherits = ".release" |
| 209 | codegen-units = 7 |
| 210 | "#, |
Chih-Hung Hsieh | 2ccedcd | 2019-12-19 15:10:50 -0800 | [diff] [blame] | 211 | ) |
| 212 | .file("src/lib.rs", "") |
| 213 | .build(); |
| 214 | |
| 215 | p.cargo("build") |
| 216 | .masquerade_as_nightly_cargo() |
| 217 | .with_status(101) |
| 218 | .with_stderr( |
Chris Wailes | 54272ac | 2021-09-09 16:08:13 -0700 | [diff] [blame] | 219 | "error: profile `release-lto` inherits from `.release`, \ |
| 220 | but that profile is not defined", |
Chih-Hung Hsieh | 2ccedcd | 2019-12-19 15:10:50 -0800 | [diff] [blame] | 221 | ) |
| 222 | .run(); |
| 223 | } |
| 224 | |
| 225 | #[cargo_test] |
| 226 | fn non_existent_inherits() { |
| 227 | let p = project() |
| 228 | .file( |
| 229 | "Cargo.toml", |
| 230 | r#" |
Thiébaud Weksteen | 3b664ca | 2020-11-26 14:41:59 +0100 | [diff] [blame] | 231 | cargo-features = ["named-profiles"] |
Chih-Hung Hsieh | 2ccedcd | 2019-12-19 15:10:50 -0800 | [diff] [blame] | 232 | |
Thiébaud Weksteen | 3b664ca | 2020-11-26 14:41:59 +0100 | [diff] [blame] | 233 | [package] |
| 234 | name = "foo" |
| 235 | version = "0.0.1" |
| 236 | authors = [] |
Chih-Hung Hsieh | 2ccedcd | 2019-12-19 15:10:50 -0800 | [diff] [blame] | 237 | |
Thiébaud Weksteen | 3b664ca | 2020-11-26 14:41:59 +0100 | [diff] [blame] | 238 | [profile.release-lto] |
| 239 | codegen-units = 7 |
| 240 | inherits = "non-existent" |
| 241 | "#, |
Chih-Hung Hsieh | 2ccedcd | 2019-12-19 15:10:50 -0800 | [diff] [blame] | 242 | ) |
| 243 | .file("src/lib.rs", "") |
| 244 | .build(); |
| 245 | |
| 246 | p.cargo("build") |
| 247 | .masquerade_as_nightly_cargo() |
| 248 | .with_status(101) |
| 249 | .with_stderr( |
| 250 | "\ |
Matthew Maurer | 859223d | 2020-03-27 12:47:38 -0700 | [diff] [blame] | 251 | [ERROR] profile `release-lto` inherits from `non-existent`, but that profile is not defined |
| 252 | ", |
Chih-Hung Hsieh | 2ccedcd | 2019-12-19 15:10:50 -0800 | [diff] [blame] | 253 | ) |
| 254 | .run(); |
| 255 | } |
| 256 | |
| 257 | #[cargo_test] |
| 258 | fn self_inherits() { |
| 259 | let p = project() |
| 260 | .file( |
| 261 | "Cargo.toml", |
| 262 | r#" |
Thiébaud Weksteen | 3b664ca | 2020-11-26 14:41:59 +0100 | [diff] [blame] | 263 | cargo-features = ["named-profiles"] |
Chih-Hung Hsieh | 2ccedcd | 2019-12-19 15:10:50 -0800 | [diff] [blame] | 264 | |
Thiébaud Weksteen | 3b664ca | 2020-11-26 14:41:59 +0100 | [diff] [blame] | 265 | [package] |
| 266 | name = "foo" |
| 267 | version = "0.0.1" |
| 268 | authors = [] |
Chih-Hung Hsieh | 2ccedcd | 2019-12-19 15:10:50 -0800 | [diff] [blame] | 269 | |
Thiébaud Weksteen | 3b664ca | 2020-11-26 14:41:59 +0100 | [diff] [blame] | 270 | [profile.release-lto] |
| 271 | codegen-units = 7 |
| 272 | inherits = "release-lto" |
| 273 | "#, |
Chih-Hung Hsieh | 2ccedcd | 2019-12-19 15:10:50 -0800 | [diff] [blame] | 274 | ) |
| 275 | .file("src/lib.rs", "") |
| 276 | .build(); |
| 277 | |
| 278 | p.cargo("build") |
| 279 | .masquerade_as_nightly_cargo() |
| 280 | .with_status(101) |
| 281 | .with_stderr( |
| 282 | "\ |
Matthew Maurer | 859223d | 2020-03-27 12:47:38 -0700 | [diff] [blame] | 283 | [ERROR] profile inheritance loop detected with profile `release-lto` inheriting `release-lto` |
| 284 | ", |
Chih-Hung Hsieh | 2ccedcd | 2019-12-19 15:10:50 -0800 | [diff] [blame] | 285 | ) |
| 286 | .run(); |
| 287 | } |
| 288 | |
| 289 | #[cargo_test] |
| 290 | fn inherits_loop() { |
| 291 | let p = project() |
| 292 | .file( |
| 293 | "Cargo.toml", |
| 294 | r#" |
Thiébaud Weksteen | 3b664ca | 2020-11-26 14:41:59 +0100 | [diff] [blame] | 295 | cargo-features = ["named-profiles"] |
Chih-Hung Hsieh | 2ccedcd | 2019-12-19 15:10:50 -0800 | [diff] [blame] | 296 | |
Thiébaud Weksteen | 3b664ca | 2020-11-26 14:41:59 +0100 | [diff] [blame] | 297 | [package] |
| 298 | name = "foo" |
| 299 | version = "0.0.1" |
| 300 | authors = [] |
Chih-Hung Hsieh | 2ccedcd | 2019-12-19 15:10:50 -0800 | [diff] [blame] | 301 | |
Thiébaud Weksteen | 3b664ca | 2020-11-26 14:41:59 +0100 | [diff] [blame] | 302 | [profile.release-lto] |
| 303 | codegen-units = 7 |
| 304 | inherits = "release-lto2" |
Chih-Hung Hsieh | 2ccedcd | 2019-12-19 15:10:50 -0800 | [diff] [blame] | 305 | |
Thiébaud Weksteen | 3b664ca | 2020-11-26 14:41:59 +0100 | [diff] [blame] | 306 | [profile.release-lto2] |
| 307 | codegen-units = 7 |
| 308 | inherits = "release-lto" |
| 309 | "#, |
Chih-Hung Hsieh | 2ccedcd | 2019-12-19 15:10:50 -0800 | [diff] [blame] | 310 | ) |
| 311 | .file("src/lib.rs", "") |
| 312 | .build(); |
| 313 | |
| 314 | p.cargo("build") |
| 315 | .masquerade_as_nightly_cargo() |
| 316 | .with_status(101) |
| 317 | .with_stderr( |
| 318 | "\ |
Matthew Maurer | 859223d | 2020-03-27 12:47:38 -0700 | [diff] [blame] | 319 | [ERROR] profile inheritance loop detected with profile `release-lto2` inheriting `release-lto` |
| 320 | ", |
Chih-Hung Hsieh | 2ccedcd | 2019-12-19 15:10:50 -0800 | [diff] [blame] | 321 | ) |
| 322 | .run(); |
| 323 | } |
| 324 | |
| 325 | #[cargo_test] |
| 326 | fn overrides_with_custom() { |
| 327 | let p = project() |
| 328 | .file( |
| 329 | "Cargo.toml", |
| 330 | r#" |
Thiébaud Weksteen | 3b664ca | 2020-11-26 14:41:59 +0100 | [diff] [blame] | 331 | cargo-features = ["named-profiles"] |
Chih-Hung Hsieh | 2ccedcd | 2019-12-19 15:10:50 -0800 | [diff] [blame] | 332 | |
Thiébaud Weksteen | 3b664ca | 2020-11-26 14:41:59 +0100 | [diff] [blame] | 333 | [package] |
| 334 | name = "foo" |
| 335 | version = "0.0.1" |
| 336 | authors = [] |
Chih-Hung Hsieh | 2ccedcd | 2019-12-19 15:10:50 -0800 | [diff] [blame] | 337 | |
Thiébaud Weksteen | 3b664ca | 2020-11-26 14:41:59 +0100 | [diff] [blame] | 338 | [dependencies] |
| 339 | xxx = {path = "xxx"} |
| 340 | yyy = {path = "yyy"} |
Chih-Hung Hsieh | 2ccedcd | 2019-12-19 15:10:50 -0800 | [diff] [blame] | 341 | |
Thiébaud Weksteen | 3b664ca | 2020-11-26 14:41:59 +0100 | [diff] [blame] | 342 | [profile.dev] |
| 343 | codegen-units = 7 |
Chih-Hung Hsieh | 2ccedcd | 2019-12-19 15:10:50 -0800 | [diff] [blame] | 344 | |
Thiébaud Weksteen | 3b664ca | 2020-11-26 14:41:59 +0100 | [diff] [blame] | 345 | [profile.dev.package.xxx] |
| 346 | codegen-units = 5 |
| 347 | [profile.dev.package.yyy] |
| 348 | codegen-units = 3 |
Chih-Hung Hsieh | 2ccedcd | 2019-12-19 15:10:50 -0800 | [diff] [blame] | 349 | |
Thiébaud Weksteen | 3b664ca | 2020-11-26 14:41:59 +0100 | [diff] [blame] | 350 | [profile.other] |
| 351 | inherits = "dev" |
| 352 | codegen-units = 2 |
Chih-Hung Hsieh | 2ccedcd | 2019-12-19 15:10:50 -0800 | [diff] [blame] | 353 | |
Thiébaud Weksteen | 3b664ca | 2020-11-26 14:41:59 +0100 | [diff] [blame] | 354 | [profile.other.package.yyy] |
| 355 | codegen-units = 6 |
| 356 | "#, |
Chih-Hung Hsieh | 2ccedcd | 2019-12-19 15:10:50 -0800 | [diff] [blame] | 357 | ) |
| 358 | .file("src/lib.rs", "") |
| 359 | .file("xxx/Cargo.toml", &basic_lib_manifest("xxx")) |
| 360 | .file("xxx/src/lib.rs", "") |
| 361 | .file("yyy/Cargo.toml", &basic_lib_manifest("yyy")) |
| 362 | .file("yyy/src/lib.rs", "") |
| 363 | .build(); |
| 364 | |
| 365 | // profile overrides are inherited between profiles using inherits and have a |
| 366 | // higher priority than profile options provided by custom profiles |
| 367 | p.cargo("build -v") |
| 368 | .masquerade_as_nightly_cargo() |
| 369 | .with_stderr_unordered( |
| 370 | "\ |
| 371 | [COMPILING] xxx [..] |
| 372 | [COMPILING] yyy [..] |
| 373 | [COMPILING] foo [..] |
| 374 | [RUNNING] `rustc --crate-name xxx [..] -C codegen-units=5 [..]` |
| 375 | [RUNNING] `rustc --crate-name yyy [..] -C codegen-units=3 [..]` |
| 376 | [RUNNING] `rustc --crate-name foo [..] -C codegen-units=7 [..]` |
| 377 | [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] |
| 378 | ", |
| 379 | ) |
| 380 | .run(); |
| 381 | |
| 382 | // This also verifies that the custom profile names appears in the finished line. |
| 383 | p.cargo("build --profile=other -Z unstable-options -v") |
| 384 | .masquerade_as_nightly_cargo() |
| 385 | .with_stderr_unordered( |
| 386 | "\ |
| 387 | [COMPILING] xxx [..] |
| 388 | [COMPILING] yyy [..] |
| 389 | [COMPILING] foo [..] |
| 390 | [RUNNING] `rustc --crate-name xxx [..] -C codegen-units=5 [..]` |
| 391 | [RUNNING] `rustc --crate-name yyy [..] -C codegen-units=6 [..]` |
| 392 | [RUNNING] `rustc --crate-name foo [..] -C codegen-units=2 [..]` |
| 393 | [FINISHED] other [unoptimized + debuginfo] target(s) in [..] |
| 394 | ", |
| 395 | ) |
| 396 | .run(); |
| 397 | } |
| 398 | |
| 399 | #[cargo_test] |
| 400 | fn conflicting_usage() { |
| 401 | let p = project() |
| 402 | .file( |
| 403 | "Cargo.toml", |
| 404 | r#" |
Thiébaud Weksteen | 3b664ca | 2020-11-26 14:41:59 +0100 | [diff] [blame] | 405 | [package] |
| 406 | name = "foo" |
| 407 | version = "0.0.1" |
| 408 | authors = [] |
| 409 | "#, |
Chih-Hung Hsieh | 2ccedcd | 2019-12-19 15:10:50 -0800 | [diff] [blame] | 410 | ) |
| 411 | .file("src/lib.rs", "") |
| 412 | .build(); |
| 413 | |
| 414 | p.cargo("build -Z unstable-options --profile=dev --release") |
| 415 | .masquerade_as_nightly_cargo() |
| 416 | .with_status(101) |
Chris Wailes | 54272ac | 2021-09-09 16:08:13 -0700 | [diff] [blame] | 417 | .with_stderr( |
| 418 | "\ |
| 419 | error: conflicting usage of --profile=dev and --release |
| 420 | The `--release` flag is the same as `--profile=release`. |
| 421 | Remove one flag or the other to continue. |
| 422 | ", |
| 423 | ) |
Chih-Hung Hsieh | 2ccedcd | 2019-12-19 15:10:50 -0800 | [diff] [blame] | 424 | .run(); |
| 425 | |
| 426 | p.cargo("install -Z unstable-options --profile=release --debug") |
| 427 | .masquerade_as_nightly_cargo() |
| 428 | .with_status(101) |
Chris Wailes | 54272ac | 2021-09-09 16:08:13 -0700 | [diff] [blame] | 429 | .with_stderr( |
| 430 | "\ |
| 431 | error: conflicting usage of --profile=release and --debug |
| 432 | The `--debug` flag is the same as `--profile=dev`. |
| 433 | Remove one flag or the other to continue. |
| 434 | ", |
| 435 | ) |
Chih-Hung Hsieh | 2ccedcd | 2019-12-19 15:10:50 -0800 | [diff] [blame] | 436 | .run(); |
| 437 | } |
| 438 | |
| 439 | #[cargo_test] |
| 440 | fn clean_custom_dirname() { |
| 441 | let p = project() |
| 442 | .file( |
| 443 | "Cargo.toml", |
| 444 | r#" |
Thiébaud Weksteen | 3b664ca | 2020-11-26 14:41:59 +0100 | [diff] [blame] | 445 | cargo-features = ["named-profiles"] |
Chih-Hung Hsieh | 2ccedcd | 2019-12-19 15:10:50 -0800 | [diff] [blame] | 446 | |
Thiébaud Weksteen | 3b664ca | 2020-11-26 14:41:59 +0100 | [diff] [blame] | 447 | [package] |
| 448 | name = "foo" |
| 449 | version = "0.0.1" |
| 450 | authors = [] |
Chih-Hung Hsieh | 2ccedcd | 2019-12-19 15:10:50 -0800 | [diff] [blame] | 451 | |
Thiébaud Weksteen | 3b664ca | 2020-11-26 14:41:59 +0100 | [diff] [blame] | 452 | [profile.other] |
| 453 | inherits = "release" |
| 454 | "#, |
Chih-Hung Hsieh | 2ccedcd | 2019-12-19 15:10:50 -0800 | [diff] [blame] | 455 | ) |
| 456 | .file("src/main.rs", "fn main() {}") |
| 457 | .build(); |
| 458 | |
| 459 | p.cargo("build --release") |
| 460 | .masquerade_as_nightly_cargo() |
| 461 | .with_stdout("") |
| 462 | .with_stderr( |
| 463 | "\ |
| 464 | [COMPILING] foo v0.0.1 ([..]) |
| 465 | [FINISHED] release [optimized] target(s) in [..] |
| 466 | ", |
| 467 | ) |
| 468 | .run(); |
| 469 | |
| 470 | p.cargo("clean -p foo").masquerade_as_nightly_cargo().run(); |
| 471 | |
| 472 | p.cargo("build --release") |
| 473 | .masquerade_as_nightly_cargo() |
| 474 | .with_stdout("") |
| 475 | .with_stderr( |
| 476 | "\ |
| 477 | [FINISHED] release [optimized] target(s) in [..] |
| 478 | ", |
| 479 | ) |
| 480 | .run(); |
| 481 | |
| 482 | p.cargo("clean -p foo --release") |
| 483 | .masquerade_as_nightly_cargo() |
| 484 | .run(); |
| 485 | |
| 486 | p.cargo("build --release") |
| 487 | .masquerade_as_nightly_cargo() |
| 488 | .with_stderr( |
| 489 | "\ |
| 490 | [COMPILING] foo v0.0.1 ([..]) |
| 491 | [FINISHED] release [optimized] target(s) in [..] |
| 492 | ", |
| 493 | ) |
| 494 | .run(); |
| 495 | |
| 496 | p.cargo("build") |
| 497 | .masquerade_as_nightly_cargo() |
| 498 | .with_stdout("") |
| 499 | .with_stderr( |
| 500 | "\ |
| 501 | [COMPILING] foo v0.0.1 ([..]) |
| 502 | [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] |
| 503 | ", |
| 504 | ) |
| 505 | .run(); |
| 506 | |
| 507 | p.cargo("build -Z unstable-options --profile=other") |
| 508 | .masquerade_as_nightly_cargo() |
| 509 | .with_stderr( |
| 510 | "\ |
| 511 | [COMPILING] foo v0.0.1 ([..]) |
| 512 | [FINISHED] other [optimized] target(s) in [..] |
| 513 | ", |
| 514 | ) |
| 515 | .run(); |
| 516 | |
| 517 | p.cargo("clean") |
| 518 | .arg("--release") |
| 519 | .masquerade_as_nightly_cargo() |
| 520 | .run(); |
| 521 | |
| 522 | // Make sure that 'other' was not cleaned |
| 523 | assert!(p.build_dir().is_dir()); |
| 524 | assert!(p.build_dir().join("debug").is_dir()); |
| 525 | assert!(p.build_dir().join("other").is_dir()); |
| 526 | assert!(!p.build_dir().join("release").is_dir()); |
| 527 | |
| 528 | // This should clean 'other' |
| 529 | p.cargo("clean -Z unstable-options --profile=other") |
| 530 | .masquerade_as_nightly_cargo() |
| 531 | .with_stderr("") |
| 532 | .run(); |
| 533 | assert!(p.build_dir().join("debug").is_dir()); |
| 534 | assert!(!p.build_dir().join("other").is_dir()); |
| 535 | } |
Matthew Maurer | 859223d | 2020-03-27 12:47:38 -0700 | [diff] [blame] | 536 | |
| 537 | #[cargo_test] |
| 538 | fn unknown_profile() { |
| 539 | let p = project() |
| 540 | .file( |
| 541 | "Cargo.toml", |
| 542 | r#" |
| 543 | cargo-features = ["named-profiles"] |
| 544 | |
| 545 | [package] |
| 546 | name = "foo" |
| 547 | version = "0.0.1" |
| 548 | "#, |
| 549 | ) |
| 550 | .file("src/lib.rs", "") |
| 551 | .build(); |
| 552 | |
| 553 | p.cargo("build --profile alpha -Zunstable-options") |
| 554 | .masquerade_as_nightly_cargo() |
| 555 | .with_stderr("[ERROR] profile `alpha` is not defined") |
| 556 | .with_status(101) |
| 557 | .run(); |
| 558 | // Clean has a separate code path, need to check it too. |
| 559 | p.cargo("clean --profile alpha -Zunstable-options") |
| 560 | .masquerade_as_nightly_cargo() |
| 561 | .with_stderr("[ERROR] profile `alpha` is not defined") |
| 562 | .with_status(101) |
| 563 | .run(); |
| 564 | } |
Chris Wailes | 54272ac | 2021-09-09 16:08:13 -0700 | [diff] [blame] | 565 | |
| 566 | #[cargo_test] |
| 567 | fn reserved_profile_names() { |
| 568 | let p = project() |
| 569 | .file( |
| 570 | "Cargo.toml", |
| 571 | r#" |
| 572 | [package] |
| 573 | name = "foo" |
| 574 | version = "0.1.0" |
| 575 | |
| 576 | [profile.doc] |
| 577 | opt-level = 1 |
| 578 | "#, |
| 579 | ) |
| 580 | .file("src/lib.rs", "") |
| 581 | .build(); |
| 582 | |
| 583 | p.cargo("build --profile=doc -Zunstable-options") |
| 584 | .masquerade_as_nightly_cargo() |
| 585 | .with_status(101) |
| 586 | .with_stderr("error: profile `doc` is reserved and not allowed to be explicitly specified") |
| 587 | .run(); |
| 588 | // Not an exhaustive list, just a sample. |
| 589 | for name in ["build", "cargo", "check", "rustc", "CaRgO_startswith"] { |
| 590 | p.cargo(&format!("build --profile={} -Zunstable-options", name)) |
| 591 | .masquerade_as_nightly_cargo() |
| 592 | .with_status(101) |
| 593 | .with_stderr(&format!( |
| 594 | "\ |
| 595 | error: profile name `{}` is reserved |
| 596 | Please choose a different name. |
| 597 | See https://doc.rust-lang.org/cargo/reference/profiles.html for more on configuring profiles. |
| 598 | ", |
| 599 | name |
| 600 | )) |
| 601 | .run(); |
| 602 | } |
| 603 | for name in ["build", "check", "cargo", "rustc", "CaRgO_startswith"] { |
| 604 | p.change_file( |
| 605 | "Cargo.toml", |
| 606 | &format!( |
| 607 | r#" |
| 608 | cargo-features = ["named-profiles"] |
| 609 | |
| 610 | [package] |
| 611 | name = "foo" |
| 612 | version = "0.1.0" |
| 613 | |
| 614 | [profile.{}] |
| 615 | opt-level = 1 |
| 616 | "#, |
| 617 | name |
| 618 | ), |
| 619 | ); |
| 620 | |
| 621 | p.cargo("build") |
| 622 | .masquerade_as_nightly_cargo() |
| 623 | .with_status(101) |
| 624 | .with_stderr(&format!( |
| 625 | "\ |
| 626 | error: failed to parse manifest at `[ROOT]/foo/Cargo.toml` |
| 627 | |
| 628 | Caused by: |
| 629 | profile name `{}` is reserved |
| 630 | Please choose a different name. |
| 631 | See https://doc.rust-lang.org/cargo/reference/profiles.html for more on configuring profiles. |
| 632 | ", |
| 633 | name |
| 634 | )) |
| 635 | .run(); |
| 636 | } |
| 637 | |
| 638 | p.change_file( |
| 639 | "Cargo.toml", |
| 640 | r#" |
| 641 | cargo-features = ["named-profiles"] |
| 642 | |
| 643 | [package] |
| 644 | name = "foo" |
| 645 | version = "0.1.0" |
| 646 | authors = [] |
| 647 | |
| 648 | [profile.debug] |
| 649 | debug = 1 |
| 650 | inherits = "dev" |
| 651 | "#, |
| 652 | ); |
| 653 | |
| 654 | p.cargo("build") |
| 655 | .masquerade_as_nightly_cargo() |
| 656 | .with_status(101) |
| 657 | .with_stderr( |
| 658 | "\ |
| 659 | error: failed to parse manifest at `[ROOT]/foo/Cargo.toml` |
| 660 | |
| 661 | Caused by: |
| 662 | profile name `debug` is reserved |
| 663 | To configure the default development profile, use the name `dev` as in [profile.dev] |
| 664 | See https://doc.rust-lang.org/cargo/reference/profiles.html for more on configuring profiles. |
| 665 | ", |
| 666 | ) |
| 667 | .run(); |
| 668 | } |
| 669 | |
| 670 | #[cargo_test] |
| 671 | fn legacy_commands_support_custom() { |
| 672 | // These commands have had `--profile` before custom named profiles. |
| 673 | let p = project() |
| 674 | .file( |
| 675 | "Cargo.toml", |
| 676 | r#" |
| 677 | cargo-features = ["named-profiles"] |
| 678 | |
| 679 | [package] |
| 680 | name = "foo" |
| 681 | version = "0.1.0" |
| 682 | |
| 683 | [profile.super-dev] |
| 684 | codegen-units = 3 |
| 685 | inherits = "dev" |
| 686 | "#, |
| 687 | ) |
| 688 | .file("src/lib.rs", "") |
| 689 | .build(); |
| 690 | |
| 691 | for command in ["rustc", "fix", "check"] { |
| 692 | let mut pb = p.cargo(command); |
| 693 | if command == "fix" { |
| 694 | pb.arg("--allow-no-vcs"); |
| 695 | } |
| 696 | pb.arg("--profile=super-dev") |
| 697 | .arg("-Zunstable-options") |
| 698 | .arg("-v") |
| 699 | .masquerade_as_nightly_cargo() |
| 700 | .with_stderr_contains("[RUNNING] [..]codegen-units=3[..]") |
| 701 | .run(); |
| 702 | p.build_dir().rm_rf(); |
| 703 | } |
| 704 | } |
Chris Wailes | bcf972c | 2021-10-21 11:03:28 -0700 | [diff] [blame^] | 705 | |
| 706 | #[cargo_test] |
| 707 | fn legacy_rustc() { |
| 708 | // `cargo rustc` historically has supported dev/test/bench/check |
| 709 | // other profiles are covered in check::rustc_check |
| 710 | let p = project() |
| 711 | .file( |
| 712 | "Cargo.toml", |
| 713 | r#" |
| 714 | [package] |
| 715 | name = "foo" |
| 716 | version = "0.1.0" |
| 717 | |
| 718 | [profile.dev] |
| 719 | codegen-units = 3 |
| 720 | "#, |
| 721 | ) |
| 722 | .file("src/lib.rs", "") |
| 723 | .build(); |
| 724 | p.cargo("rustc --profile dev -v") |
| 725 | .with_stderr( |
| 726 | "\ |
| 727 | [COMPILING] foo v0.1.0 [..] |
| 728 | [RUNNING] `rustc --crate-name foo [..]-C codegen-units=3[..] |
| 729 | [FINISHED] [..] |
| 730 | ", |
| 731 | ) |
| 732 | .run(); |
| 733 | } |