Skip to content

Commit 65d0eb5

Browse files
committed
Auto merge of #12997 - hi-rustin:rustin-patch-cargo-test-support, r=epage
cargo-test-support: Add features to the default Cargo.toml file
2 parents eed300d + 504c4b2 commit 65d0eb5

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

crates/cargo-test-support/src/registry.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,6 +1523,30 @@ impl Package {
15231523
manifest.push_str(&format!("rust-version = \"{}\"", version));
15241524
}
15251525

1526+
if !self.features.is_empty() {
1527+
let features: Vec<String> = self
1528+
.features
1529+
.iter()
1530+
.map(|(feature, features)| {
1531+
if features.is_empty() {
1532+
format!("{} = []", feature)
1533+
} else {
1534+
format!(
1535+
"{} = [{}]",
1536+
feature,
1537+
features
1538+
.iter()
1539+
.map(|s| format!("\"{}\"", s))
1540+
.collect::<Vec<_>>()
1541+
.join(", ")
1542+
)
1543+
}
1544+
})
1545+
.collect();
1546+
1547+
manifest.push_str(&format!("\n[features]\n{}", features.join("\n")));
1548+
}
1549+
15261550
for dep in self.deps.iter() {
15271551
let target = match dep.target {
15281552
None => String::new(),
@@ -1540,6 +1564,9 @@ impl Package {
15401564
"#,
15411565
target, kind, dep.name, dep.vers
15421566
));
1567+
if dep.optional {
1568+
manifest.push_str("optional = true\n");
1569+
}
15431570
if let Some(artifact) = &dep.artifact {
15441571
manifest.push_str(&format!("artifact = \"{}\"\n", artifact));
15451572
}

tests/testsuite/cargo_remove/update_lock_file/in/Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testsuite/cargo_remove/update_lock_file/out/Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)