diff --git a/tests/testsuite/bad_config.rs b/tests/testsuite/bad_config.rs index 82da880ea079..8c97d83b640c 100644 --- a/tests/testsuite/bad_config.rs +++ b/tests/testsuite/bad_config.rs @@ -1664,3 +1664,38 @@ note: Sources are not allowed to be defined multiple times. ) .run(); } + +#[cargo_test] +fn bad_trim_paths() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.0" + + [profile.dev] + trim-paths = "split-debuginfo" + "#, + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("check -Ztrim-paths") + .masquerade_as_nightly_cargo(&["trim-paths"]) + .with_status(101) + .with_stderr( + "\ +error: failed to parse manifest at `[..]` + +Caused by: + TOML parse error at line 7, column 30 + | + 7 | trim-paths = \"split-debuginfo\" + | ^^^^^^^^^^^^^^^^^ + unknown variant `split-debuginfo`, expected one of `none`, `macro`, `diagnostics`, `object`, `all` +", + ) + .run(); +} diff --git a/tests/testsuite/config.rs b/tests/testsuite/config.rs index cb091dabc413..2d1c931d2474 100644 --- a/tests/testsuite/config.rs +++ b/tests/testsuite/config.rs @@ -3,7 +3,9 @@ use cargo::core::{PackageIdSpec, Shell}; use cargo::util::config::{self, Config, Definition, JobsConfig, SslVersionConfig, StringList}; use cargo::util::interning::InternedString; -use cargo::util::toml::{self as cargo_toml, TomlDebugInfo, VecStringOrBool as VSOB}; +use cargo::util::toml::{ + self as cargo_toml, ProfileTrimPaths, TomlDebugInfo, VecStringOrBool as VSOB, +}; use cargo::CargoResult; use cargo_test_support::compare; use cargo_test_support::{panic_error, paths, project, symlink_supported, t}; @@ -1706,3 +1708,35 @@ jobs = 2 JobsConfig::Integer(v) => assert_eq!(v, 2), } } + +#[cargo_test] +fn trim_paths_parsing() { + let config = ConfigBuilder::new().build(); + let p: cargo_toml::TomlProfile = config.get("profile.dev").unwrap(); + assert_eq!(p.trim_paths, None); + + // .unstable_flag("advanced-env") + + let test_cases = [ + (ProfileTrimPaths::None, "none"), + (ProfileTrimPaths::Macro, "macro"), + (ProfileTrimPaths::Diagnostics, "diagnostics"), + (ProfileTrimPaths::Object, "object"), + (ProfileTrimPaths::All, "all"), + ]; + for (expected, val) in test_cases { + // env + let config = ConfigBuilder::new() + .env("CARGO_PROFILE_DEV_TRIM_PATHS", val) + .build(); + let trim_paths: ProfileTrimPaths = config.get("profile.dev.trim-paths").unwrap(); + assert_eq!(trim_paths, expected, "failed to parse {val}"); + + // config.toml + let config = ConfigBuilder::new() + .config_arg(format!("profile.dev.trim-paths='{val}'")) + .build(); + let trim_paths: ProfileTrimPaths = config.get("profile.dev.trim-paths").unwrap(); + assert_eq!(trim_paths, expected, "failed to parse {val}"); + } +} diff --git a/tests/testsuite/main.rs b/tests/testsuite/main.rs index 8279f58180f4..1b97bb227822 100644 --- a/tests/testsuite/main.rs +++ b/tests/testsuite/main.rs @@ -137,6 +137,7 @@ mod profile_config; mod profile_custom; mod profile_overrides; mod profile_targets; +mod profile_trim_paths; mod profiles; mod progress; mod pub_priv; diff --git a/tests/testsuite/profile_trim_paths.rs b/tests/testsuite/profile_trim_paths.rs new file mode 100644 index 000000000000..9bb64bec40f3 --- /dev/null +++ b/tests/testsuite/profile_trim_paths.rs @@ -0,0 +1,57 @@ +//! Tests for `-Ztrim-paths`. + +use cargo_test_support::project; + +#[cargo_test] +fn gated_manifest() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + + [profile.dev] + trim-paths = "all" + "#, + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("check") + .with_status(101) + .with_stderr_contains( + "\ +[ERROR] failed to parse manifest at `[CWD]/Cargo.toml` + +Caused by: + feature `trim-paths` is required", + ) + .run(); +} + +#[cargo_test] +fn gated_config_toml() { + let p = project() + .file( + ".cargo/config.toml", + r#" + [profile.dev] + trim-paths = "all" + "#, + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("check") + .with_status(101) + .with_stderr_contains( + "\ +[ERROR] config profile `dev` is not valid (defined in `[CWD]/.cargo/config.toml`) + +Caused by: + feature `trim-paths` is required", + ) + .run(); +} diff --git a/tests/testsuite/profiles.rs b/tests/testsuite/profiles.rs index 531c02700339..65dea874526a 100644 --- a/tests/testsuite/profiles.rs +++ b/tests/testsuite/profiles.rs @@ -782,3 +782,38 @@ fn debug_options_valid() { .with_stderr_does_not_contain("[..]-C debuginfo[..]") .run(); } + +#[cargo_test(nightly, reason = "--remap-path-scope is unstable")] +fn trim_paths_options_valid() { + let build = |option| { + let p = project() + .file( + "Cargo.toml", + &format!( + r#" + [package] + name = "foo" + version = "0.0.0" + + [profile.dev] + trim-paths = "{option}" + "# + ), + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("build -v") + }; + + for option in ["macro", "diagnostics", "object", "all"] { + build(option) + .with_stderr_contains(&format!( + "[RUNNING] `rustc [..]--remap-path-scope={option} [..]" + )) + .run(); + } + build("none") + .with_stderr_does_not_contain("[..]--remap-path-scope[..]") + .run(); +}