[lib++][format] Uses the new exception test macros.
authorMark de Wever <koraq@xs4all.nl>
Sat, 21 Jan 2023 12:35:30 +0000 (13:35 +0100)
committerMark de Wever <koraq@xs4all.nl>
Fri, 17 Feb 2023 17:53:14 +0000 (18:53 +0100)
Reviewed By: #libc, ldionne

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

libcxx/test/std/containers/container.adaptors/container.adaptors.format/format.functions.vformat.pass.cpp
libcxx/test/std/containers/sequences/vector.bool/vector.bool.fmt/format.functions.vformat.pass.cpp
libcxx/test/std/utilities/format/format.functions/vformat.locale.pass.cpp
libcxx/test/std/utilities/format/format.functions/vformat.pass.cpp
libcxx/test/std/utilities/format/format.functions/vformat_to.locale.pass.cpp
libcxx/test/std/utilities/format/format.functions/vformat_to.pass.cpp
libcxx/test/std/utilities/format/format.range/format.range.fmtmap/format.functions.vformat.pass.cpp
libcxx/test/std/utilities/format/format.range/format.range.fmtset/format.functions.vformat.pass.cpp
libcxx/test/std/utilities/format/format.range/format.range.formatter/format.functions.vformat.pass.cpp
libcxx/test/std/utilities/format/format.tuple/format.functions.vformat.pass.cpp

index e74144e..a7136e7 100644 (file)
@@ -47,20 +47,15 @@ auto test_exception =
         [[maybe_unused]] std::string_view what,
         [[maybe_unused]] std::basic_string_view<CharT> fmt,
         [[maybe_unused]] Args&&... args) {
-#ifndef TEST_HAS_NO_EXCEPTIONS
-      try {
-        TEST_IGNORE_NODISCARD std::vformat(fmt, std::make_format_args<context_t<CharT>>(args...));
-        TEST_FAIL(TEST_WRITE_CONCATENATED("\nFormat string   ", fmt, "\nDidn't throw an exception.\n"));
-      } catch (const std::format_error& e) {
-        TEST_LIBCPP_REQUIRE(
-            e.what() == what,
-            TEST_WRITE_CONCATENATED(
-                "\nFormat string   ", fmt, "\nExpected exception ", what, "\nActual exception   ", e.what(), '\n'));
-
-        return;
-      }
-      assert(false);
-#endif
+      TEST_VALIDATE_EXCEPTION(
+          std::format_error,
+          [&]([[maybe_unused]] const std::format_error& e) {
+            TEST_LIBCPP_REQUIRE(
+                e.what() == what,
+                TEST_WRITE_CONCATENATED(
+                    "\nFormat string   ", fmt, "\nExpected exception ", what, "\nActual exception   ", e.what(), '\n'));
+          },
+          TEST_IGNORE_NODISCARD std::vformat(fmt, std::make_format_args<context_t<CharT>>(args...)));
     };
 
 int main(int, char**) {
index 08830a3..c5a6237 100644 (file)
@@ -45,20 +45,15 @@ auto test_exception =
         [[maybe_unused]] std::string_view what,
         [[maybe_unused]] std::basic_string_view<CharT> fmt,
         [[maybe_unused]] Args&&... args) {
-#ifndef TEST_HAS_NO_EXCEPTIONS
-      try {
-        TEST_IGNORE_NODISCARD std::vformat(fmt, std::make_format_args<context_t<CharT>>(args...));
-        TEST_FAIL(TEST_WRITE_CONCATENATED("\nFormat string   ", fmt, "\nDidn't throw an exception.\n"));
-      } catch (const std::format_error& e) {
-        TEST_LIBCPP_REQUIRE(
-            e.what() == what,
-            TEST_WRITE_CONCATENATED(
-                "\nFormat string   ", fmt, "\nExpected exception ", what, "\nActual exception   ", e.what(), '\n'));
-
-        return;
-      }
-      assert(false);
-#endif
+      TEST_VALIDATE_EXCEPTION(
+          std::format_error,
+          [&]([[maybe_unused]] const std::format_error& e) {
+            TEST_LIBCPP_REQUIRE(
+                e.what() == what,
+                TEST_WRITE_CONCATENATED(
+                    "\nFormat string   ", fmt, "\nExpected exception ", what, "\nActual exception   ", e.what(), '\n'));
+          },
+          TEST_IGNORE_NODISCARD std::vformat(fmt, std::make_format_args<context_t<CharT>>(args...)));
     };
 
 int main(int, char**) {
index b73c351..4136123 100644 (file)
@@ -39,19 +39,15 @@ auto test_exception =
         [[maybe_unused]] std::string_view what,
         [[maybe_unused]] std::basic_string_view<CharT> fmt,
         [[maybe_unused]] Args&&... args) {
-#ifndef TEST_HAS_NO_EXCEPTIONS
-      try {
-        TEST_IGNORE_NODISCARD std::vformat(std::locale(), fmt, std::make_format_args<context_t<CharT>>(args...));
-        TEST_FAIL(TEST_WRITE_CONCATENATED("\nFormat string   ", fmt, "\nDidn't throw an exception.\n"));
-      } catch ([[maybe_unused]] const std::format_error& e) {
-        TEST_LIBCPP_REQUIRE(
-            e.what() == what,
-            TEST_WRITE_CONCATENATED(
-                "\nFormat string   ", fmt, "\nExpected exception ", what, "\nActual exception   ", e.what(), '\n'));
-        return;
-      }
-      assert(false);
-#endif
+      TEST_VALIDATE_EXCEPTION(
+          std::format_error,
+          [&]([[maybe_unused]] const std::format_error& e) {
+            TEST_LIBCPP_REQUIRE(
+                e.what() == what,
+                TEST_WRITE_CONCATENATED(
+                    "\nFormat string   ", fmt, "\nExpected exception ", what, "\nActual exception   ", e.what(), '\n'));
+          },
+          TEST_IGNORE_NODISCARD std::vformat(std::locale(), fmt, std::make_format_args<context_t<CharT>>(args...)));
     };
 
 int main(int, char**) {
index ea8c0c9..8a95b55 100644 (file)
@@ -38,20 +38,15 @@ auto test_exception =
         [[maybe_unused]] std::string_view what,
         [[maybe_unused]] std::basic_string_view<CharT> fmt,
         [[maybe_unused]] Args&&... args) {
-#ifndef TEST_HAS_NO_EXCEPTIONS
-      try {
-        TEST_IGNORE_NODISCARD std::vformat(fmt, std::make_format_args<context_t<CharT>>(args...));
-        TEST_FAIL(TEST_WRITE_CONCATENATED("\nFormat string   ", fmt, "\nDidn't throw an exception.\n"));
-      } catch ([[maybe_unused]] const std::format_error& e) {
-        TEST_LIBCPP_REQUIRE(
-            e.what() == what,
-            TEST_WRITE_CONCATENATED(
-                "\nFormat string   ", fmt, "\nExpected exception ", what, "\nActual exception   ", e.what(), '\n'));
-
-        return;
-      }
-      assert(false);
-#endif
+      TEST_VALIDATE_EXCEPTION(
+          std::format_error,
+          [&]([[maybe_unused]] const std::format_error& e) {
+            TEST_LIBCPP_REQUIRE(
+                e.what() == what,
+                TEST_WRITE_CONCATENATED(
+                    "\nFormat string   ", fmt, "\nExpected exception ", what, "\nActual exception   ", e.what(), '\n'));
+          },
+          TEST_IGNORE_NODISCARD std::vformat(fmt, std::make_format_args<context_t<CharT>>(args...)));
     };
 
 int main(int, char**) {
index 993f19a..6c5e7f4 100644 (file)
@@ -26,7 +26,8 @@
 #include <list>
 #include <vector>
 
-#include "test_macros.h"
+#include "assert_macros.h"
+#include "concat_macros.h"
 #include "format_tests.h"
 #include "string_literal.h"
 
@@ -58,23 +59,22 @@ auto test = []<class CharT, class... Args>(
   }
 };
 
-auto test_exception =
-    []<class CharT, class... Args>(
-        [[maybe_unused]] std::string_view what,
-        [[maybe_unused]] std::basic_string_view<CharT> fmt,
-        [[maybe_unused]] Args&&... args) {
-#ifndef TEST_HAS_NO_EXCEPTIONS
-      try {
+auto test_exception = []<class CharT, class... Args>([[maybe_unused]] std::string_view what,
+                                                     [[maybe_unused]] std::basic_string_view<CharT> fmt,
+                                                     [[maybe_unused]] Args&&... args) {
+  TEST_VALIDATE_EXCEPTION(
+      std::format_error,
+      [&]([[maybe_unused]] const std::format_error& e) {
+        TEST_LIBCPP_REQUIRE(
+            e.what() == what,
+            TEST_WRITE_CONCATENATED(
+                "\nFormat string   ", fmt, "\nExpected exception ", what, "\nActual exception   ", e.what(), '\n'));
+      },
+      [&] {
         std::basic_string<CharT> out;
         std::vformat_to(std::back_inserter(out), std::locale(), fmt, std::make_format_args<context_t<CharT>>(args...));
-        assert(false);
-      } catch ([[maybe_unused]] const std::format_error& e) {
-        LIBCPP_ASSERT(e.what() == what);
-        return;
-      }
-      assert(false);
-#endif
-    };
+      }());
+};
 
 int main(int, char**) {
   format_tests<char, execution_modus::partial>(test, test_exception);
index 0574d49..77c7834 100644 (file)
@@ -23,6 +23,8 @@
 #include <list>
 #include <vector>
 
+#include "assert_macros.h"
+#include "concat_macros.h"
 #include "test_macros.h"
 #include "format_tests.h"
 #include "string_literal.h"
@@ -60,17 +62,18 @@ auto test_exception =
         [[maybe_unused]] std::string_view what,
         [[maybe_unused]] std::basic_string_view<CharT> fmt,
         [[maybe_unused]] Args&&... args) {
-#ifndef TEST_HAS_NO_EXCEPTIONS
-      try {
-        std::basic_string<CharT> out;
-        std::vformat_to(std::back_inserter(out), fmt, std::make_format_args<context_t<CharT>>(args...));
-        assert(false);
-      } catch ([[maybe_unused]] const std::format_error& e) {
-        LIBCPP_ASSERT(e.what() == what);
-        return;
-      }
-      assert(false);
-#endif
+      TEST_VALIDATE_EXCEPTION(
+          std::format_error,
+          [&]([[maybe_unused]] const std::format_error& e) {
+            TEST_LIBCPP_REQUIRE(
+                e.what() == what,
+                TEST_WRITE_CONCATENATED(
+                    "\nFormat string   ", fmt, "\nExpected exception ", what, "\nActual exception   ", e.what(), '\n'));
+          },
+          [&] {
+            std::basic_string<CharT> out;
+            std::vformat_to(std::back_inserter(out), fmt, std::make_format_args<context_t<CharT>>(args...));
+          }());
     };
 
 int main(int, char**) {
index 518ef45..613eb5e 100644 (file)
@@ -44,20 +44,15 @@ auto test_exception =
         [[maybe_unused]] std::string_view what,
         [[maybe_unused]] std::basic_string_view<CharT> fmt,
         [[maybe_unused]] Args&&... args) {
-#ifndef TEST_HAS_NO_EXCEPTIONS
-      try {
-        TEST_IGNORE_NODISCARD std::vformat(fmt, std::make_format_args<context_t<CharT>>(args...));
-        TEST_FAIL(TEST_WRITE_CONCATENATED("\nFormat string   ", fmt, "\nDidn't throw an exception.\n"));
-      } catch (const std::format_error& e) {
-        TEST_LIBCPP_REQUIRE(
-            e.what() == what,
-            TEST_WRITE_CONCATENATED(
-                "\nFormat string   ", fmt, "\nExpected exception ", what, "\nActual exception   ", e.what(), '\n'));
-
-        return;
-      }
-      assert(false);
-#endif
+      TEST_VALIDATE_EXCEPTION(
+          std::format_error,
+          [&]([[maybe_unused]] const std::format_error& e) {
+            TEST_LIBCPP_REQUIRE(
+                e.what() == what,
+                TEST_WRITE_CONCATENATED(
+                    "\nFormat string   ", fmt, "\nExpected exception ", what, "\nActual exception   ", e.what(), '\n'));
+          },
+          TEST_IGNORE_NODISCARD std::vformat(fmt, std::make_format_args<context_t<CharT>>(args...)));
     };
 
 int main(int, char**) {
index 0a4fd4b..e411b03 100644 (file)
@@ -44,20 +44,15 @@ auto test_exception =
         [[maybe_unused]] std::string_view what,
         [[maybe_unused]] std::basic_string_view<CharT> fmt,
         [[maybe_unused]] Args&&... args) {
-#ifndef TEST_HAS_NO_EXCEPTIONS
-      try {
-        TEST_IGNORE_NODISCARD std::vformat(fmt, std::make_format_args<context_t<CharT>>(args...));
-        TEST_FAIL(TEST_WRITE_CONCATENATED("\nFormat string   ", fmt, "\nDidn't throw an exception.\n"));
-      } catch (const std::format_error& e) {
-        TEST_LIBCPP_REQUIRE(
-            e.what() == what,
-            TEST_WRITE_CONCATENATED(
-                "\nFormat string   ", fmt, "\nExpected exception ", what, "\nActual exception   ", e.what(), '\n'));
-
-        return;
-      }
-      assert(false);
-#endif
+      TEST_VALIDATE_EXCEPTION(
+          std::format_error,
+          [&]([[maybe_unused]] const std::format_error& e) {
+            TEST_LIBCPP_REQUIRE(
+                e.what() == what,
+                TEST_WRITE_CONCATENATED(
+                    "\nFormat string   ", fmt, "\nExpected exception ", what, "\nActual exception   ", e.what(), '\n'));
+          },
+          TEST_IGNORE_NODISCARD std::vformat(fmt, std::make_format_args<context_t<CharT>>(args...)));
     };
 
 int main(int, char**) {
index 20b210c..98bda2d 100644 (file)
@@ -45,20 +45,15 @@ auto test_exception =
         [[maybe_unused]] std::string_view what,
         [[maybe_unused]] std::basic_string_view<CharT> fmt,
         [[maybe_unused]] Args&&... args) {
-#ifndef TEST_HAS_NO_EXCEPTIONS
-      try {
-        TEST_IGNORE_NODISCARD std::vformat(fmt, std::make_format_args<context_t<CharT>>(args...));
-        TEST_FAIL(TEST_WRITE_CONCATENATED("\nFormat string   ", fmt, "\nDidn't throw an exception.\n"));
-      } catch (const std::format_error& e) {
-        TEST_LIBCPP_REQUIRE(
-            e.what() == what,
-            TEST_WRITE_CONCATENATED(
-                "\nFormat string   ", fmt, "\nExpected exception ", what, "\nActual exception   ", e.what(), '\n'));
-
-        return;
-      }
-      assert(false);
-#endif
+      TEST_VALIDATE_EXCEPTION(
+          std::format_error,
+          [&]([[maybe_unused]] const std::format_error& e) {
+            TEST_LIBCPP_REQUIRE(
+                e.what() == what,
+                TEST_WRITE_CONCATENATED(
+                    "\nFormat string   ", fmt, "\nExpected exception ", what, "\nActual exception   ", e.what(), '\n'));
+          },
+          TEST_IGNORE_NODISCARD std::vformat(fmt, std::make_format_args<context_t<CharT>>(args...)));
     };
 
 int main(int, char**) {
index c766f89..9445ddb 100644 (file)
@@ -45,20 +45,15 @@ auto test_exception =
         [[maybe_unused]] std::string_view what,
         [[maybe_unused]] std::basic_string_view<CharT> fmt,
         [[maybe_unused]] Args&&... args) {
-#ifndef TEST_HAS_NO_EXCEPTIONS
-      try {
-        TEST_IGNORE_NODISCARD std::vformat(fmt, std::make_format_args<context_t<CharT>>(args...));
-        TEST_FAIL(TEST_WRITE_CONCATENATED("\nFormat string   ", fmt, "\nDidn't throw an exception.\n"));
-      } catch ([[maybe_unused]] const std::format_error& e) {
-        TEST_LIBCPP_REQUIRE(
-            e.what() == what,
-            TEST_WRITE_CONCATENATED(
-                "\nFormat string   ", fmt, "\nExpected exception ", what, "\nActual exception   ", e.what(), '\n'));
-
-        return;
-      }
-      assert(false);
-#endif
+      TEST_VALIDATE_EXCEPTION(
+          std::format_error,
+          [&]([[maybe_unused]] const std::format_error& e) {
+            TEST_LIBCPP_REQUIRE(
+                e.what() == what,
+                TEST_WRITE_CONCATENATED(
+                    "\nFormat string   ", fmt, "\nExpected exception ", what, "\nActual exception   ", e.what(), '\n'));
+          },
+          TEST_IGNORE_NODISCARD std::vformat(fmt, std::make_format_args<context_t<CharT>>(args...)));
     };
 
 int main(int, char**) {