Skip to content

Commit af75652

Browse files
committed
test(trim-paths): parsing in mainfest and config
1 parent 99fafbc commit af75652

File tree

5 files changed

+163
-1
lines changed

5 files changed

+163
-1
lines changed

tests/testsuite/bad_config.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,3 +1664,38 @@ note: Sources are not allowed to be defined multiple times.
16641664
)
16651665
.run();
16661666
}
1667+
1668+
#[cargo_test]
1669+
fn bad_trim_paths() {
1670+
let p = project()
1671+
.file(
1672+
"Cargo.toml",
1673+
r#"
1674+
[package]
1675+
name = "foo"
1676+
version = "0.0.0"
1677+
1678+
[profile.dev]
1679+
trim-paths = "split-debuginfo"
1680+
"#,
1681+
)
1682+
.file("src/lib.rs", "")
1683+
.build();
1684+
1685+
p.cargo("check -Ztrim-paths")
1686+
.masquerade_as_nightly_cargo(&["trim-paths"])
1687+
.with_status(101)
1688+
.with_stderr(
1689+
"\
1690+
error: failed to parse manifest at `[..]`
1691+
1692+
Caused by:
1693+
TOML parse error at line 7, column 30
1694+
|
1695+
7 | trim-paths = \"split-debuginfo\"
1696+
| ^^^^^^^^^^^^^^^^^
1697+
unknown variant `split-debuginfo`, expected one of `none`, `macro`, `diagnostics`, `object`, `all`
1698+
",
1699+
)
1700+
.run();
1701+
}

tests/testsuite/config.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
use cargo::core::{PackageIdSpec, Shell};
44
use cargo::util::config::{self, Config, Definition, JobsConfig, SslVersionConfig, StringList};
55
use cargo::util::interning::InternedString;
6-
use cargo::util::toml::{self as cargo_toml, TomlDebugInfo, VecStringOrBool as VSOB};
6+
use cargo::util::toml::{
7+
self as cargo_toml, ProfileTrimPaths, TomlDebugInfo, VecStringOrBool as VSOB,
8+
};
79
use cargo::CargoResult;
810
use cargo_test_support::compare;
911
use cargo_test_support::{panic_error, paths, project, symlink_supported, t};
@@ -1706,3 +1708,35 @@ jobs = 2
17061708
JobsConfig::Integer(v) => assert_eq!(v, 2),
17071709
}
17081710
}
1711+
1712+
#[cargo_test]
1713+
fn trim_paths_parsing() {
1714+
let config = ConfigBuilder::new().build();
1715+
let p: cargo_toml::TomlProfile = config.get("profile.dev").unwrap();
1716+
assert_eq!(p.trim_paths, None);
1717+
1718+
// .unstable_flag("advanced-env")
1719+
1720+
let test_cases = [
1721+
(ProfileTrimPaths::None, "none"),
1722+
(ProfileTrimPaths::Macro, "macro"),
1723+
(ProfileTrimPaths::Diagnostics, "diagnostics"),
1724+
(ProfileTrimPaths::Object, "object"),
1725+
(ProfileTrimPaths::All, "all"),
1726+
];
1727+
for (expected, val) in test_cases {
1728+
// env
1729+
let config = ConfigBuilder::new()
1730+
.env("CARGO_PROFILE_DEV_TRIM_PATHS", val)
1731+
.build();
1732+
let trim_paths: ProfileTrimPaths = config.get("profile.dev.trim-paths").unwrap();
1733+
assert_eq!(trim_paths, expected, "failed to parse {val}");
1734+
1735+
// config.toml
1736+
let config = ConfigBuilder::new()
1737+
.config_arg(format!("profile.dev.trim-paths='{val}'"))
1738+
.build();
1739+
let trim_paths: ProfileTrimPaths = config.get("profile.dev.trim-paths").unwrap();
1740+
assert_eq!(trim_paths, expected, "failed to parse {val}");
1741+
}
1742+
}

tests/testsuite/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ mod profile_config;
137137
mod profile_custom;
138138
mod profile_overrides;
139139
mod profile_targets;
140+
mod profile_trim_paths;
140141
mod profiles;
141142
mod progress;
142143
mod pub_priv;

tests/testsuite/profile_trim_paths.rs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//! Tests for `-Ztrim-paths`.
2+
3+
use cargo_test_support::project;
4+
5+
#[cargo_test]
6+
fn gated_manifest() {
7+
let p = project()
8+
.file(
9+
"Cargo.toml",
10+
r#"
11+
[package]
12+
name = "foo"
13+
version = "0.0.1"
14+
15+
[profile.dev]
16+
trim-paths = "all"
17+
"#,
18+
)
19+
.file("src/lib.rs", "")
20+
.build();
21+
22+
p.cargo("check")
23+
.with_status(101)
24+
.with_stderr_contains(
25+
"\
26+
[ERROR] failed to parse manifest at `[CWD]/Cargo.toml`
27+
28+
Caused by:
29+
feature `trim-paths` is required",
30+
)
31+
.run();
32+
}
33+
34+
#[cargo_test]
35+
fn gated_config_toml() {
36+
let p = project()
37+
.file(
38+
".cargo/config.toml",
39+
r#"
40+
[profile.dev]
41+
trim-paths = "all"
42+
"#,
43+
)
44+
.file("src/lib.rs", "")
45+
.build();
46+
47+
p.cargo("check")
48+
.with_status(101)
49+
.with_stderr_contains(
50+
"\
51+
[ERROR] config profile `dev` is not valid (defined in `[CWD]/.cargo/config.toml`)
52+
53+
Caused by:
54+
feature `trim-paths` is required",
55+
)
56+
.run();
57+
}

tests/testsuite/profiles.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,3 +782,38 @@ fn debug_options_valid() {
782782
.with_stderr_does_not_contain("[..]-C debuginfo[..]")
783783
.run();
784784
}
785+
786+
#[cargo_test(nightly, reason = "--remap-path-scope is unstable")]
787+
fn trim_paths_options_valid() {
788+
let build = |option| {
789+
let p = project()
790+
.file(
791+
"Cargo.toml",
792+
&format!(
793+
r#"
794+
[package]
795+
name = "foo"
796+
version = "0.0.0"
797+
798+
[profile.dev]
799+
trim-paths = "{option}"
800+
"#
801+
),
802+
)
803+
.file("src/lib.rs", "")
804+
.build();
805+
806+
p.cargo("build -v")
807+
};
808+
809+
for option in ["macro", "diagnostics", "object", "all"] {
810+
build(option)
811+
.with_stderr_contains(&format!(
812+
"[RUNNING] `rustc [..]--remap-path-scope={option} [..]"
813+
))
814+
.run();
815+
}
816+
build("none")
817+
.with_stderr_does_not_contain("[..]--remap-path-scope[..]")
818+
.run();
819+
}

0 commit comments

Comments
 (0)