diff --git a/crates/cli/tests/cli_run.rs b/crates/cli/tests/cli_run.rs index 3cd3360a1a..511b33d509 100644 --- a/crates/cli/tests/cli_run.rs +++ b/crates/cli/tests/cli_run.rs @@ -115,7 +115,7 @@ mod cli_run { let is_reporting_runtime = stderr.starts_with("runtime: ") && stderr.ends_with("ms\n"); if !(stderr.is_empty() || is_reporting_runtime) { - panic!("\n___________\nThe roc command:\n\n {}\n\nhad unexpected stderr:\n\n {}\n___________\n", compile_out.cmd_str, stderr); + panic!("\n___________\nThe roc command:\n\n {:?}\n\nhad unexpected stderr:\n\n {}\n___________\n", compile_out.cmd_str, stderr); } assert!( diff --git a/crates/cli_utils/src/helpers.rs b/crates/cli_utils/src/helpers.rs index b0a2b34326..d866228838 100644 --- a/crates/cli_utils/src/helpers.rs +++ b/crates/cli_utils/src/helpers.rs @@ -9,7 +9,7 @@ use roc_utils::root_dir; use serde::Deserialize; use serde_xml_rs::from_str; use std::env; -use std::ffi::OsStr; +use std::ffi::{OsStr, OsString}; use std::io::Read; use std::io::Write; use std::path::Path; @@ -19,7 +19,7 @@ use tempfile::NamedTempFile; #[derive(Debug)] pub struct Out { - pub cmd_str: String, // command with all its arguments, for easy debugging + pub cmd_str: OsString, // command with all its arguments, for easy debugging pub stdout: String, pub stderr: String, pub status: ExitStatus, @@ -158,7 +158,7 @@ where roc_cmd.env(k, v); } - let roc_cmd_str = format!("{:?}", roc_cmd); + let roc_cmd_str = pretty_command_string(&roc_cmd); let mut roc_cmd_child = roc_cmd .stdin(Stdio::piped()) @@ -166,7 +166,7 @@ where .stderr(Stdio::piped()) .spawn() .unwrap_or_else(|err| { - panic!("Failed to execute command\n\n {roc_cmd_str}\n\nwith error:\n\n {err}",) + panic!("Failed to execute command\n\n {roc_cmd_str:?}\n\nwith error:\n\n {err}",) }); { @@ -177,14 +177,14 @@ where .write_all(stdin_str.as_bytes()) .unwrap_or_else(|err| { panic!( - "Failed to write to stdin for command\n\n {roc_cmd_str}\n\nwith error:\n\n {err}", + "Failed to write to stdin for command\n\n {roc_cmd_str:?}\n\nwith error:\n\n {err}", ) }); } } let roc_cmd_output = roc_cmd_child.wait_with_output().unwrap_or_else(|err| { - panic!("Failed to get output for command\n\n {roc_cmd_str}\n\nwith error:\n\n {err}",) + panic!("Failed to get output for command\n\n {roc_cmd_str:?}\n\nwith error:\n\n {err}",) }); Out { @@ -207,12 +207,12 @@ pub fn run_cmd<'a, I: IntoIterator, E: IntoIterator>( cmd.arg(arg); } - let cmd_str = format!("{:?}", cmd); + let cmd_str = pretty_command_string(&cmd); cmd.stdin(Stdio::piped()); cmd.stdout(Stdio::piped()); @@ -447,3 +447,15 @@ pub fn known_bad_file(file_name: &str) -> PathBuf { path } + +fn pretty_command_string(command: &Command) -> OsString { + let mut command_string = std::ffi::OsString::new(); + command_string.push(command.get_program()); + + for arg in command.get_args() { + command_string.push(" "); + command_string.push(arg); + } + + command_string +}