From de190a4bfbdcfa0d52e122b1c85348837b9ef708 Mon Sep 17 00:00:00 2001 From: Luca Matei Pintilie Date: Sat, 21 Aug 2021 11:02:18 +0200 Subject: [PATCH] Format and add test --- src/flags/color.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/flags/color.rs b/src/flags/color.rs index cbdd7be..ddfe63c 100644 --- a/src/flags/color.rs +++ b/src/flags/color.rs @@ -6,9 +6,9 @@ use super::Configurable; use crate::config_file::Config; use crate::print_error; -use std::env; use clap::ArgMatches; use serde::Deserialize; +use std::env; /// A collection of flags on how to use colors. #[derive(Clone, Debug, Copy, PartialEq, Eq, Default)] @@ -93,7 +93,7 @@ impl Configurable for ColorOption { fn from_environment() -> Option { if env::var("NO_COLOR").is_ok() { - return Some(Self::Never) + return Some(Self::Never); } else { None } @@ -115,6 +115,8 @@ mod test_color_option { use crate::config_file::{self, Config}; use crate::flags::Configurable; + use std::env::set_var; + #[test] fn test_from_arg_matches_none() { let argv = vec!["lsd"]; @@ -152,6 +154,12 @@ mod test_color_option { ); } + #[test] + fn test_from_env_no_color() { + set_var("NO_COLOR", "true"); + assert_eq!(Some(ColorOption::Never), ColorOption::from_environment()); + } + #[test] fn test_from_arg_matches_classic_mode() { let argv = vec!["lsd", "--color", "always", "--classic"];