From 98d88e06ff72993c1cf014c17a889c4738f36ee0 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sat, 8 Jul 2023 11:22:24 -0700 Subject: [PATCH] Use setlocale() in the test_convert test This "fixes" (or at least hides) the intermittent test_convert failures, as we no longer race with other setlocale calls. --- fish-rust/src/tests/string_escape.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/fish-rust/src/tests/string_escape.rs b/fish-rust/src/tests/string_escape.rs index d5a34cfc8..c6ed49485 100644 --- a/fish-rust/src/tests/string_escape.rs +++ b/fish-rust/src/tests/string_escape.rs @@ -6,15 +6,21 @@ use crate::wchar::{widestrs, wstr, WString}; use crate::wutil::encoding::{wcrtomb, zero_mbstate, AT_LEAST_MB_LEN_MAX}; use rand::{Rng, RngCore}; use rand_pcg::Pcg64Mcg; +use std::sync::Mutex; /// wcs2string is locale-dependent, so ensure we have a multibyte locale /// before using it in a test. -/// This is only needed for the variable escape function. fn setlocale() { + static LOCALE_LOCK: Mutex<()> = Mutex::new(()); + let _guard = LOCALE_LOCK.lock().unwrap(); + #[rustfmt::skip] const UTF8_LOCALES: &[&str] = &[ "C.UTF-8", "en_US.UTF-8", "en_GB.UTF-8", "de_DE.UTF-8", "C.utf8", "UTF-8", ]; + if crate::compat::MB_CUR_MAX() > 1 { + return; + } for locale in UTF8_LOCALES { let locale = std::ffi::CString::new(locale.to_owned()).unwrap(); unsafe { libc::setlocale(libc::LC_CTYPE, locale.as_ptr()) }; @@ -172,6 +178,7 @@ fn str2hex(input: &[u8]) -> String { /// string comes back through double conversion. #[test] fn test_convert() { + setlocale(); use rand::random; let seed: u128 = random::();