From 2d85683f987af3020f38497c3813cf184ded79c6 Mon Sep 17 00:00:00 2001 From: Mark de Wever Date: Sat, 21 Jan 2023 13:35:30 +0100 Subject: [PATCH] [lib++][format] Uses the new exception test macros. Reviewed By: #libc, ldionne Differential Revision: https://reviews.llvm.org/D143393 --- .../format.functions.vformat.pass.cpp | 23 ++++++---------- .../format.functions.vformat.pass.cpp | 23 ++++++---------- .../format.functions/vformat.locale.pass.cpp | 22 ++++++--------- .../format/format.functions/vformat.pass.cpp | 23 ++++++---------- .../format.functions/vformat_to.locale.pass.cpp | 32 +++++++++++----------- .../format/format.functions/vformat_to.pass.cpp | 25 +++++++++-------- .../format.functions.vformat.pass.cpp | 23 ++++++---------- .../format.functions.vformat.pass.cpp | 23 ++++++---------- .../format.functions.vformat.pass.cpp | 23 ++++++---------- .../format.tuple/format.functions.vformat.pass.cpp | 23 ++++++---------- 10 files changed, 102 insertions(+), 138 deletions(-) diff --git a/libcxx/test/std/containers/container.adaptors/container.adaptors.format/format.functions.vformat.pass.cpp b/libcxx/test/std/containers/container.adaptors/container.adaptors.format/format.functions.vformat.pass.cpp index e74144e..a7136e7 100644 --- a/libcxx/test/std/containers/container.adaptors/container.adaptors.format/format.functions.vformat.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/container.adaptors.format/format.functions.vformat.pass.cpp @@ -47,20 +47,15 @@ auto test_exception = [[maybe_unused]] std::string_view what, [[maybe_unused]] std::basic_string_view fmt, [[maybe_unused]] Args&&... args) { -#ifndef TEST_HAS_NO_EXCEPTIONS - try { - TEST_IGNORE_NODISCARD std::vformat(fmt, std::make_format_args>(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>(args...))); }; int main(int, char**) { diff --git a/libcxx/test/std/containers/sequences/vector.bool/vector.bool.fmt/format.functions.vformat.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/vector.bool.fmt/format.functions.vformat.pass.cpp index 08830a3..c5a6237 100644 --- a/libcxx/test/std/containers/sequences/vector.bool/vector.bool.fmt/format.functions.vformat.pass.cpp +++ b/libcxx/test/std/containers/sequences/vector.bool/vector.bool.fmt/format.functions.vformat.pass.cpp @@ -45,20 +45,15 @@ auto test_exception = [[maybe_unused]] std::string_view what, [[maybe_unused]] std::basic_string_view fmt, [[maybe_unused]] Args&&... args) { -#ifndef TEST_HAS_NO_EXCEPTIONS - try { - TEST_IGNORE_NODISCARD std::vformat(fmt, std::make_format_args>(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>(args...))); }; int main(int, char**) { diff --git a/libcxx/test/std/utilities/format/format.functions/vformat.locale.pass.cpp b/libcxx/test/std/utilities/format/format.functions/vformat.locale.pass.cpp index b73c351..4136123 100644 --- a/libcxx/test/std/utilities/format/format.functions/vformat.locale.pass.cpp +++ b/libcxx/test/std/utilities/format/format.functions/vformat.locale.pass.cpp @@ -39,19 +39,15 @@ auto test_exception = [[maybe_unused]] std::string_view what, [[maybe_unused]] std::basic_string_view fmt, [[maybe_unused]] Args&&... args) { -#ifndef TEST_HAS_NO_EXCEPTIONS - try { - TEST_IGNORE_NODISCARD std::vformat(std::locale(), fmt, std::make_format_args>(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>(args...))); }; int main(int, char**) { diff --git a/libcxx/test/std/utilities/format/format.functions/vformat.pass.cpp b/libcxx/test/std/utilities/format/format.functions/vformat.pass.cpp index ea8c0c9..8a95b55 100644 --- a/libcxx/test/std/utilities/format/format.functions/vformat.pass.cpp +++ b/libcxx/test/std/utilities/format/format.functions/vformat.pass.cpp @@ -38,20 +38,15 @@ auto test_exception = [[maybe_unused]] std::string_view what, [[maybe_unused]] std::basic_string_view fmt, [[maybe_unused]] Args&&... args) { -#ifndef TEST_HAS_NO_EXCEPTIONS - try { - TEST_IGNORE_NODISCARD std::vformat(fmt, std::make_format_args>(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>(args...))); }; int main(int, char**) { diff --git a/libcxx/test/std/utilities/format/format.functions/vformat_to.locale.pass.cpp b/libcxx/test/std/utilities/format/format.functions/vformat_to.locale.pass.cpp index 993f19a..6c5e7f4 100644 --- a/libcxx/test/std/utilities/format/format.functions/vformat_to.locale.pass.cpp +++ b/libcxx/test/std/utilities/format/format.functions/vformat_to.locale.pass.cpp @@ -26,7 +26,8 @@ #include #include -#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 = []( } }; -auto test_exception = - []( - [[maybe_unused]] std::string_view what, - [[maybe_unused]] std::basic_string_view fmt, - [[maybe_unused]] Args&&... args) { -#ifndef TEST_HAS_NO_EXCEPTIONS - try { +auto test_exception = []([[maybe_unused]] std::string_view what, + [[maybe_unused]] std::basic_string_view 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 out; std::vformat_to(std::back_inserter(out), std::locale(), fmt, std::make_format_args>(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(test, test_exception); diff --git a/libcxx/test/std/utilities/format/format.functions/vformat_to.pass.cpp b/libcxx/test/std/utilities/format/format.functions/vformat_to.pass.cpp index 0574d49..77c7834 100644 --- a/libcxx/test/std/utilities/format/format.functions/vformat_to.pass.cpp +++ b/libcxx/test/std/utilities/format/format.functions/vformat_to.pass.cpp @@ -23,6 +23,8 @@ #include #include +#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 fmt, [[maybe_unused]] Args&&... args) { -#ifndef TEST_HAS_NO_EXCEPTIONS - try { - std::basic_string out; - std::vformat_to(std::back_inserter(out), fmt, std::make_format_args>(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 out; + std::vformat_to(std::back_inserter(out), fmt, std::make_format_args>(args...)); + }()); }; int main(int, char**) { diff --git a/libcxx/test/std/utilities/format/format.range/format.range.fmtmap/format.functions.vformat.pass.cpp b/libcxx/test/std/utilities/format/format.range/format.range.fmtmap/format.functions.vformat.pass.cpp index 518ef45..613eb5e 100644 --- a/libcxx/test/std/utilities/format/format.range/format.range.fmtmap/format.functions.vformat.pass.cpp +++ b/libcxx/test/std/utilities/format/format.range/format.range.fmtmap/format.functions.vformat.pass.cpp @@ -44,20 +44,15 @@ auto test_exception = [[maybe_unused]] std::string_view what, [[maybe_unused]] std::basic_string_view fmt, [[maybe_unused]] Args&&... args) { -#ifndef TEST_HAS_NO_EXCEPTIONS - try { - TEST_IGNORE_NODISCARD std::vformat(fmt, std::make_format_args>(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>(args...))); }; int main(int, char**) { diff --git a/libcxx/test/std/utilities/format/format.range/format.range.fmtset/format.functions.vformat.pass.cpp b/libcxx/test/std/utilities/format/format.range/format.range.fmtset/format.functions.vformat.pass.cpp index 0a4fd4b..e411b03 100644 --- a/libcxx/test/std/utilities/format/format.range/format.range.fmtset/format.functions.vformat.pass.cpp +++ b/libcxx/test/std/utilities/format/format.range/format.range.fmtset/format.functions.vformat.pass.cpp @@ -44,20 +44,15 @@ auto test_exception = [[maybe_unused]] std::string_view what, [[maybe_unused]] std::basic_string_view fmt, [[maybe_unused]] Args&&... args) { -#ifndef TEST_HAS_NO_EXCEPTIONS - try { - TEST_IGNORE_NODISCARD std::vformat(fmt, std::make_format_args>(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>(args...))); }; int main(int, char**) { diff --git a/libcxx/test/std/utilities/format/format.range/format.range.formatter/format.functions.vformat.pass.cpp b/libcxx/test/std/utilities/format/format.range/format.range.formatter/format.functions.vformat.pass.cpp index 20b210c..98bda2d 100644 --- a/libcxx/test/std/utilities/format/format.range/format.range.formatter/format.functions.vformat.pass.cpp +++ b/libcxx/test/std/utilities/format/format.range/format.range.formatter/format.functions.vformat.pass.cpp @@ -45,20 +45,15 @@ auto test_exception = [[maybe_unused]] std::string_view what, [[maybe_unused]] std::basic_string_view fmt, [[maybe_unused]] Args&&... args) { -#ifndef TEST_HAS_NO_EXCEPTIONS - try { - TEST_IGNORE_NODISCARD std::vformat(fmt, std::make_format_args>(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>(args...))); }; int main(int, char**) { diff --git a/libcxx/test/std/utilities/format/format.tuple/format.functions.vformat.pass.cpp b/libcxx/test/std/utilities/format/format.tuple/format.functions.vformat.pass.cpp index c766f89..9445ddb 100644 --- a/libcxx/test/std/utilities/format/format.tuple/format.functions.vformat.pass.cpp +++ b/libcxx/test/std/utilities/format/format.tuple/format.functions.vformat.pass.cpp @@ -45,20 +45,15 @@ auto test_exception = [[maybe_unused]] std::string_view what, [[maybe_unused]] std::basic_string_view fmt, [[maybe_unused]] Args&&... args) { -#ifndef TEST_HAS_NO_EXCEPTIONS - try { - TEST_IGNORE_NODISCARD std::vformat(fmt, std::make_format_args>(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>(args...))); }; int main(int, char**) { -- 2.7.4