[libcxx][test] Portability fix for some locale-dependent tests.
authorLouis Dionne <ldionne@apple.com>
Thu, 14 May 2020 13:37:46 +0000 (09:37 -0400)
committerLouis Dionne <ldionne@apple.com>
Wed, 20 May 2020 18:35:18 +0000 (14:35 -0400)
Tests for `std::system_error` constructor marked as slightly non-portable.
One (but not the only one) reason for such non-portability is that these
tests assume the default locale to be set to "C" (or "POSIX").

However, the default locale for the process depends on OS and
environment. This patch adds explicit setting of the correct
locale expected by the tests.

Thanks to Andrey Maksimov for the patch.

Differential Revision: https://reviews.llvm.org/D72456

libcxx/test/std/diagnostics/syserr/syserr.syserr/syserr.syserr.members/ctor_error_code.pass.cpp
libcxx/test/std/diagnostics/syserr/syserr.syserr/syserr.syserr.members/ctor_error_code_const_char_pointer.pass.cpp
libcxx/test/std/diagnostics/syserr/syserr.syserr/syserr.syserr.members/ctor_error_code_string.pass.cpp
libcxx/test/std/diagnostics/syserr/syserr.syserr/syserr.syserr.members/ctor_int_error_category.pass.cpp
libcxx/test/std/diagnostics/syserr/syserr.syserr/syserr.syserr.members/ctor_int_error_category_const_char_pointer.pass.cpp
libcxx/test/std/diagnostics/syserr/syserr.syserr/syserr.syserr.members/ctor_int_error_category_string.pass.cpp

index c011c5a..2bd8467 100644 (file)
 #include <system_error>
 #include <string>
 #include <cassert>
+#include <clocale>
 
 #include "test_macros.h"
 
 int main(int, char**)
 {
+    std::setlocale (LC_ALL, "C");
     std::system_error se(static_cast<int>(std::errc::not_a_directory),
                          std::generic_category(), "some text");
     assert(se.code() == std::make_error_code(std::errc::not_a_directory));
index ee679ae..86f4781 100644 (file)
 #include <system_error>
 #include <string>
 #include <cassert>
+#include <clocale>
 
 #include "test_macros.h"
 
 int main(int, char**)
 {
+    std::setlocale (LC_ALL, "C");
     std::string what_arg("test message");
     std::system_error se(make_error_code(std::errc::not_a_directory), what_arg.c_str());
     assert(se.code() == std::make_error_code(std::errc::not_a_directory));
index a7df85b..0bb3428 100644 (file)
 #include <system_error>
 #include <string>
 #include <cassert>
+#include <clocale>
 
 #include "test_macros.h"
 
 int main(int, char**)
 {
+    std::setlocale (LC_ALL, "C");
     std::string what_arg("test message");
     std::system_error se(make_error_code(std::errc::not_a_directory), what_arg);
     assert(se.code() == std::make_error_code(std::errc::not_a_directory));
index 153342f..bce564f 100644 (file)
 #include <system_error>
 #include <string>
 #include <cassert>
+#include <clocale>
 
 #include "test_macros.h"
 
 int main(int, char**)
 {
+    std::setlocale (LC_ALL, "C");
     std::system_error se(static_cast<int>(std::errc::not_a_directory),
                          std::generic_category());
     assert(se.code() == std::make_error_code(std::errc::not_a_directory));
index 89a4ec3..39e6958 100644 (file)
 #include <system_error>
 #include <string>
 #include <cassert>
+#include <clocale>
 
 #include "test_macros.h"
 
 int main(int, char**)
 {
+    std::setlocale (LC_ALL, "C");
     std::string what_arg("test message");
     std::system_error se(static_cast<int>(std::errc::not_a_directory),
                          std::generic_category(), what_arg.c_str());
index 0eb96a4..eac6ecf 100644 (file)
 #include <system_error>
 #include <string>
 #include <cassert>
+#include <clocale>
 
 #include "test_macros.h"
 
 int main(int, char**)
 {
+    std::setlocale (LC_ALL, "C");
     std::string what_arg("test message");
     std::system_error se(static_cast<int>(std::errc::not_a_directory),
                          std::generic_category(), what_arg);