From b3dbf52e921e7c64aeb45184d0527fa172750dc5 Mon Sep 17 00:00:00 2001 From: dark0dave Date: Sat, 25 Nov 2023 13:15:37 +0000 Subject: [PATCH] fix(exit): This fixes a regression which was introduced, we should search for contains otherwise the installer does not exit when warnings are detected. Closes #32 Signed-off-by: dark0dave --- src/state.rs | 2 +- src/weidu_parser.rs | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/state.rs b/src/state.rs index be6c772..d4964a8 100644 --- a/src/state.rs +++ b/src/state.rs @@ -1,4 +1,4 @@ -#[derive(Debug)] +#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)] pub enum State { RequiresInput { question: String }, InProgress, diff --git a/src/weidu_parser.rs b/src/weidu_parser.rs index a158fad..5a81d11 100644 --- a/src/weidu_parser.rs +++ b/src/weidu_parser.rs @@ -131,13 +131,26 @@ fn string_looks_like_question(weidu_output: &str) -> bool { fn detect_weidu_finished_state(weidu_output: &str) -> Option { let comparable_output = weidu_output.trim().to_lowercase(); - if WEIDU_FAILED_WITH_ERROR.eq(&comparable_output) { + if comparable_output.contains(WEIDU_FAILED_WITH_ERROR) { Some(State::CompletedWithErrors { error_details: comparable_output, }) - } else if WEIDU_COMPLETED_WITH_WARNINGS.eq(&comparable_output) { + } else if comparable_output.contains(WEIDU_COMPLETED_WITH_WARNINGS) { Some(State::CompletedWithWarnings) } else { None } } + +#[cfg(test)] +mod tests { + use super::*; + #[test] + fn test_exit_warnings() { + let test = "INSTALLED WITH WARNINGS Additional equipment for Thieves and Bards"; + assert_eq!( + detect_weidu_finished_state(test), + Some(State::CompletedWithWarnings) + ) + } +}