Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(status): Don't show status if all exit codes are 0 #3109

Merged
merged 2 commits into from
Oct 3, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 29 additions & 6 deletions src/modules/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 🔴=🔴 🔴 🔴",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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]];
Expand Down