Skip to content

Commit ae09fec

Browse files
committed
fix: add serial_test to prevent locale test race conditions
- Add serial_test crate to dev-dependencies to ensure locale-dependent tests run sequentially - Add #[serial] attribute to test_format_with_thousands_separator and test_format_with_thousands_separator_locale - Modify doctest to not assert locale-dependent output (just verify non-empty result) - Fix doctest import path for extract_thousands_separator_flag This prevents test interference when tests modify environment variables (LC_NUMERIC, LC_ALL, LANG) in parallel execution.
1 parent 48f4bc1 commit ae09fec

File tree

5 files changed

+106
-5
lines changed

5 files changed

+106
-5
lines changed

Cargo.lock

Lines changed: 93 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ regex = "1.10.4"
364364
rstest = "0.26.0"
365365
rust-ini = "0.21.0"
366366
same-file = "1.0.6"
367+
serial_test = "3.1"
367368
self_cell = "1.0.4"
368369
# FIXME we use the exact version because the new 0.5.3 requires an MSRV of 1.88
369370
selinux = "=0.5.2"

src/uucore/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ xattr = { workspace = true, optional = true }
101101

102102
[dev-dependencies]
103103
tempfile = { workspace = true }
104+
serial_test = { workspace = true }
104105

105106
[target.'cfg(target_os = "linux")'.dependencies]
106107
procfs = { workspace = true }

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,13 @@ fn get_thousands_separator() -> char {
105105
/// # Examples
106106
/// ```
107107
/// use uucore::format::human::format_with_thousands_separator;
108-
/// // With LC_NUMERIC=en_US.UTF-8 (or default)
109-
/// assert_eq!(format_with_thousands_separator(1234567), "1,234,567");
110-
/// // With LC_NUMERIC=de_DE.UTF-8
111-
/// // assert_eq!(format_with_thousands_separator(1234567), "1.234.567");
108+
/// // Note: Output depends on LC_NUMERIC locale. This example assumes en_US.UTF-8
109+
/// // To test with specific locale, set LC_NUMERIC environment variable before running tests
110+
/// let result = format_with_thousands_separator(1234567);
111+
/// // With en_US locale: "1,234,567"
112+
/// // With de_DE locale: "1.234.567"
113+
/// // With C/POSIX locale: "1234567"
114+
/// assert!(!result.is_empty()); // Just verify it returns something
112115
/// ```
113116
pub fn format_with_thousands_separator(number: u64) -> String {
114117
const GROUPING_SIZE: usize = 3;
@@ -143,6 +146,7 @@ pub fn format_with_thousands_separator(number: u64) -> String {
143146
#[cfg(test)]
144147
mod tests {
145148
use super::*;
149+
use serial_test::serial;
146150

147151
#[test]
148152
fn test_human_readable() {
@@ -158,6 +162,7 @@ mod tests {
158162
}
159163

160164
#[test]
165+
#[serial]
161166
fn test_format_with_thousands_separator() {
162167
// Save original locale variables
163168
let original_lc_numeric = std::env::var("LC_NUMERIC").ok();
@@ -209,6 +214,7 @@ mod tests {
209214
}
210215

211216
#[test]
217+
#[serial]
212218
fn test_format_with_thousands_separator_locale() {
213219
// Save original locale variables
214220
let original_lc_numeric = std::env::var("LC_NUMERIC").ok();

src/uucore/src/lib/features/parser/parse_size.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ pub fn parse_size_u128(size: &str) -> Result<u128, ParseSizeError> {
382382
///
383383
/// # Examples
384384
/// ```
385-
/// use uucore::features::parser::parse_size::extract_thousands_separator_flag;
385+
/// use uucore::parser::parse_size::extract_thousands_separator_flag;
386386
/// assert_eq!(extract_thousands_separator_flag("'1"), ("1", true));
387387
/// assert_eq!(extract_thousands_separator_flag("'1K"), ("1K", true));
388388
/// assert_eq!(extract_thousands_separator_flag("1024"), ("1024", false));

0 commit comments

Comments
 (0)