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" ...`.
This commit is contained in:
Mazdak Farrokhzad 2019-12-20 12:17:22 +01:00 committed by GitHub
commit b779cbbe68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 30 additions and 2 deletions

View File

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

View File

@ -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""#);
}