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): Showing exit code 0 with pipelines #3028

Merged
merged 1 commit into from Sep 1, 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
55 changes: 36 additions & 19 deletions src/modules/status.rs
Expand Up @@ -19,6 +19,15 @@ enum PipeStatusStatus<'a> {
///
/// Will display the status only if it is not 0
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
let mut module = context.new_module("status");
let config = StatusConfig::try_load(module.config);

// As we default to disabled=true, we have to check here after loading our config module,
// before it was only checking against whatever is in the config starship.toml
if config.disabled {
return None;
};

let exit_code = context
.properties
.get("status_code")
Expand All @@ -31,24 +40,18 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
false => PipeStatusStatus::NoPipe,
},
};

let pipestatus_status = match config.pipestatus {
true => pipestatus_status,
false => PipeStatusStatus::Disabled,
};

if exit_code == "0"
&& (pipestatus_status == PipeStatusStatus::Disabled
|| pipestatus_status == PipeStatusStatus::NoPipe)
{
return None;
}
let mut module = context.new_module("status");
let config = StatusConfig::try_load(module.config);

// As we default to disabled=true, we have to check here after loading our config module,
// before it was only checking against whatever is in the config starship.toml
if config.disabled {
return None;
};
let pipestatus_status = match config.pipestatus {
true => pipestatus_status,
false => PipeStatusStatus::Disabled,
};

// Create pipestatus string
let pipestatus = match pipestatus_status {
Expand Down Expand Up @@ -494,15 +497,29 @@ mod tests {
}
}

#[test]
fn successful_pipeline() {
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
})
.status(main_exit_code)
.pipestatus(&pipe_exit_code)
.collect();
assert_eq!(expected, actual);
}

#[test]
fn pipeline_disabled() {
let exit_values = [
[0, 0, 0, 0],
[0, 1, 2, 3],
[130, 126, 131, 127],
[1, 1, 1, 1],
];
let exit_values_rendered = ["F 🟢", "F 🟢", "F 🧱", "F 🔴"];
let exit_values = [[130, 126, 131, 127], [1, 1, 1, 1]];
let exit_values_rendered = ["F 🧱", "F 🔴"];

for (status, rendered) in exit_values.iter().zip(exit_values_rendered.iter()) {
let main_exit_code = status[0];
Expand Down