From 915335fd768965c8a3db7ab902bc59ff7824693b Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Sun, 25 Feb 2024 17:10:08 +0200 Subject: [PATCH] tests: check setlocale return value It might fail while nl_langinfo does not. --- lib/utils/mu-test-utils.cc | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/utils/mu-test-utils.cc b/lib/utils/mu-test-utils.cc index 8df132379..0d4a149b5 100644 --- a/lib/utils/mu-test-utils.cc +++ b/lib/utils/mu-test-utils.cc @@ -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; }