diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-12-20 12:17:22 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-12-20 12:17:22 +0100 |
| commit | b779cbbe6806caccb73f21ac6aeba99316ca8900 (patch) | |
| tree | 1e0df416d7841096d632bd247f17c05b7abf0f9f /src | |
| parent | f0eb4b4752424233e64b19ae242c052eaa65e1ce (diff) | |
| parent | ce56e7528359b9581cac0b59080d25468d60de20 (diff) | |
| download | rust-b779cbbe6806caccb73f21ac6aeba99316ca8900.tar.gz rust-b779cbbe6806caccb73f21ac6aeba99316ca8900.zip | |
Rollup merge of #67219 - jsgf:command-argv0-debug, r=joshtriplett
Fix up Command Debug output when arg0 is specified. PR https://github.com/rust-lang/rust/pull/66512 added the ability to set argv[0] on Command. As a side effect, it changed the Debug output to print both the program and argv[0], which in practice results in stuttery output (`"echo" "echo" "foo"`). This PR reverts the behaviour to the the old one, so that the command is only printed once - unless arg0 has been set. In that case it emits `"[command]" "arg0" "arg1" ...`.
Diffstat (limited to 'src')
| -rw-r--r-- | src/libstd/sys/unix/process/process_common.rs | 8 | ||||
| -rw-r--r-- | src/test/ui/command/command-argv0-debug.rs | 24 | ||||
| -rw-r--r-- | src/test/ui/command/command-argv0.rs (renamed from src/test/ui/command-argv0.rs) | 0 | ||||
| -rw-r--r-- | src/test/ui/command/command-exec.rs (renamed from src/test/ui/command-exec.rs) | 0 | ||||
| -rw-r--r-- | src/test/ui/command/command-pre-exec.rs (renamed from src/test/ui/command-pre-exec.rs) | 0 | ||||
| -rw-r--r-- | src/test/ui/command/command-uid-gid.rs (renamed from src/test/ui/command-uid-gid.rs) | 0 |
6 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/command-argv0-debug.rs b/src/test/ui/command/command-argv0-debug.rs new file mode 100644 index 00000000000..133d2ada2b2 --- /dev/null +++ b/src/test/ui/command/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""#); +} diff --git a/src/test/ui/command-argv0.rs b/src/test/ui/command/command-argv0.rs index 56a9fb4d391..56a9fb4d391 100644 --- a/src/test/ui/command-argv0.rs +++ b/src/test/ui/command/command-argv0.rs diff --git a/src/test/ui/command-exec.rs b/src/test/ui/command/command-exec.rs index 568be67abe3..568be67abe3 100644 --- a/src/test/ui/command-exec.rs +++ b/src/test/ui/command/command-exec.rs diff --git a/src/test/ui/command-pre-exec.rs b/src/test/ui/command/command-pre-exec.rs index c0fc554183a..c0fc554183a 100644 --- a/src/test/ui/command-pre-exec.rs +++ b/src/test/ui/command/command-pre-exec.rs diff --git a/src/test/ui/command-uid-gid.rs b/src/test/ui/command/command-uid-gid.rs index f867106c35d..f867106c35d 100644 --- a/src/test/ui/command-uid-gid.rs +++ b/src/test/ui/command/command-uid-gid.rs |
