From 68694029c4a3d9a100eedc25c5fa0146e7677fa9 Mon Sep 17 00:00:00 2001 From: David Knaack Date: Sun, 3 Oct 2021 16:03:09 +0200 Subject: [PATCH] fix(status): Don't show status if all exit codes are 0 (#3109) * fix(status): Don't show status if all exit codes are 0 * fix tests --- src/modules/status.rs | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/src/modules/status.rs b/src/modules/status.rs index a0056329..f2ca7530 100644 --- a/src/modules/status.rs +++ b/src/modules/status.rs @@ -46,9 +46,12 @@ pub fn module<'a>(context: &'a Context) -> Option> { false => PipeStatusStatus::Disabled, }; + // Exit code is zero and pipestatus is all zero or disabled/missing if exit_code == "0" - && (pipestatus_status == PipeStatusStatus::Disabled - || pipestatus_status == PipeStatusStatus::NoPipe) + && (match pipestatus_status { + PipeStatusStatus::Pipe(ps) => ps.iter().all(|s| s == "0"), + _ => true, + }) { return None; } @@ -412,13 +415,13 @@ mod tests { #[test] fn pipeline_uses_pipestatus_format() { let exit_values = [ - [0, 0, 0, 0], + [0, 1, 0, 0], [0, 1, 2, 3], [130, 126, 131, 127], [1, 1, 1, 1], ]; let exit_values_rendered = [ - "PSF 🟒=🟒 🟒 🟒", + "PSF 🟒=πŸ”΄ 🟒 🟒", "PSF 🟒=πŸ”΄ πŸ”΄ πŸ”΄", "PSF 🧱=🚫 ⚑ πŸ”", "PSF πŸ”΄=πŸ”΄ πŸ”΄ πŸ”΄", @@ -456,13 +459,13 @@ mod tests { #[test] fn pipeline_no_map_symbols() { let exit_values = [ - [0, 0, 0, 0], + [0, 1, 0, 0], [0, 1, 2, 3], [130, 126, 131, 127], [1, 1, 1, 1], ]; let exit_values_rendered = [ - "PSF 🟒=🟒0 🟒0 🟒0", + "PSF 🟒=πŸ”΄1 🟒0 🟒0", "PSF 🟒=πŸ”΄1 πŸ”΄2 πŸ”΄3", "PSF INTπŸ”΄=πŸ”΄126 πŸ”΄1313 πŸ”΄127", "PSF πŸ”΄=πŸ”΄1 πŸ”΄1 πŸ”΄1", @@ -516,6 +519,26 @@ mod tests { assert_eq!(expected, actual); } + #[test] + fn successful_pipeline_pipestatus_enabled() { + let pipe_exit_code = [0, 0, 0]; + + let main_exit_code = 0; + + let expected = None; + + let actual = ModuleRenderer::new("status") + .config(toml::toml! { + [status] + disabled = false + pipestatus = true + }) + .status(main_exit_code) + .pipestatus(&pipe_exit_code) + .collect(); + assert_eq!(expected, actual); + } + #[test] fn pipeline_disabled() { let exit_values = [[130, 126, 131, 127], [1, 1, 1, 1]];