Skip to content

Commit

Permalink
Auto merge of #14128 - eth3lbert:snapbox-profile, r=weihanglo
Browse files Browse the repository at this point in the history
test: migrate profile* to snapbox

### What does this PR try to resolve?

Part of #14039.

Migrate following to snapbox:

- `tests/testsuite/profile_config.rs`
- `tests/testsuite/profile_custom.rs`
- `tests/testsuite/profile_overrides.rs`
- `tests/testsuite/profile_targets.rs`
- `tests/testsuite/profile_trim_paths.rs`
- `tests/testsuite/profiles.rs`
  • Loading branch information
bors committed Jun 23, 2024
2 parents 9a7a603 + 1559840 commit e18afe2
Show file tree
Hide file tree
Showing 6 changed files with 853 additions and 824 deletions.
174 changes: 86 additions & 88 deletions tests/testsuite/profile_config.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
//! Tests for profiles defined in config files.
#![allow(deprecated)]

use cargo_test_support::paths::CargoPathExt;
use cargo_test_support::prelude::*;
use cargo_test_support::registry::Package;
use cargo_test_support::{basic_lib_manifest, paths, project};
use cargo_test_support::{basic_lib_manifest, paths, project, str};
use cargo_util_schemas::manifest::TomlDebugInfo;

// TODO: this should be remove once -Zprofile-rustflags is stabilized
Expand Down Expand Up @@ -33,18 +32,23 @@ fn rustflags_works_with_zflag() {
p.cargo("check -v")
.masquerade_as_nightly_cargo(&["profile-rustflags"])
.with_status(101)
.with_stderr_contains("[..]feature `profile-rustflags` is required[..]")
.with_stderr_data(str![[r#"
[ERROR] config profile `dev` is not valid (defined in `[ROOT]/foo/.cargo/config.toml`)
Caused by:
feature `profile-rustflags` is required
...
"#]])
.run();

p.cargo("check -v -Zprofile-rustflags")
.masquerade_as_nightly_cargo(&["profile-rustflags"])
.with_stderr(
"\
[CHECKING] foo [..]
[RUNNING] `rustc --crate-name foo [..] -C link-dead-code=yes [..]
[FINISHED] [..]
",
)
.with_stderr_data(str![[r#"
[CHECKING] foo v0.0.1 ([ROOT]/foo)
[RUNNING] `rustc --crate-name foo [..] -C link-dead-code=yes [..]`
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
"#]])
.run();

p.change_file(
Expand All @@ -60,12 +64,11 @@ fn rustflags_works_with_zflag() {

p.cargo("check -v")
.masquerade_as_nightly_cargo(&["profile-rustflags"])
.with_stderr(
"\
[FRESH] foo [..]
[FINISHED] [..]
",
)
.with_stderr_data(str![[r#"
[FRESH] foo v0.0.1 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
"#]])
.run();
}

Expand Down Expand Up @@ -95,17 +98,14 @@ fn profile_config_validate_warnings() {
)
.build();

p.cargo("build")
.with_stderr_unordered(
"\
[WARNING] unused config key `profile.dev.bad-key` in `[..].cargo/config.toml`
[WARNING] unused config key `profile.dev.package.bar.bad-key-bar` in `[..].cargo/config.toml`
[WARNING] unused config key `profile.dev.build-override.bad-key-bo` in `[..].cargo/config.toml`
[COMPILING] foo [..]
[FINISHED] [..]
",
)
.run();
p.cargo("build").with_stderr_data(str![[r#"
[WARNING] unused config key `profile.dev.bad-key` in `[ROOT]/foo/.cargo/config.toml`
[WARNING] unused config key `profile.dev.build-override.bad-key-bo` in `[ROOT]/foo/.cargo/config.toml`
[WARNING] unused config key `profile.dev.package.bar.bad-key-bar` in `[ROOT]/foo/.cargo/config.toml`
[COMPILING] foo v0.5.0 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
"#]].unordered()).run();
}

#[cargo_test]
Expand All @@ -132,14 +132,13 @@ fn profile_config_error_paths() {

p.cargo("build")
.with_status(101)
.with_stderr(
"\
[ERROR] error in [..]/foo/.cargo/config.toml: could not load config key `profile.dev`
.with_stderr_data(str![[r#"
[ERROR] error in [ROOT]/foo/.cargo/config.toml: could not load config key `profile.dev`
Caused by:
error in [..]/home/.cargo/config.toml: `profile.dev.rpath` expected true/false, but found a string
",
)
error in [ROOT]/home/.cargo/config.toml: `profile.dev.rpath` expected true/false, but found a string
"#]])
.run();
}

Expand All @@ -159,14 +158,13 @@ fn profile_config_validate_errors() {

p.cargo("build")
.with_status(101)
.with_stderr(
"\
[ERROR] config profile `dev` is not valid (defined in `[..]/foo/.cargo/config.toml`)
.with_stderr_data(str![[r#"
[ERROR] config profile `dev` is not valid (defined in `[ROOT]/foo/.cargo/config.toml`)
Caused by:
`panic` may not be specified in a `package` profile
",
)
"#]])
.run();
}

Expand All @@ -186,14 +184,13 @@ fn profile_config_syntax_errors() {

p.cargo("build")
.with_status(101)
.with_stderr(
"\
[ERROR] error in [..]/.cargo/config.toml: could not load config key `profile.dev`
.with_stderr_data(str![[r#"
[ERROR] error in [ROOT]/foo/.cargo/config.toml: could not load config key `profile.dev`
Caused by:
error in [..]/foo/.cargo/config.toml: `profile.dev.codegen-units` expected an integer, but found a string
",
)
error in [ROOT]/foo/.cargo/config.toml: `profile.dev.codegen-units` expected an integer, but found a string
"#]])
.run();
}

Expand Down Expand Up @@ -231,12 +228,12 @@ fn profile_config_override_spec_multiple() {
// much of a problem.
p.cargo("build -v")
.with_status(101)
.with_stderr(
"\
.with_stderr_data(str![[r#"
[LOCKING] 2 packages to latest compatible versions
[ERROR] multiple package overrides in profile `dev` match package `bar v0.5.0 ([..])`
found package specs: bar, bar@0.5.0",
)
[ERROR] multiple package overrides in profile `dev` match package `bar v0.5.0 ([ROOT]/foo/bar)`
found package specs: bar, bar@0.5.0
"#]])
.run();
}

Expand Down Expand Up @@ -264,22 +261,12 @@ fn profile_config_all_options() {

p.cargo("build --release -v")
.env_remove("CARGO_INCREMENTAL")
.with_stderr(
"\
[COMPILING] foo [..]
[RUNNING] `rustc --crate-name foo [..] \
-C opt-level=1 \
-C panic=abort \
-C lto[..]\
-C codegen-units=2 \
-C debuginfo=2 [..]\
-C debug-assertions=on \
-C overflow-checks=off [..]\
-C rpath [..]\
-C incremental=[..]
[FINISHED] `release` profile [optimized + debuginfo] [..]
",
)
.with_stderr_data(str![[r#"
[COMPILING] foo v0.0.1 ([ROOT]/foo)
[RUNNING] `rustc --crate-name foo [..] -C opt-level=1 -C panic=abort -C lto[..]-C codegen-units=2 -C debuginfo=2 [..]-C debug-assertions=on -C overflow-checks=off [..]-C rpath --out-dir [ROOT]/foo/target/release/deps -C incremental=[ROOT]/foo/target/release/incremental[..]`
[FINISHED] `release` profile [optimized + debuginfo] target(s) in [ELAPSED]s
"#]])
.run();
}

Expand Down Expand Up @@ -318,18 +305,19 @@ fn profile_config_override_precedence() {
.build();

p.cargo("build -v")
.with_stderr(
"\
.with_stderr_data(str![[r#"
[LOCKING] 2 packages to latest compatible versions
[COMPILING] bar [..]
[RUNNING] `rustc --crate-name bar [..] -C opt-level=2[..]-C codegen-units=2 [..]
[COMPILING] foo [..]
[RUNNING] `rustc --crate-name foo [..]-C codegen-units=2 [..]
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]",
)
[COMPILING] bar v0.5.0 ([ROOT]/foo/bar)
[RUNNING] `rustc --crate-name bar [..] -C opt-level=2[..]-C codegen-units=2 [..]`
[COMPILING] foo v0.0.1 ([ROOT]/foo)
[RUNNING] `rustc --crate-name foo [..]-C codegen-units=2 [..]`
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
"#]])
.run();
}

#[allow(deprecated)]
#[cargo_test]
fn profile_config_no_warn_unknown_override() {
let p = project()
Expand Down Expand Up @@ -371,7 +359,12 @@ fn profile_config_mixed_types() {
.build();

p.cargo("build -v")
.with_stderr_contains("[..]-C opt-level=3 [..]")
.with_stderr_data(str![[r#"
[COMPILING] foo v0.5.0 ([ROOT]/foo)
[RUNNING] `rustc [..]-C opt-level=3 [..]`
[FINISHED] `dev` profile [optimized + debuginfo] target(s) in [ELAPSED]s
"#]])
.run();
}

Expand Down Expand Up @@ -486,10 +479,16 @@ fn named_env_profile() {
p.cargo("build -v --profile=other")
.env("CARGO_PROFILE_OTHER_CODEGEN_UNITS", "1")
.env("CARGO_PROFILE_OTHER_INHERITS", "dev")
.with_stderr_contains("[..]-C codegen-units=1 [..]")
.with_stderr_data(str![[r#"
[COMPILING] foo v0.1.0 ([ROOT]/foo)
[RUNNING] `rustc [..]-C codegen-units=1 [..]`
[FINISHED] `other` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
"#]])
.run();
}

#[allow(deprecated)]
#[cargo_test]
fn test_with_dev_profile() {
// The `test` profile inherits from `dev` for both local crates and
Expand All @@ -512,20 +511,19 @@ fn test_with_dev_profile() {
.build();
p.cargo("test --lib --no-run -v")
.env("CARGO_PROFILE_DEV_DEBUG", "0")
.with_stderr(
"\
[UPDATING] [..]
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 2 packages to latest compatible versions
[DOWNLOADING] [..]
[DOWNLOADED] [..]
[DOWNLOADING] crates ...
[DOWNLOADED] somedep v1.0.0 (registry `dummy-registry`)
[COMPILING] somedep v1.0.0
[RUNNING] `rustc --crate-name somedep [..]
[COMPILING] foo v0.1.0 [..]
[RUNNING] `rustc --crate-name foo [..]
[FINISHED] [..]
[EXECUTABLE] `[..]/target/debug/deps/foo-[..][EXE]`
",
)
[RUNNING] `rustc --crate-name somedep [..]`
[COMPILING] foo v0.1.0 ([ROOT]/foo)
[RUNNING] `rustc --crate-name foo [..]`
[FINISHED] `test` profile [unoptimized] target(s) in [ELAPSED]s
[EXECUTABLE] `[ROOT]/foo/target/debug/deps/foo-[HASH][EXE]`
"#]])
.with_stdout_does_not_contain("[..] -C debuginfo=0[..]")
.run();
}
Loading

0 comments on commit e18afe2

Please sign in to comment.