1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#![deny(
dead_code,
missing_docs,
missing_debug_implementations,
missing_copy_implementations,
trivial_casts,
trivial_numeric_casts,
unsafe_code,
unstable_features,
unused_import_braces,
unused_qualifications
)]
use std::env;
const ENV_VAR_NO_COLOR: &str = "NO_COLOR";
pub fn is_no_color() -> bool {
env::var_os(ENV_VAR_NO_COLOR).is_some()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_env_var_no_color_true_with_value() {
env::set_var(ENV_VAR_NO_COLOR, "1");
assert!(is_no_color(), true);
}
#[test]
fn test_env_var_no_color_true_without_value() {
env::set_var(ENV_VAR_NO_COLOR, "");
assert!(is_no_color(), true);
}
}