Skip to content

Commit

Permalink
tests: check setlocale return value
Browse files Browse the repository at this point in the history
It might fail while nl_langinfo does not.
  • Loading branch information
djcb committed Feb 25, 2024
1 parent 5b65717 commit 915335f
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions lib/utils/mu-test-utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,12 @@ bool
Mu::set_en_us_utf8_locale()
{
setenv("LC_ALL", "en_US.UTF-8", 1);
setlocale(LC_ALL, "en_US.UTF-8");

if (strcmp(nl_langinfo(CODESET), "UTF-8") != 0) {
/* LCOV_EXCL_START*/
mu_println("Note: Unit tests require the en_US.utf8 locale. "
"Ignoring test cases.");
/* LCOV_EXCL_STOP*/
if (auto str = setlocale(LC_ALL, "en_US.UTF-8"); !str)
return false;

if (strcmp(nl_langinfo(CODESET), "UTF-8") != 0)
return false;
}

return true;
}
Expand Down

0 comments on commit 915335f

Please sign in to comment.