Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/libstd/sys/unix/process/process_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,12 @@ impl ChildStdio {

impl fmt::Debug for Command {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", self.program)?;
for arg in &self.args {
if self.program != self.args[0] {
write!(f, "[{:?}] ", self.program)?;
}
write!(f, "{:?}", self.args[0])?;

for arg in &self.args[1..] {
write!(f, " {:?}", arg)?;
}
Ok(())
Expand Down
24 changes: 24 additions & 0 deletions src/test/ui/command/command-argv0-debug.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// run-pass

// ignore-windows - this is a unix-specific test
// ignore-cloudabi no processes
// ignore-emscripten no processes
// ignore-sgx no processes
#![feature(process_set_argv0)]

use std::os::unix::process::CommandExt;
use std::process::Command;

fn main() {
let mut command = Command::new("some-boring-name");

assert_eq!(format!("{:?}", command), r#""some-boring-name""#);

command.args(&["1", "2", "3"]);

assert_eq!(format!("{:?}", command), r#""some-boring-name" "1" "2" "3""#);

command.arg0("exciting-name");

assert_eq!(format!("{:?}", command), r#"["some-boring-name"] "exciting-name" "1" "2" "3""#);
}
File renamed without changes.
File renamed without changes.
File renamed without changes.