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
This commit is contained in:
David Knaack 2021-10-03 16:03:09 +02:00 committed by GitHub
parent e85a68578c
commit 68694029c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 29 additions and 6 deletions

View File

@ -46,9 +46,12 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
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]];