Skip to content

Commit

Permalink
fix(status): Showing exit code 0 with pipelines (starship#3028)
Browse files Browse the repository at this point in the history
Have fixed a bug there the status module was showing when the exit code
was 0.
  • Loading branch information
andytom authored Sep 1, 2021
1 parent 494b6eb commit 3933553
Showing 1 changed file with 36 additions and 19 deletions.
55 changes: 36 additions & 19 deletions src/modules/status.rs
Original file line number Diff line number Diff line change
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

0 comments on commit 3933553

Please sign in to comment.