pub(crate) fn cargo_test_mode_active() -> bool {
std::env::var("KTSTR_CARGO_TEST_MODE")
.map(|v| !v.is_empty())
.unwrap_or(false)
}
#[cfg(test)]
mod tests {
use super::*;
use crate::test_support::test_helpers::{EnvVarGuard, lock_env};
#[test]
fn cargo_test_mode_active_set_non_empty() {
let _lock = lock_env();
let _env = EnvVarGuard::set("KTSTR_CARGO_TEST_MODE", "1");
assert!(cargo_test_mode_active());
let _env_word = EnvVarGuard::set("KTSTR_CARGO_TEST_MODE", "yes");
assert!(cargo_test_mode_active());
}
#[test]
fn cargo_test_mode_active_empty_string_rejected() {
let _lock = lock_env();
let _env = EnvVarGuard::set("KTSTR_CARGO_TEST_MODE", "");
assert!(
!cargo_test_mode_active(),
"empty-string KTSTR_CARGO_TEST_MODE must NOT activate; \
treating it as truthy would silently degrade SHM / \
flock coordination on a stray `--env` pass-through"
);
}
#[test]
fn cargo_test_mode_active_unset() {
let _lock = lock_env();
let _env = EnvVarGuard::remove("KTSTR_CARGO_TEST_MODE");
assert!(!cargo_test_mode_active());
}
#[test]
fn cargo_test_mode_active_zero_string_activates_per_non_empty_contract() {
let _lock = lock_env();
let _env = EnvVarGuard::set("KTSTR_CARGO_TEST_MODE", "0");
assert!(
cargo_test_mode_active(),
"\"0\" is non-empty so the bypass activates per the \
documented contract; if you expect the C-style \
\"0=off\" semantic, the doc + predicate must change \
together"
);
}
}