Skip to content

Commit

Permalink
test(trim-paths): parsing in mainfest and config
Browse files Browse the repository at this point in the history
  • Loading branch information
weihanglo committed Sep 8, 2023
1 parent 99fafbc commit af75652
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 1 deletion.
35 changes: 35 additions & 0 deletions tests/testsuite/bad_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
36 changes: 35 additions & 1 deletion tests/testsuite/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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}");
}
}
1 change: 1 addition & 0 deletions tests/testsuite/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
57 changes: 57 additions & 0 deletions tests/testsuite/profile_trim_paths.rs
Original file line number Diff line number Diff line change
@@ -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();
}
35 changes: 35 additions & 0 deletions tests/testsuite/profiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

0 comments on commit af75652

Please sign in to comment.