Skip to content

Commit e2c4cda

Browse files
committed
test(trim-paths): parsing in mainfest and config
1 parent 2604f7c commit e2c4cda

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
@@ -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,63 @@ 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+
let test_cases = [
1742+
(TomlTrimPathsValue::Diagnostics.into(), "diagnostics"),
1743+
(TomlTrimPathsValue::Macro.into(), "macro"),
1744+
(TomlTrimPathsValue::Object.into(), "object"),
1745+
];
1746+
for (expected, val) in test_cases {
1747+
// env
1748+
let config = ConfigBuilder::new()
1749+
.env("CARGO_PROFILE_DEV_TRIM_PATHS", val)
1750+
.build();
1751+
let trim_paths: TomlTrimPaths = config.get("profile.dev.trim-paths").unwrap();
1752+
assert_eq!(trim_paths, expected, "failed to parse {val}");
1753+
1754+
// config.toml
1755+
let config = ConfigBuilder::new()
1756+
.config_arg(format!("profile.dev.trim-paths='{val}'"))
1757+
.build();
1758+
let trim_paths: TomlTrimPaths = config.get("profile.dev.trim-paths").unwrap();
1759+
assert_eq!(trim_paths, expected, "failed to parse {val}");
1760+
}
1761+
1762+
let test_cases = [(TomlTrimPaths::none(), false), (TomlTrimPaths::All, true)];
1763+
1764+
for (expected, val) in test_cases {
1765+
// env
1766+
let config = ConfigBuilder::new()
1767+
.env("CARGO_PROFILE_DEV_TRIM_PATHS", format!("{val}"))
1768+
.build();
1769+
let trim_paths: TomlTrimPaths = config.get("profile.dev.trim-paths").unwrap();
1770+
assert_eq!(trim_paths, expected, "failed to parse {val}");
1771+
1772+
// config.toml
1773+
let config = ConfigBuilder::new()
1774+
.config_arg(format!("profile.dev.trim-paths={val}"))
1775+
.build();
1776+
let trim_paths: TomlTrimPaths = config.get("profile.dev.trim-paths").unwrap();
1777+
assert_eq!(trim_paths, expected, "failed to parse {val}");
1778+
}
1779+
1780+
let expected = vec![
1781+
TomlTrimPathsValue::Diagnostics,
1782+
TomlTrimPathsValue::Macro,
1783+
TomlTrimPathsValue::Object,
1784+
]
1785+
.into();
1786+
let val = r#"["diagnostics", "macro", "object"]"#;
1787+
// config.toml
1788+
let config = ConfigBuilder::new()
1789+
.config_arg(format!("profile.dev.trim-paths={val}"))
1790+
.build();
1791+
let trim_paths: TomlTrimPaths = config.get("profile.dev.trim-paths").unwrap();
1792+
assert_eq!(trim_paths, expected, "failed to parse {val}");
1793+
}

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)