Skip to content

Commit dc977b3

Browse files
committed
test(trim-paths): parsing in mainfest and config
1 parent 14494ba commit dc977b3

File tree

4 files changed

+158
-0
lines changed

4 files changed

+158
-0
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`, `diagnostics`, `macro`, `object`, `all`
1698+
",
1699+
)
1700+
.run();
1701+
}

tests/testsuite/config.rs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
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::TomlTrimPaths;
7+
use cargo::util::toml::TomlTrimPathsValue;
68
use cargo::util::toml::{self as cargo_toml, TomlDebugInfo, VecStringOrBool as VSOB};
79
use cargo::CargoResult;
810
use cargo_test_support::compare;
@@ -1729,3 +1731,64 @@ jobs = 2
17291731
JobsConfig::Integer(v) => assert_eq!(v, 2),
17301732
}
17311733
}
1734+
1735+
#[cargo_test]
1736+
fn trim_paths_parsing() {
1737+
let config = ConfigBuilder::new().build();
1738+
let p: cargo_toml::TomlProfile = config.get("profile.dev").unwrap();
1739+
assert_eq!(p.trim_paths, None);
1740+
1741+
// .unstable_flag("advanced-env")
1742+
1743+
let test_cases = [
1744+
(TomlTrimPaths::diagnostics(), "diagnostics"),
1745+
(TomlTrimPaths::r#macro(), "macro"),
1746+
(TomlTrimPaths::object(), "object"),
1747+
];
1748+
for (expected, val) in test_cases {
1749+
// env
1750+
let config = ConfigBuilder::new()
1751+
.env("CARGO_PROFILE_DEV_TRIM_PATHS", val)
1752+
.build();
1753+
let trim_paths: TomlTrimPaths = config.get("profile.dev.trim-paths").unwrap();
1754+
assert_eq!(trim_paths, expected, "failed to parse {val}");
1755+
1756+
// config.toml
1757+
let config = ConfigBuilder::new()
1758+
.config_arg(format!("profile.dev.trim-paths='{val}'"))
1759+
.build();
1760+
let trim_paths: TomlTrimPaths = config.get("profile.dev.trim-paths").unwrap();
1761+
assert_eq!(trim_paths, expected, "failed to parse {val}");
1762+
}
1763+
1764+
let test_cases = [(TomlTrimPaths::none(), false), (TomlTrimPaths::all(), true)];
1765+
1766+
for (expected, val) in test_cases {
1767+
// env
1768+
let config = ConfigBuilder::new()
1769+
.env("CARGO_PROFILE_DEV_TRIM_PATHS", format!("{val}"))
1770+
.build();
1771+
let trim_paths: TomlTrimPaths = config.get("profile.dev.trim-paths").unwrap();
1772+
assert_eq!(trim_paths, expected, "failed to parse {val}");
1773+
1774+
// config.toml
1775+
let config = ConfigBuilder::new()
1776+
.config_arg(format!("profile.dev.trim-paths={val}"))
1777+
.build();
1778+
let trim_paths: TomlTrimPaths = config.get("profile.dev.trim-paths").unwrap();
1779+
assert_eq!(trim_paths, expected, "failed to parse {val}");
1780+
}
1781+
1782+
let expected = TomlTrimPaths::Many(vec![
1783+
TomlTrimPathsValue::Diagnostics,
1784+
TomlTrimPathsValue::Macro,
1785+
TomlTrimPathsValue::Object,
1786+
]);
1787+
let val = r#"["diagnostics", "macro", "object"]"#;
1788+
// config.toml
1789+
let config = ConfigBuilder::new()
1790+
.config_arg(format!("profile.dev.trim-paths={val}"))
1791+
.build();
1792+
let trim_paths: TomlTrimPaths = config.get("profile.dev.trim-paths").unwrap();
1793+
assert_eq!(trim_paths, expected, "failed to parse {val}");
1794+
}

tests/testsuite/main.rs

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

tests/testsuite/profile_trim_paths.rs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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 = "macro"
17+
"#,
18+
)
19+
.file("src/lib.rs", "")
20+
.build();
21+
22+
p.cargo("check")
23+
.masquerade_as_nightly_cargo(&["-Ztrim-paths"])
24+
.with_status(101)
25+
.with_stderr_contains(
26+
"\
27+
[ERROR] failed to parse manifest at `[CWD]/Cargo.toml`
28+
29+
Caused by:
30+
feature `trim-paths` is required",
31+
)
32+
.run();
33+
}
34+
35+
#[cargo_test]
36+
fn gated_config_toml() {
37+
let p = project()
38+
.file(
39+
".cargo/config.toml",
40+
r#"
41+
[profile.dev]
42+
trim-paths = "macro"
43+
"#,
44+
)
45+
.file("src/lib.rs", "")
46+
.build();
47+
48+
p.cargo("check")
49+
.masquerade_as_nightly_cargo(&["-Ztrim-paths"])
50+
.with_status(101)
51+
.with_stderr_contains(
52+
"\
53+
[ERROR] config profile `dev` is not valid (defined in `[CWD]/.cargo/config.toml`)
54+
55+
Caused by:
56+
feature `trim-paths` is required",
57+
)
58+
.run();
59+
}

0 commit comments

Comments
 (0)