Skip to content

Commit 29d396b

Browse files
committed
fix: Make get_thousands_separator_uncached truly bypass locale cache
The test helper function get_thousands_separator_uncached() was calling get_numeric_locale() which uses OnceLock for permanent caching. This caused tests to fail intermittently on Ubuntu when test execution order varied, as the first test would cache its locale value and subsequent tests would receive that cached value instead of reading fresh env vars. Changes: - Made get_locale_from_env() pub(crate) in i18n/mod.rs - Updated get_thousands_separator_uncached() to call get_locale_from_env() directly instead of the cached get_numeric_locale() This ensures tests can properly change LC_NUMERIC environment variables and see the effects immediately without cache interference. Fixes Ubuntu test failures in: - test_get_thousands_separator (line 423) - test_format_with_thousands_separator_locale (line 383)
1 parent c6cb13e commit 29d396b

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

src/uucore/src/lib/features/format/human.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,9 @@ fn get_thousands_separator() -> char {
149149
fn get_thousands_separator_uncached() -> char {
150150
#[cfg(feature = "i18n-decimal")]
151151
{
152-
use crate::i18n::get_numeric_locale;
153-
let (locale, _encoding) = get_numeric_locale();
152+
use crate::i18n::get_locale_from_env;
153+
// Bypass the cache by calling get_locale_from_env directly
154+
let (locale, _encoding) = get_locale_from_env("LC_NUMERIC");
154155

155156
// C and POSIX locales have no thousands separator
156157
// The default locale from i18n is en-US-posix for C/POSIX

src/uucore/src/lib/features/i18n/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const DEFAULT_LOCALE: Locale = locale!("en-US-posix");
2929
/// 3. LANG
3030
///
3131
/// Or fallback on Posix locale, with ASCII encoding.
32-
fn get_locale_from_env(locale_name: &str) -> (Locale, UEncoding) {
32+
pub(crate) fn get_locale_from_env(locale_name: &str) -> (Locale, UEncoding) {
3333
let locale_var = ["LC_ALL", locale_name, "LANG"]
3434
.iter()
3535
.find_map(|&key| std::env::var(key).ok());

0 commit comments

Comments
 (0)