diff options
| author | datdenkikniet <jcdra1@gmail.com> | 2023-04-15 13:45:58 +0200 |
|---|---|---|
| committer | datdenkikniet <jcdra1@gmail.com> | 2023-04-15 13:45:58 +0200 |
| commit | 461023e3b836db394dce0e034a1d329b1f5c8f48 (patch) | |
| tree | a0679e39c1802cc2d170a8000685ae78eb084f9c /xtask/src/command.rs | |
| parent | df69b35c250eff5858d6e994a9866be35b987a6e (diff) | |
More emojis and correct place for things
Diffstat (limited to 'xtask/src/command.rs')
| -rw-r--r-- | xtask/src/command.rs | 71 |
1 files changed, 68 insertions, 3 deletions
diff --git a/xtask/src/command.rs b/xtask/src/command.rs index 99b7518..71dda2b 100644 --- a/xtask/src/command.rs +++ b/xtask/src/command.rs @@ -1,4 +1,8 @@ -use crate::{debug, ExtraArguments, Package, RunResult, Target, TestRunError}; +use log::{error, info, Level}; + +use crate::{ + cargo_commands::FinalRunResult, ExtraArguments, Package, RunResult, Target, TestRunError, +}; use core::fmt; use std::{ fs::File, @@ -279,7 +283,7 @@ impl core::fmt::Display for CargoCommand<'_> { .map(|t| format!("test {t}")) .unwrap_or("all tests".into()); let feat = feat(features); - write!(f, "Run {test} in {p} ({feat})") + write!(f, "Run {test} in {p} (features: {feat})") } CargoCommand::Book { arguments: _ } => write!(f, "Build the book"), CargoCommand::ExampleSize { @@ -652,7 +656,7 @@ impl fmt::Display for BuildMode { } pub fn run_command(command: &CargoCommand, stderr_mode: OutputMode) -> anyhow::Result<RunResult> { - debug!("👟 {command}"); + log::info!("👟 {command}"); let result = Command::new(command.executable()) .args(command.args()) @@ -697,3 +701,64 @@ pub fn run_successful(run: &RunResult, expected_output_file: &str) -> Result<(), Ok(()) } } + +pub fn handle_results(results: Vec<FinalRunResult>) -> anyhow::Result<()> { + let errors = results.iter().filter_map(|r| { + if let FinalRunResult::Failed(c, r) = r { + Some((c, r)) + } else { + None + } + }); + + let successes = results.iter().filter_map(|r| { + if let FinalRunResult::Success(c, r) = r { + Some((c, r)) + } else { + None + } + }); + + let log_stdout_stderr = |level: Level| { + move |(command, result): (&CargoCommand, &RunResult)| { + let stdout = &result.stdout; + let stderr = &result.stderr; + if !stdout.is_empty() && !stderr.is_empty() { + log::log!( + level, + "Output for \"{command}\"\nStdout:\n{stdout}\nStderr:\n{stderr}" + ); + } else if !stdout.is_empty() { + log::log!( + level, + "Output for \"{command}\":\nStdout:\n{}", + stdout.trim_end() + ); + } else if !stderr.is_empty() { + log::log!( + level, + "Output for \"{command}\"\nStderr:\n{}", + stderr.trim_end() + ); + } + } + }; + + successes.clone().for_each(log_stdout_stderr(Level::Debug)); + errors.clone().for_each(log_stdout_stderr(Level::Error)); + + successes.for_each(|(cmd, _)| { + info!("✅ Success: {cmd}"); + }); + + errors.clone().for_each(|(cmd, _)| { + error!("❌ Failed: {cmd}"); + }); + + let ecount = errors.count(); + if ecount != 0 { + Err(anyhow::anyhow!("{ecount} commands failed.")) + } else { + Ok(()) + } +} |
