From 4b39274b9ef9391f00e092c4e91b5df84dbeadd9 Mon Sep 17 00:00:00 2001 From: Raushan Kumar Date: Tue, 21 Apr 2026 06:49:11 +0000 Subject: [PATCH 1/2] test(help): add test for man page temp file extension (#16910) --- tests/testsuite/help.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/testsuite/help.rs b/tests/testsuite/help.rs index cec7d5513d3..4fc963146f7 100644 --- a/tests/testsuite/help.rs +++ b/tests/testsuite/help.rs @@ -118,6 +118,36 @@ fn help_man() { help_with_man_and_path("", "build", "build", Path::new("")); } +#[cargo_test] +fn help_man_temp_file_extension() { + let p = project() + .at("man") + .file("Cargo.toml", &basic_manifest("man", "1.0.0")) + .file( + "src/main.rs", + r#" + fn main() { + let path = std::env::args().nth(1).unwrap(); + if path.ends_with(".1") { + println!("has .1 extension"); + } else { + println!("no .1 extension"); + } + } + "#, + ) + .build(); + p.cargo("build").run(); + + cargo_process("help build") + .env("PATH", &p.target_debug_dir()) + .with_stdout_data(str![[r#" +no .1 extension + +"#]]) + .run(); +} + #[cargo_test] fn help_alias() { // Check that `help some_alias` will resolve. From 67e895acc55519e3e4d4d1672bb74173e19461d1 Mon Sep 17 00:00:00 2001 From: Raushan Kumar Date: Tue, 21 Apr 2026 06:56:22 +0000 Subject: [PATCH 2/2] fix(help): add .1 extension to man page temp file (#16910) --- src/bin/cargo/commands/help.rs | 6 +++++- tests/testsuite/help.rs | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/bin/cargo/commands/help.rs b/src/bin/cargo/commands/help.rs index b618cd8f6d5..fa732a9b3af 100644 --- a/src/bin/cargo/commands/help.rs +++ b/src/bin/cargo/commands/help.rs @@ -171,7 +171,11 @@ fn extract_man(subcommand: &str, extension: &str) -> Option> { /// display it. fn write_and_spawn(name: &str, contents: &[u8], command: &str) -> CargoResult<()> { let prefix = format!("cargo-{}.", name); - let mut tmp = tempfile::Builder::new().prefix(&prefix).tempfile()?; + let suffix = if command == "man" { ".1" } else { "" }; + let mut tmp = tempfile::Builder::new() + .prefix(&prefix) + .suffix(suffix) + .tempfile()?; let f = tmp.as_file_mut(); f.write_all(contents)?; f.flush()?; diff --git a/tests/testsuite/help.rs b/tests/testsuite/help.rs index 4fc963146f7..14c35d40e1e 100644 --- a/tests/testsuite/help.rs +++ b/tests/testsuite/help.rs @@ -142,7 +142,7 @@ fn help_man_temp_file_extension() { cargo_process("help build") .env("PATH", &p.target_debug_dir()) .with_stdout_data(str![[r#" -no .1 extension +has .1 extension "#]]) .run();