Skip to content

Commit f2b139f

Browse files
committed
Command: also print removed env vars
1 parent 9530589 commit f2b139f

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

library/std/src/process/tests.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ fn env_empty() {
452452
#[test]
453453
#[cfg(not(windows))]
454454
#[cfg_attr(any(target_os = "emscripten", target_env = "sgx"), ignore)]
455-
fn main() {
455+
fn debug_print() {
456456
const PIDFD: &'static str =
457457
if cfg!(target_os = "linux") { " create_pidfd: false,\n" } else { "" };
458458

@@ -538,6 +538,27 @@ fn main() {
538538
cwd: Some(
539539
"/some/path",
540540
),
541+
{PIDFD}}}"#
542+
)
543+
);
544+
545+
let mut command_with_removed_env = Command::new("boring-name");
546+
command_with_removed_env.env_remove("BAR");
547+
assert_eq!(format!("{command_with_removed_env:?}"), r#"unset(BAR) "boring-name""#);
548+
assert_eq!(
549+
format!("{command_with_removed_env:#?}"),
550+
format!(
551+
r#"Command {{
552+
program: "boring-name",
553+
args: [
554+
"boring-name",
555+
],
556+
env: CommandEnv {{
557+
clear: false,
558+
vars: {{
559+
"BAR": None,
560+
}},
561+
}},
541562
{PIDFD}}}"#
542563
)
543564
);

library/std/src/sys/unix/process/process_common.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,8 @@ impl fmt::Debug for Command {
561561
for (key, value_opt) in self.get_envs() {
562562
if let Some(value) = value_opt {
563563
write!(f, "{}={value:?} ", key.to_string_lossy())?;
564+
} else {
565+
write!(f, "unset({}) ", key.to_string_lossy())?;
564566
}
565567
}
566568
if self.program != self.args[0] {

0 commit comments

Comments
 (0)