pub const DIFFLORE_CAPTURE_ENV: &str = "DIFFLORE_CAPTURE";
#[must_use]
pub fn capture_enabled() -> bool {
std::env::var(DIFFLORE_CAPTURE_ENV).as_deref() != Ok("false")
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn capture_enabled_returns_true_when_unset() {
temp_env::with_var(DIFFLORE_CAPTURE_ENV, None::<&str>, || {
assert!(capture_enabled(), "unset env must leave capture enabled");
});
}
#[test]
fn capture_enabled_returns_true_when_set_to_other_values() {
for value in ["true", "1", "", "FALSE", "False", "no", "off", " false"] {
temp_env::with_var(DIFFLORE_CAPTURE_ENV, Some(value), || {
assert!(
capture_enabled(),
"value {value:?} must not disable capture (only exact lowercase \"false\" does)",
);
});
}
}
#[test]
fn capture_enabled_returns_false_only_for_exact_lowercase_false() {
temp_env::with_var(DIFFLORE_CAPTURE_ENV, Some("false"), || {
assert!(
!capture_enabled(),
"exact lowercase \"false\" must disable capture",
);
});
}
}