36#include <catch2/catch_amalgamated.hpp>
41#define INTERNAL_CATCH_TEST_M( msg, macroName, resultDisposition, ... ) \
44 CATCH_INTERNAL_IGNORE_BUT_WARN(__VA_ARGS__); \
45 std::string s1( macroName##_catch_sr ); \
48 Catch::AssertionHandler catchAssertionHandler( s1, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition ); \
49 INTERNAL_CATCH_TRY { \
50 CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
51 CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \
52 catchAssertionHandler.handleExpr( Catch::Decomposer() <= __VA_ARGS__ ); \
53 CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
54 } INTERNAL_CATCH_CATCH( catchAssertionHandler ) \
55 INTERNAL_CATCH_REACT( catchAssertionHandler ) \
56 } while( (void)0, (false) && static_cast<bool>( !!(__VA_ARGS__) ) )
58 #define REQUIRE_MSG(MSG, ... ) INTERNAL_CATCH_TEST_M( MSG, "REQUIRE: ", Catch::ResultDisposition::Normal, __VA_ARGS__ )
60#define INTERNAL_CHECK_THAT_M( msg, macroName, matcher, resultDisposition, arg ) \
62 std::string s1( macroName##_catch_sr ); \
66 Catch::AssertionHandler catchAssertionHandler( s1, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(arg) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \
67 INTERNAL_CATCH_TRY { \
68 catchAssertionHandler.handleExpr( Catch::makeMatchExpr( arg, matcher, #matcher##_catch_sr ) ); \
69 } INTERNAL_CATCH_CATCH( catchAssertionHandler ) \
70 INTERNAL_CATCH_REACT( catchAssertionHandler ) \
73 #define REQUIRE_THAT_MSG(MSG, arg, matcher ) INTERNAL_CHECK_THAT_M( MSG, "REQUIRE_THAT", matcher, Catch::ResultDisposition::Normal, arg )
75 #define INFO_STR( msg ) INTERNAL_CATCH_INFO( "INFO", static_cast<std::string>(msg) )
77 #define REQUIRE_EPSI(a,b) INTERNAL_CATCH_TEST( "REQUIRE: ", Catch::ResultDisposition::Normal, jau::equals(a, b))
78 #define REQUIRE_EPSI_MSG(m,a,b) INTERNAL_CATCH_TEST_M( m, "REQUIRE: ", Catch::ResultDisposition::Normal, jau::equals(a, b))
80 #define REQUIRE_DIFF(a,b,d) INTERNAL_CATCH_TEST( "REQUIRE: ", Catch::ResultDisposition::Normal, jau::equals(a, b, 1, d))
81 #define REQUIRE_DIFF_MSG(m,a,b,d) INTERNAL_CATCH_TEST_M( m, "REQUIRE: ", Catch::ResultDisposition::Normal, jau::equals(a, b, 1, d))
84 #define COMPARE_SARRAYS(lhs, rhs) compareStdArrays(Catch::getResultCapture().getCurrentTestName(), __LINE__, lhs, rhs)
85 #define COMPARE_SARRAYS_EPS(lhs, rhs, eps) compareStdArrays(Catch::getResultCapture().getCurrentTestName(), __LINE__, lhs, rhs, eps)
87 template <
typename T,
size_t N >
88 void compareStdArrays(
const std::string & test,
unsigned line,
const std::array<T, N>& lhs,
const std::array<T, N>& rhs) {
89 std::vector<T> lv(lhs.begin(), lhs.end());
90 std::vector<T> rv(rhs.begin(), rhs.end());
93 template <
typename T,
size_t N >
94 void compareStdArrays(
const std::string & test,
unsigned line,
const std::array<T, N>& lhs,
const std::array<T, N>& rhs,
const T epsilon) {
95 const std::string m =
"["+test+
"] at line "+
std::to_string(line)+
", element ";
96 for(
size_t i=0; i<N; ++i) {
101 #define COMPARE_NARRAYS(lhs, rhs, len) compareNativeArrays(Catch::getResultCapture().getCurrentTestName(), __LINE__, lhs, rhs, len)
102 #define COMPARE_NARRAYS_EPS(lhs, rhs, len, eps) compareNativeArrays(Catch::getResultCapture().getCurrentTestName(), __LINE__, lhs, rhs, len, eps)
104 template <
typename T >
105 void compareNativeArrays(
const std::string & test,
unsigned line,
const T lhs[],
const T rhs[],
const size_t len) {
106 const std::string m =
"["+test+
"] at line "+
std::to_string(line)+
", element ";
107 for(
size_t i=0; i<len; ++i) {
111 template <
typename T >
112 void compareNativeArrays(
const std::string & test,
unsigned line,
const T lhs[],
const T rhs[],
const size_t len,
const T epsilon) {
113 const std::string m =
"["+test+
"] at line "+
std::to_string(line)+
", element ";
114 for(
size_t i=0; i<len; ++i) {
120#if !defined(CATCH_CONFIG_MAIN)
#define REQUIRE_MSG(MSG,...)
void compareNativeArrays(const std::string &test, unsigned line, const T lhs[], const T rhs[], const size_t len)
void compareStdArrays(const std::string &test, unsigned line, const std::array< T, N > &lhs, const std::array< T, N > &rhs)
#define REQUIRE_THAT_MSG(MSG, arg, matcher)
std::string to_string(const alphabet &v) noexcept