From 9f19cc8cac893a887e1952ce764bb6b09a6785df Mon Sep 17 00:00:00 2001 From: Louis Dionne Date: Thu, 14 May 2020 09:37:46 -0400 Subject: [PATCH] [libcxx][test] Portability fix for some locale-dependent tests. 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 --- .../syserr.syserr.members/ctor_error_code.pass.cpp | 2 ++ .../ctor_error_code_const_char_pointer.pass.cpp | 2 ++ .../syserr.syserr.members/ctor_error_code_string.pass.cpp | 2 ++ .../syserr.syserr.members/ctor_int_error_category.pass.cpp | 2 ++ .../ctor_int_error_category_const_char_pointer.pass.cpp | 2 ++ .../ctor_int_error_category_string.pass.cpp | 2 ++ 6 files changed, 12 insertions(+) diff --git a/libcxx/test/std/diagnostics/syserr/syserr.syserr/syserr.syserr.members/ctor_error_code.pass.cpp b/libcxx/test/std/diagnostics/syserr/syserr.syserr/syserr.syserr.members/ctor_error_code.pass.cpp index c011c5a5afcf..2bd84677c9ad 100644 --- a/libcxx/test/std/diagnostics/syserr/syserr.syserr/syserr.syserr.members/ctor_error_code.pass.cpp +++ b/libcxx/test/std/diagnostics/syserr/syserr.syserr/syserr.syserr.members/ctor_error_code.pass.cpp @@ -17,11 +17,13 @@ #include #include #include +#include #include "test_macros.h" int main(int, char**) { + std::setlocale (LC_ALL, "C"); std::system_error se(static_cast(std::errc::not_a_directory), std::generic_category(), "some text"); assert(se.code() == std::make_error_code(std::errc::not_a_directory)); diff --git a/libcxx/test/std/diagnostics/syserr/syserr.syserr/syserr.syserr.members/ctor_error_code_const_char_pointer.pass.cpp b/libcxx/test/std/diagnostics/syserr/syserr.syserr/syserr.syserr.members/ctor_error_code_const_char_pointer.pass.cpp index ee679ae4a4a8..86f47816dc69 100644 --- a/libcxx/test/std/diagnostics/syserr/syserr.syserr/syserr.syserr.members/ctor_error_code_const_char_pointer.pass.cpp +++ b/libcxx/test/std/diagnostics/syserr/syserr.syserr/syserr.syserr.members/ctor_error_code_const_char_pointer.pass.cpp @@ -17,11 +17,13 @@ #include #include #include +#include #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)); diff --git a/libcxx/test/std/diagnostics/syserr/syserr.syserr/syserr.syserr.members/ctor_error_code_string.pass.cpp b/libcxx/test/std/diagnostics/syserr/syserr.syserr/syserr.syserr.members/ctor_error_code_string.pass.cpp index a7df85bcb642..0bb3428e8007 100644 --- a/libcxx/test/std/diagnostics/syserr/syserr.syserr/syserr.syserr.members/ctor_error_code_string.pass.cpp +++ b/libcxx/test/std/diagnostics/syserr/syserr.syserr/syserr.syserr.members/ctor_error_code_string.pass.cpp @@ -17,11 +17,13 @@ #include #include #include +#include #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)); diff --git a/libcxx/test/std/diagnostics/syserr/syserr.syserr/syserr.syserr.members/ctor_int_error_category.pass.cpp b/libcxx/test/std/diagnostics/syserr/syserr.syserr/syserr.syserr.members/ctor_int_error_category.pass.cpp index 153342f68a23..bce564fe95b0 100644 --- a/libcxx/test/std/diagnostics/syserr/syserr.syserr/syserr.syserr.members/ctor_int_error_category.pass.cpp +++ b/libcxx/test/std/diagnostics/syserr/syserr.syserr/syserr.syserr.members/ctor_int_error_category.pass.cpp @@ -17,11 +17,13 @@ #include #include #include +#include #include "test_macros.h" int main(int, char**) { + std::setlocale (LC_ALL, "C"); std::system_error se(static_cast(std::errc::not_a_directory), std::generic_category()); assert(se.code() == std::make_error_code(std::errc::not_a_directory)); diff --git a/libcxx/test/std/diagnostics/syserr/syserr.syserr/syserr.syserr.members/ctor_int_error_category_const_char_pointer.pass.cpp b/libcxx/test/std/diagnostics/syserr/syserr.syserr/syserr.syserr.members/ctor_int_error_category_const_char_pointer.pass.cpp index 89a4ec3cca2a..39e6958192a8 100644 --- a/libcxx/test/std/diagnostics/syserr/syserr.syserr/syserr.syserr.members/ctor_int_error_category_const_char_pointer.pass.cpp +++ b/libcxx/test/std/diagnostics/syserr/syserr.syserr/syserr.syserr.members/ctor_int_error_category_const_char_pointer.pass.cpp @@ -17,11 +17,13 @@ #include #include #include +#include #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(std::errc::not_a_directory), std::generic_category(), what_arg.c_str()); diff --git a/libcxx/test/std/diagnostics/syserr/syserr.syserr/syserr.syserr.members/ctor_int_error_category_string.pass.cpp b/libcxx/test/std/diagnostics/syserr/syserr.syserr/syserr.syserr.members/ctor_int_error_category_string.pass.cpp index 0eb96a41c43a..eac6ecf43977 100644 --- a/libcxx/test/std/diagnostics/syserr/syserr.syserr/syserr.syserr.members/ctor_int_error_category_string.pass.cpp +++ b/libcxx/test/std/diagnostics/syserr/syserr.syserr/syserr.syserr.members/ctor_int_error_category_string.pass.cpp @@ -17,11 +17,13 @@ #include #include #include +#include #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(std::errc::not_a_directory), std::generic_category(), what_arg);