nu_test_support::locale_override

Function with_locale_override

Source
pub fn with_locale_override<T>(locale_string: &str, func: fn() -> T) -> T
Expand description

Run a closure in a fake locale environment.

Before the closure is executed, an environment variable whose name is defined in nu_utils::locale::LOCALE_OVERRIDE_ENV_VAR is set to the value provided by locale_string. When the closure is done, the previous value is restored.

Environment variables are global values. So when they are changed by one thread they are changed for all others. To prevent a test from overwriting the environment variable of another test, a mutex is used.