From d0bc71c18042673e7c944ad87dbd2b64720a064e Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Thu, 4 Jan 2024 03:15:26 +0100 Subject: [PATCH] test: test output depending on environment --- src/checker/mod.rs | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/src/checker/mod.rs b/src/checker/mod.rs index 267de6b..e8af4d2 100644 --- a/src/checker/mod.rs +++ b/src/checker/mod.rs @@ -96,10 +96,14 @@ mod tests { state: CheckState::Up, }; - assert_eq!( - check_result.to_string(), - r##"{"color":"#00FF00","full_text":"test","name":"test","separator_block_width":16}"## - ) + if Term::stdout().is_term() { + assert_eq!(check_result.to_string(), "\u{1b}[32mtest\u{1b}[0m") + } else { + assert_eq!( + check_result.to_string(), + r##"{"color":"#00FF00","full_text":"test","name":"test","separator_block_width":16}"## + ) + } } #[test] @@ -109,10 +113,14 @@ mod tests { state: CheckState::Warn, }; - assert_eq!( - check_result.to_string(), - r##"{"color":"#FFFF00","full_text":"test","name":"test","separator_block_width":16}"## - ) + if Term::stdout().is_term() { + assert_eq!(check_result.to_string(), "\u{1b}[33mtest\u{1b}[0m") + } else { + assert_eq!( + check_result.to_string(), + r##"{"color":"#FFFF00","full_text":"test","name":"test","separator_block_width":16}"## + ) + } } #[test] @@ -122,9 +130,13 @@ mod tests { state: CheckState::Down, }; - assert_eq!( - check_result.to_string(), - r##"{"color":"#FF0000","full_text":"test","name":"test","separator_block_width":16}"## - ) + if Term::stdout().is_term() { + assert_eq!(check_result.to_string(), "\u{1b}[31mtest\u{1b}[0m") + } else { + assert_eq!( + check_result.to_string(), + r##"{"color":"#FF0000","full_text":"test","name":"test","separator_block_width":16}"## + ) + } } }