pub struct LocaleOverride { /* private fields */ }Expand description
Guard that overrides DYLINT_LOCALE for the lifetime of the instance.
The guard captures any existing value and restores it when dropped. The
mutation itself must be executed under a serialized test harness (for
example via the serial_test::serial attribute) to ensure the unsafe
environment access remains race-free.
§Examples
ⓘ
use whitaker_common::test_support::LocaleOverride;
use serial_test::serial;
#[test]
#[serial]
fn ui_runs_in_welsh_locale() {
let _guard = LocaleOverride::set("cy");
// Execute lint UI harness here.
}Implementations§
Source§impl LocaleOverride
impl LocaleOverride
Sourcepub fn set(locale: &str) -> Self
pub fn set(locale: &str) -> Self
Sets DYLINT_LOCALE to locale, returning a guard that will restore
the prior value (if any) when dropped.
Sourcepub fn clear() -> Self
pub fn clear() -> Self
Removes DYLINT_LOCALE, returning a guard that reinstates the prior
value (if any) when dropped.
§Examples
ⓘ
use whitaker_common::test_support::LocaleOverride;
use serial_test::serial;
use std::ffi::OsString;
#[test]
#[serial]
fn clears_then_restores_locale() {
unsafe {
std::env::set_var("DYLINT_LOCALE", "cy");
}
{
let _guard = LocaleOverride::clear();
assert!(std::env::var_os("DYLINT_LOCALE").is_none());
}
assert_eq!(
std::env::var_os("DYLINT_LOCALE"),
Some(OsString::from("cy"))
);
}Trait Implementations§
Source§impl Drop for LocaleOverride
impl Drop for LocaleOverride
Auto Trait Implementations§
impl Freeze for LocaleOverride
impl RefUnwindSafe for LocaleOverride
impl Send for LocaleOverride
impl Sync for LocaleOverride
impl Unpin for LocaleOverride
impl UnsafeUnpin for LocaleOverride
impl UnwindSafe for LocaleOverride
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more