Also log command with enough verbosity

This commit is contained in:
datdenkikniet 2023-04-15 13:55:56 +02:00
parent 461023e3b8
commit 622a58db5a
2 changed files with 16 additions and 5 deletions

View file

@ -1,7 +1,8 @@
use log::{error, info, Level}; use log::{error, info, Level};
use crate::{ use crate::{
cargo_commands::FinalRunResult, ExtraArguments, Package, RunResult, Target, TestRunError, argument_parsing::Globals, cargo_commands::FinalRunResult, ExtraArguments, Package, RunResult,
Target, TestRunError,
}; };
use core::fmt; use core::fmt;
use std::{ use std::{
@ -305,6 +306,12 @@ impl core::fmt::Display for CargoCommand<'_> {
} }
impl<'a> CargoCommand<'a> { impl<'a> CargoCommand<'a> {
pub fn as_cmd_string(&self) -> String {
let executable = self.executable();
let args = self.args().join(" ");
format!("{executable} {args}")
}
fn command(&self) -> &str { fn command(&self) -> &str {
match self { match self {
CargoCommand::Run { .. } | CargoCommand::Qemu { .. } => "run", CargoCommand::Run { .. } | CargoCommand::Qemu { .. } => "run",
@ -702,7 +709,7 @@ pub fn run_successful(run: &RunResult, expected_output_file: &str) -> Result<(),
} }
} }
pub fn handle_results(results: Vec<FinalRunResult>) -> anyhow::Result<()> { pub fn handle_results(globals: &Globals, results: Vec<FinalRunResult>) -> anyhow::Result<()> {
let errors = results.iter().filter_map(|r| { let errors = results.iter().filter_map(|r| {
if let FinalRunResult::Failed(c, r) = r { if let FinalRunResult::Failed(c, r) = r {
Some((c, r)) Some((c, r))
@ -748,11 +755,15 @@ pub fn handle_results(results: Vec<FinalRunResult>) -> anyhow::Result<()> {
errors.clone().for_each(log_stdout_stderr(Level::Error)); errors.clone().for_each(log_stdout_stderr(Level::Error));
successes.for_each(|(cmd, _)| { successes.for_each(|(cmd, _)| {
info!("✅ Success: {cmd}"); if globals.verbose > 0 {
info!("✅ Success: {cmd}\n {}", cmd.as_cmd_string());
} else {
info!("✅ Success: {cmd}");
}
}); });
errors.clone().for_each(|(cmd, _)| { errors.clone().for_each(|(cmd, _)| {
error!("❌ Failed: {cmd}"); error!("❌ Failed: {cmd}\n {}", cmd.as_cmd_string());
}); });
let ecount = errors.count(); let ecount = errors.count();

View file

@ -287,7 +287,7 @@ fn main() -> anyhow::Result<()> {
} }
}; };
handle_results(final_run_results) handle_results(globals, final_run_results)
} }
// run example binary `example` // run example binary `example`