[libcxx-commits] [libcxx] fedbd26 - [libc++][nfc] Add TEST_HAS_NO_LOCALIZATION.

Mark de Wever via libcxx-commits libcxx-commits at lists.llvm.org
Thu Feb 10 08:44:42 PST 2022


Author: Mark de Wever
Date: 2022-02-10T17:44:37+01:00
New Revision: fedbd264e39ba36022f208c4612da472cae0953f

URL: https://github.com/llvm/llvm-project/commit/fedbd264e39ba36022f208c4612da472cae0953f
DIFF: https://github.com/llvm/llvm-project/commit/fedbd264e39ba36022f208c4612da472cae0953f.diff

LOG: [libc++][nfc] Add TEST_HAS_NO_LOCALIZATION.

This avoids using an libc++ internal macro in our tests.

Reviewed By: #libc, ldionne

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

Added: 
    

Modified: 
    libcxx/test/std/input.output/filesystems/class.path/path.nonmember/path.factory.pass.cpp
    libcxx/test/std/iterators/iterator.primitives/iterator.traits/cxx20_iterator_traits.compile.pass.cpp
    libcxx/test/std/utilities/format/format.formatter/format.context/format.context/ctor.pass.cpp
    libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.floating_point.pass.cpp
    libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/types.compile.pass.cpp
    libcxx/test/std/utilities/format/format.functions/format.pass.cpp
    libcxx/test/support/test_macros.h

Removed: 
    


################################################################################
diff  --git a/libcxx/test/std/input.output/filesystems/class.path/path.nonmember/path.factory.pass.cpp b/libcxx/test/std/input.output/filesystems/class.path/path.nonmember/path.factory.pass.cpp
index 3c253ac157c15..be502a782a970 100644
--- a/libcxx/test/std/input.output/filesystems/class.path/path.nonmember/path.factory.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/class.path/path.nonmember/path.factory.pass.cpp
@@ -49,8 +49,7 @@ int main(int, char**)
     path p = fs::u8path(In3, In3End);
     assert(p == In1);
   }
-#if TEST_STD_VER > 17 && defined(__cpp_char8_t) && defined(_LIBCPP_VERSION) && \
-    !defined(_LIBCPP_HAS_NO_LOCALIZATION)
+#if TEST_STD_VER > 17 && defined(__cpp_char8_t) && defined(_LIBCPP_VERSION) && !defined(TEST_HAS_NO_LOCALIZATION)
   const char8_t* u8In1 = u8"abcd/efg";
   const std::u8string u8In2(u8In1);
   const auto u8In3 = u8In2.begin();

diff  --git a/libcxx/test/std/iterators/iterator.primitives/iterator.traits/cxx20_iterator_traits.compile.pass.cpp b/libcxx/test/std/iterators/iterator.primitives/iterator.traits/cxx20_iterator_traits.compile.pass.cpp
index 4cc64b0638de2..15c2793d7dae6 100644
--- a/libcxx/test/std/iterators/iterator.primitives/iterator.traits/cxx20_iterator_traits.compile.pass.cpp
+++ b/libcxx/test/std/iterators/iterator.primitives/iterator.traits/cxx20_iterator_traits.compile.pass.cpp
@@ -33,10 +33,12 @@
 #include <unordered_set>
 #include <vector>
 
-#ifndef _LIBCPP_HAS_NO_LOCALIZATION
-# include <regex>
-# include <ostream>
-# include <istream>
+#include "test_macros.h"
+
+#ifndef TEST_HAS_NO_LOCALIZATION
+#  include <regex>
+#  include <ostream>
+#  include <istream>
 #endif
 
 #ifndef _LIBCPP_HAS_NO_FILESYSTEM_LIBRARY
@@ -199,14 +201,14 @@ static_assert(testIOIterator<std::front_insert_iterator<std::vector<int>>, std::
 static_assert(testIOIterator<std::insert_iterator<std::vector<int>>, std::output_iterator_tag>());
 static_assert(testConstWithoutConcept<std::istream_iterator<int, char>, int, std::input_iterator_tag>());
 
-#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
+#if !defined(TEST_HAS_NO_LOCALIZATION)
 static_assert(testWithoutConcept<std::istreambuf_iterator<char>, char, long long, char, char*, std::input_iterator_tag>());
 static_assert(testWithoutConcept<std::move_iterator<int*>, int, std::ptr
diff _t, int&&, int*, std::random_access_iterator_tag>());
 static_assert(testIOIterator<std::ostream_iterator<int, char>, std::output_iterator_tag>());
 static_assert(testIOIterator<std::ostreambuf_iterator<int, char>, std::output_iterator_tag>());
 static_assert(testConstWithoutConcept<std::cregex_iterator, std::cmatch, std::forward_iterator_tag>());
 static_assert(testConstWithoutConcept<std::cregex_token_iterator, std::csub_match, std::forward_iterator_tag>());
-#endif // !_LIBCPP_HAS_NO_LOCALIZATION
+#endif // !TEST_HAS_NO_LOCALIZATION
 
 #ifndef _LIBCPP_HAS_NO_FILESYSTEM_LIBRARY
 static_assert(testWithoutConcept<std::filesystem::directory_iterator, std::filesystem::directory_entry, std::ptr
diff _t,

diff  --git a/libcxx/test/std/utilities/format/format.formatter/format.context/format.context/ctor.pass.cpp b/libcxx/test/std/utilities/format/format.formatter/format.context/format.context/ctor.pass.cpp
index a0edd38ee3e7e..049672f30f1db 100644
--- a/libcxx/test/std/utilities/format/format.formatter/format.context/format.context/ctor.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.formatter/format.context/format.context/ctor.pass.cpp
@@ -72,12 +72,12 @@ void test() {
     assert(output.size() == 1);
     assert(output.front() == CharT('a'));
 
-#ifndef _LIBCPP_HAS_NO_LOCALIZATION
+#ifndef TEST_HAS_NO_LOCALIZATION
     assert(context.locale() == std::locale());
 #endif
   }
 
-#ifndef _LIBCPP_HAS_NO_LOCALIZATION
+#ifndef TEST_HAS_NO_LOCALIZATION
   std::locale en_US{LOCALE_en_US_UTF_8};
   std::locale fr_FR{LOCALE_fr_FR_UTF_8};
   {

diff  --git a/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.floating_point.pass.cpp b/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.floating_point.pass.cpp
index 0e8e95d2762f6..1934471794dcc 100644
--- a/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.floating_point.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/formatter.floating_point.pass.cpp
@@ -97,7 +97,7 @@ void test_hex_lower_case_precision(ArithmeticT value) {
     buffer[size] = '0';
   }
   test_termination_condition(STR("025000.20000a}"), value, std::basic_string<CharT>{buffer.begin(), buffer.end()});
-#ifndef _LIBCPP_HAS_NO_LOCALIZATION
+#ifndef TEST_HAS_NO_LOCALIZATION
   end = std::to_chars(buffer.begin(), buffer.end(), value, std::chars_format::hex, 20'000).ptr;
   test_termination_condition(STR(".20000La}"), value, std::basic_string<CharT>{buffer.begin(), end});
 
@@ -137,7 +137,7 @@ void test_hex_upper_case_precision(ArithmeticT value) {
     buffer[size] = '0';
   }
   test_termination_condition(STR("025000.20000A}"), value, std::basic_string<CharT>{buffer.begin(), buffer.end()});
-#ifndef _LIBCPP_HAS_NO_LOCALIZATION
+#ifndef TEST_HAS_NO_LOCALIZATION
   end = std::to_chars(buffer.begin(), buffer.end(), value, std::chars_format::hex, 20'000).ptr;
   std::transform(buffer.begin(), end, buffer.begin(), [](char c) { return std::toupper(c); });
   test_termination_condition(STR(".20000LA}"), value, std::basic_string<CharT>{buffer.begin(), end});
@@ -177,7 +177,7 @@ void test_scientific_lower_case_precision(ArithmeticT value) {
     buffer[size] = '0';
   }
   test_termination_condition(STR("025000.20000e}"), value, std::basic_string<CharT>{buffer.begin(), buffer.end()});
-#ifndef _LIBCPP_HAS_NO_LOCALIZATION
+#ifndef TEST_HAS_NO_LOCALIZATION
   end = std::to_chars(buffer.begin(), buffer.end(), value, std::chars_format::scientific, 20'000).ptr;
   test_termination_condition(STR(".20000Le}"), value, std::basic_string<CharT>{buffer.begin(), end});
 
@@ -217,7 +217,7 @@ void test_scientific_upper_case_precision(ArithmeticT value) {
     buffer[size] = '0';
   }
   test_termination_condition(STR("025000.20000E}"), value, std::basic_string<CharT>{buffer.begin(), buffer.end()});
-#ifndef _LIBCPP_HAS_NO_LOCALIZATION
+#ifndef TEST_HAS_NO_LOCALIZATION
   end = std::to_chars(buffer.begin(), buffer.end(), value, std::chars_format::scientific, 20'000).ptr;
   std::transform(buffer.begin(), end, buffer.begin(), [](char c) { return std::toupper(c); });
   test_termination_condition(STR(".20000LE}"), value, std::basic_string<CharT>{buffer.begin(), end});
@@ -257,7 +257,7 @@ void test_fixed_lower_case_precision(ArithmeticT value) {
     buffer[size] = '0';
   }
   test_termination_condition(STR("025000.20000f}"), value, std::basic_string<CharT>{buffer.begin(), buffer.end()});
-#ifndef _LIBCPP_HAS_NO_LOCALIZATION
+#ifndef TEST_HAS_NO_LOCALIZATION
   end = std::to_chars(buffer.begin(), buffer.end(), value, std::chars_format::fixed, 20'000).ptr;
   test_termination_condition(STR(".20000Lf}"), value, std::basic_string<CharT>{buffer.begin(), end});
 
@@ -297,7 +297,7 @@ void test_fixed_upper_case_precision(ArithmeticT value) {
     buffer[size] = '0';
   }
   test_termination_condition(STR("025000.20000F}"), value, std::basic_string<CharT>{buffer.begin(), buffer.end()});
-#ifndef _LIBCPP_HAS_NO_LOCALIZATION
+#ifndef TEST_HAS_NO_LOCALIZATION
   end = std::to_chars(buffer.begin(), buffer.end(), value, std::chars_format::fixed, 20'000).ptr;
   std::transform(buffer.begin(), end, buffer.begin(), [](char c) { return std::toupper(c); });
   test_termination_condition(STR(".20000LF}"), value, std::basic_string<CharT>{buffer.begin(), end});
@@ -337,7 +337,7 @@ void test_general_lower_case_precision(ArithmeticT value) {
     buffer[size] = '0';
   }
   test_termination_condition(STR("025000.20000g}"), value, std::basic_string<CharT>{buffer.begin(), buffer.end()});
-#ifndef _LIBCPP_HAS_NO_LOCALIZATION
+#ifndef TEST_HAS_NO_LOCALIZATION
   end = std::to_chars(buffer.begin(), buffer.end(), value, std::chars_format::general, 20'000).ptr;
   test_termination_condition(STR(".20000Lg}"), value, std::basic_string<CharT>{buffer.begin(), end});
 
@@ -377,7 +377,7 @@ void test_general_upper_case_precision(ArithmeticT value) {
     buffer[size] = '0';
   }
   test_termination_condition(STR("025000.20000G}"), value, std::basic_string<CharT>{buffer.begin(), buffer.end()});
-#ifndef _LIBCPP_HAS_NO_LOCALIZATION
+#ifndef TEST_HAS_NO_LOCALIZATION
   end = std::to_chars(buffer.begin(), buffer.end(), value, std::chars_format::general, 20'000).ptr;
   std::transform(buffer.begin(), end, buffer.begin(), [](char c) { return std::toupper(c); });
   test_termination_condition(STR(".20000LG}"), value, std::basic_string<CharT>{buffer.begin(), end});

diff  --git a/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/types.compile.pass.cpp b/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/types.compile.pass.cpp
index 522a583f349cb..fcddf832df2c9 100644
--- a/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/types.compile.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.formatter/format.formatter.spec/types.compile.pass.cpp
@@ -33,9 +33,6 @@
 #include <map>
 #include <optional>
 #include <queue>
-#ifndef _LIBCPP_HAS_NO_LOCALIZATION
-#  include <regex>
-#endif
 #include <set>
 #include <stack>
 #include <span>
@@ -51,6 +48,10 @@
 
 #include "test_macros.h"
 
+#ifndef TEST_HAS_NO_LOCALIZATION
+#  include <regex>
+#endif
+
 // Validate default template argument.
 static_assert(std::same_as<std::formatter<int>, std::formatter<int, char>>);
 
@@ -213,7 +214,7 @@ void test_P1636() {
   assert_formatter_is_disabled<std::filesystem::path, CharT>();
 #endif
   assert_formatter_is_disabled<std::shared_ptr<int>, CharT>();
-#ifndef _LIBCPP_HAS_NO_LOCALIZATION
+#ifndef TEST_HAS_NO_LOCALIZATION
   assert_formatter_is_disabled<std::sub_match<CharT*>, CharT>();
 #endif
 #ifndef _LIBCPP_HAS_NO_THREADS

diff  --git a/libcxx/test/std/utilities/format/format.functions/format.pass.cpp b/libcxx/test/std/utilities/format/format.functions/format.pass.cpp
index bbd43f7b7c526..5fbdbdd32aaff 100644
--- a/libcxx/test/std/utilities/format/format.functions/format.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.functions/format.pass.cpp
@@ -24,18 +24,19 @@
 
 #include <format>
 #include <cassert>
-#ifndef _LIBCPP_HAS_NO_LOCALIZATION
-#  include <iostream>
-#endif
 #include <vector>
 
 #include "test_macros.h"
 #include "format_tests.h"
 
+#ifndef TEST_HAS_NO_LOCALIZATION
+#  include <iostream>
+#endif
+
 auto test = []<class CharT, class... Args>(std::basic_string_view<CharT> expected, std::basic_string_view<CharT> fmt,
                                            const Args&... args) {
   std::basic_string<CharT> out = std::format(fmt, args...);
-#ifndef _LIBCPP_HAS_NO_LOCALIZATION
+#ifndef TEST_HAS_NO_LOCALIZATION
   if constexpr (std::same_as<CharT, char>)
     if (out != expected)
       std::cerr << "\nFormat string   " << fmt << "\nExpected output " << expected << "\nActual output   " << out
@@ -49,14 +50,14 @@ auto test_exception = []<class CharT, class... Args>(std::string_view what, std:
 #ifndef TEST_HAS_NO_EXCEPTIONS
   try {
     std::format(fmt, args...);
-#  ifndef _LIBCPP_HAS_NO_LOCALIZATION
+#  ifndef TEST_HAS_NO_LOCALIZATION
     if constexpr (std::same_as<CharT, char>)
       std::cerr << "\nFormat string   " << fmt << "\nDidn't throw an exception.\n";
 #  endif
     assert(false);
   } catch (const std::format_error& e) {
-#  if defined(_LIBCPP_VERSION) && !defined(_LIBCPP_HAS_NO_LOCALIZATION)
     if constexpr (std::same_as<CharT, char>)
+#  if defined(_LIBCPP_VERSION) && !defined(TEST_HAS_NO_LOCALIZATION)
       if (e.what() != what)
         std::cerr << "\nFormat string   " << fmt << "\nExpected exception " << what << "\nActual exception   "
                   << e.what() << '\n';

diff  --git a/libcxx/test/support/test_macros.h b/libcxx/test/support/test_macros.h
index f65d0e13d15f1..c3794ab4685dd 100644
--- a/libcxx/test/support/test_macros.h
+++ b/libcxx/test/support/test_macros.h
@@ -376,6 +376,10 @@ inline void DoNotOptimize(Tp const& value) {
 #   define TEST_HAS_NO_UNICODE_CHARS
 #endif
 
+#if defined(_LIBCPP_HAS_NO_LOCALIZATION)
+#  define TEST_HAS_NO_LOCALIZATION
+#endif
+
 #if defined(__GNUC__)
 #pragma GCC diagnostic pop
 #endif


        


More information about the libcxx-commits mailing list