[[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**) {
[[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**) {
[[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**) {
[[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**) {
#include <list>
#include <vector>
-#include "test_macros.h"
+#include "assert_macros.h"
+#include "concat_macros.h"
#include "format_tests.h"
#include "string_literal.h"
}
};
-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);
#include <list>
#include <vector>
+#include "assert_macros.h"
+#include "concat_macros.h"
#include "test_macros.h"
#include "format_tests.h"
#include "string_literal.h"
[[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**) {
[[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**) {
[[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**) {
[[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**) {
[[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**) {