Skip to content

Commit 08c5e35

Browse files
committed
test(trim-paths): parsing in mainfest and config
1 parent 4d29af1 commit 08c5e35

File tree

4 files changed

+156
-0
lines changed

4 files changed

+156
-0
lines changed

tests/testsuite/bad_config.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,3 +1664,37 @@ 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+
r#"error: failed to parse manifest at `[..]`
1690+
1691+
Caused by:
1692+
TOML parse error at line 7, column 30
1693+
|
1694+
7 | trim-paths = "split-debuginfo"
1695+
| ^^^^^^^^^^^^^^^^^
1696+
expected a boolean, "none", "diagnostics", "macro", "object", "all", or an array with these options
1697+
"#,
1698+
)
1699+
.run();
1700+
}

tests/testsuite/config.rs

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

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)