Skip to content

Commit 2a1b960

Browse files
committed
test: fix musl libc test fail due to locale differences
The 'nvme-cli - uint128' test was failing when build with musl libc. The reason was that musl libc leaves the thousands separator from LC_NUMERIC empty with the fr_FR.utf-8. This patch offers a solution by skipping the test with a warning if the thousands separator cannot be obtained. Signed-off-by: Michal Rábek <[email protected]>
1 parent 11f406d commit 2a1b960

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

unit/test-uint128.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,30 @@ static struct tostr_test tostr_tests[] = {
4949
void tostr_test(struct tostr_test *test)
5050
{
5151
char *str;
52+
const char *exp = test->exp;
5253

5354
if (!setlocale(LC_NUMERIC, test->locale))
5455
return;
5556

56-
if (test->locale)
57+
if (test->locale) {
58+
/* For locale tests, adapt to what the system provides.
59+
* musl libc may not support thousands_sep for all locales. */
60+
struct lconv *lc = localeconv();
61+
const char *sep = lc->thousands_sep;
62+
63+
if (!sep || !*sep) {
64+
/* No separator available, skip test */
65+
fprintf(stderr, "WARNING: thousands_sep is empty for this "
66+
"system's %s locale! Skipping test...\n",
67+
test->locale);
68+
return;
69+
}
5770
str = uint128_t_to_l10n_string(test->val);
58-
else
71+
} else {
5972
str = uint128_t_to_string(test->val);
73+
}
6074

61-
check_str(test->val, test->exp, str);
75+
check_str(test->val, exp, str);
6276
}
6377

6478
int main(void)

0 commit comments

Comments
 (0)