diff --git a/ninja-xtask/CHANGELOG.md b/ninja-xtask/CHANGELOG.md index f3151c4..c3c8444 100644 --- a/ninja-xtask/CHANGELOG.md +++ b/ninja-xtask/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog ninja-xtask +## v0.2.6 + +- show stdout and exit status for failed commands + ## v0.2.4 & 0.2.5 - fix build workflow for publishing binaries diff --git a/ninja-xtask/Cargo.lock b/ninja-xtask/Cargo.lock index dd6cc81..21fef2a 100644 --- a/ninja-xtask/Cargo.lock +++ b/ninja-xtask/Cargo.lock @@ -352,7 +352,7 @@ checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" [[package]] name = "ninja-xtask" -version = "0.2.5" +version = "0.2.6" dependencies = [ "autocfg", "clap", diff --git a/ninja-xtask/Cargo.toml b/ninja-xtask/Cargo.toml index 7793cb0..961a9c3 100644 --- a/ninja-xtask/Cargo.toml +++ b/ninja-xtask/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ninja-xtask" -version = "0.2.5" +version = "0.2.6" edition = "2024" readme = "README.md" description = "xtask utilities that I use in most projects" diff --git a/ninja-xtask/src/lib.rs b/ninja-xtask/src/lib.rs index c63c152..8039aa2 100644 --- a/ninja-xtask/src/lib.rs +++ b/ninja-xtask/src/lib.rs @@ -93,8 +93,12 @@ impl From for Exit<()> { println!("{}: OK", cmd.name); Self::Ok(()) } else { + let stdout = String::from_utf8_lossy(&output.stdout); let stderr = String::from_utf8_lossy(&output.stderr); - Self::Error(stderr.to_string()) + Self::Error(format!( + "====== {} exited with {} ======\n-- stdout: --\n{}\n\n-- stderr: --\n{}", + cmd.name, output.status, stdout, stderr + )) } } Err(e) => { diff --git a/ninja-xtask/tests/fixture/src/lib.rs b/ninja-xtask/tests/fixture/src/lib.rs index 66e8ee2..1b5aa23 100644 --- a/ninja-xtask/tests/fixture/src/lib.rs +++ b/ninja-xtask/tests/fixture/src/lib.rs @@ -1 +1,11 @@ -enum foo { bar } \ No newline at end of file +enum foo { bar } + +#[cfg(test)] +mod tests { + #[test] + fn print_and_panic() { + println!("test printed to stdout"); + dbg!("test dbg"); + assert_eq!(5,7); + } +} \ No newline at end of file diff --git a/ninja-xtask/tests/test_fmt.rs b/ninja-xtask/tests/test_commands.rs similarity index 60% rename from ninja-xtask/tests/test_fmt.rs rename to ninja-xtask/tests/test_commands.rs index d8787f1..829f563 100644 --- a/ninja-xtask/tests/test_fmt.rs +++ b/ninja-xtask/tests/test_commands.rs @@ -1,7 +1,10 @@ -use std::fs; +use std::{fs, path::PathBuf}; use dircpy::copy_dir; -use ninja_xtask::commands::fmt; +use ninja_xtask::{ + Exit, + commands::{fmt, test}, +}; use tempfile::tempdir; #[test] @@ -23,3 +26,18 @@ fn fmt_fixture() { assert_ne!(original, formatted); dbg!(tmp.path()); } + +#[test] +fn fail_output() { + let fixture = PathBuf::from("tests/fixture"); + let run_tests = test(&fixture); + let exit = Exit::from(run_tests); + let Exit::Error(output) = exit else { + panic!("test didn't fail") + }; + assert!(output.contains("====== tests exited with")); + assert!(output.contains("test printed to stdout")); + assert!(output.contains("test dbg")); + assert!(output.contains("left: 5")); + println!("{output}"); +}