about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libstd/sys/unix/process/process_common.rs8
-rw-r--r--src/test/ui/command-argv0-debug.rs24
2 files changed, 30 insertions, 2 deletions
diff --git a/src/libstd/sys/unix/process/process_common.rs b/src/libstd/sys/unix/process/process_common.rs
index c9109b0c9d4..e66d6fdc56a 100644
--- a/src/libstd/sys/unix/process/process_common.rs
+++ b/src/libstd/sys/unix/process/process_common.rs
@@ -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(())
diff --git a/src/test/ui/command-argv0-debug.rs b/src/test/ui/command-argv0-debug.rs
new file mode 100644
index 00000000000..133d2ada2b2
--- /dev/null
+++ b/src/test/ui/command-argv0-debug.rs
@@ -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""#);
+}